Achieving control and orientation with Arduino Alvik on rotating platform

Achieving control and orientation with Arduino Alvik on rotating platform

This entry is part 5 of 9 in the series Arduino Alvik

Arduino Alvik was launched on May 14, 2024 and there are lots of searches going on to find the correct codes for it. Arduino Alvik is a robot designed for STEM education and is intended to be a tool for hands-on learning, creativity, and critical thinking. It’s suitable for users of all ages and skill levels.

At Vidyasagar Academy we have written different interesting codes for Arduino Alvik and teaching them practically to our students. All these codes are successfully tested in our lab.

Arduino Alvik is a unique and innovative development platform, designed to expand the capabilities of the Arduino ecosystem by incorporating MicroPython as its primary programming language. Alvik focuses on offering a versatile environment for building projects that require advanced features such as real-time control, robotic automation, and sensor-based systems. This makes it particularly appealing to hobbyists, educators, and professionals alike, who want to leverage the power of both the hardware flexibility of Arduino and the ease-of-use that MicroPython provides.

With Alvik, users can easily integrate sensors, motors, LEDs, and other actuators into their projects while using high-level Pythonic constructs to write clean and efficient code. This platform retains the simplicity that Arduino is known for, but offers more advanced features typically seen in MicroPython-based environments, such as asynchronous programming, native handling of complex data structures, and fast prototyping for IoT applications.

Alvik also comes equipped with its own specialized modules and libraries that make it easier to control different hardware components like motors, sensors, and buzzers. It supports various robotic applications, including line-following robots, making it ideal for robotics enthusiasts.

References

To understand how to write proper codes for Arduino Alvik, use its IR sensors array, Ultrasonic sensor, touch pad and all the new wonderful things, read previous posts in our Arduino Alvik Series.

How it works?

The Code for Achieving control and orientation with Arduino Alvik

This code works properly with slowly rotating platforms.

from arduino_alvik import ArduinoAlvik
from time import sleep_ms
import sys

# Initialize the Alvik robot
alvik = ArduinoAlvik()
alvik.begin()

# Define a tolerance threshold for stability
gyro_threshold = 1.0  # Adjust this value as needed

# Function to adjust motors based on gyroscope data
def adjust_motors(gx, gy, gz):
    if abs(gz) > gyro_threshold:
        if gz > 0:
            print("Rotating clockwise")
            alvik.set_wheels_speed(30, -30)  # Adjust the speed for clockwise rotation
        else:
            print("Rotating counter-clockwise")
            alvik.set_wheels_speed(-30, 30)  # Adjust the speed for counter-clockwise rotation
    else:
        print("Direction is stable, stopping motors")
        alvik.set_wheels_speed(0, 0)  # Stop motors when stable

while True:
    try:
        # Get the current accelerometer and gyroscope readings
        ax, ay, az = alvik.get_accelerations()
        gx, gy, gz = alvik.get_gyros()
        
        print(f'ax: {ax}, ay: {ay}, az: {az}, gx: {gx}, gy: {gy}, gz: {gz}')
        
        # Adjust motors based on the gyroscope data
        adjust_motors(gx, gy, gz)
        
        # Pause briefly before the next reading
        sleep_ms(300)
        
    except KeyboardInterrupt:
        print('Stopping the robot')
        alvik.set_wheels_speed(0, 0)
        alvik.stop()
        sys.exit()

Procedure to use the code in Arduino Alvik

If you are new to Arduino Alvik, the read this step-by-step procedure to create new file in Arduino Lab software and then run the code given above.

Share on your network!
Prof. Dattaraj Vidyasagar
Prof. Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x