Event booking for offline workshop on Arduino Alvik started. Seats: 16 only. Click here to Book Now!
- Arduino Alvik: How to write the blinking LED code?
- How to write code for alternate Blinking LEDs with different colors in Arduino Alvik?
- How to move Arduino Alvik forward and backward using simple code?
- How to give turns to Arduino Alvik using simple code?
- Achieving control and orientation with Arduino Alvik on rotating platform
- Simple black line follower code for Arduino Alvik
- AlvikArduino Alvik Arduino Alvik robot is launched by Arduino on 14 May, 2024. Its the latest and the best educational robot now available at Vidyasagar Academy. Our expert faculties have designed well planned course to learn Arduino Alvik for any student from 4th standard up to engineering level. Read more about Arduino Alvik at official website or Arduino.: How to use alvik.drive() function in Arduino AlvikArduino Alvik Arduino Alvik robot is launched by Arduino on 14 May, 2024. Its the latest and the best educational robot now available at Vidyasagar Academy. Our expert faculties have designed well planned course to learn Arduino Alvik for any student from 4th standard up to engineering level. Read more about Arduino Alvik at official website or Arduino. coding
- Alvik: Detecting different colors & controlling the robot movements
- Alvik: Detecting Falling and Crashes (IMU) Corrected Code
If you are Arduino Alvik lover, and using the different functions given in Arduino Alvik user guide, then you must have come across the drive()
function. I am sure that you must have been confused that how to use this function with proper parameters in it to control the motion of the robot.
So in this article, let us see what are importance of this function and how to use it practically to control the motion of Alvik robot precisely.
As per the api of drive function, given on official website of Arduino Alvik, there are two parameters in it, as follows:
drive(linear_velocity: float, angular_velocity: float, linear_unit: str = 'cm/s',angular_unit: str = 'deg/s')
To make the Arduino Alvik robot move forward in a straight line, you need to ensure that the angular velocity is set to 0, as angular velocity introduces a rotational movement that causes the robot to turn. The linear velocity will control how fast the robot moves forward. For example –
alvik.drive(10, 0, 'cm/s', 'deg/s'
Here’s how you calculate the values and use the function correctly:
Linear Velocity
Maximum Speed of the Robot: According to the datasheet, the robot’s wheels can achieve a maximum speed of 55.
Converting Wheel Speed to Linear Velocity: The relationship between linear velocity and wheel angular speed is given by:
v = ω x r
where:
v = linear velocity
ω = wheel angular speed (rad/s)
r = wheel radius (meters)
diameter of wheel = 34 mm = 0.034m
radius of wheel = 17mm = 0.017m
To achieve the maximum linear velocity:
Vmax = ωmax x r
Angular Velocity
Remember that to keep the robot moving in a straight line, set the angular velocity to 0. The function call would look for a straight-line motion –
alvik.drive(10, 0, 'cm/s', 'deg/s') # Move straight at 10 cm/s
In above function, 10 is the linear velocity and 0 is the angular velocity. Since angular velocity component is set to 0, the robot will move forward in straight line, without turning.
Why two parameters in the function?
Why did they give such function for alvik that contain both parameters of linear and angular velocity? Does it have any kind of practical use to use both parameters which are non zero?
If you try to put some non-zero values of both parameters in the function, like the one given below, then you will notice that the robot moves randomly, but not in a straight line.
alvik.drive(10, 30, 'cm/s', 'deg/s') # forward motion
sleep(1) # delay 1 seconds
alvik.brake() # robot stops
So this is a great question that why did they give such function for alvik that contain both parameters of linear and angular velocity?
The inclusion of both linear velocity and angular velocity parameters in the drive() function is designed to give the robot the ability to perform differential drive motion control, which is widely used in robotics. Let us understand its practical use –
Purpose of Combining Linear and Angular Velocities
Precise Path Control (Curved Motion)
By specifying both linear velocity (forward/backward speed) and angular velocity (rate of rotation), you can make the robot move along curved or circular paths. For example –
- High linear velocity, small angular velocity → Wide curve
- Moderate linear velocity, high angular velocity → Tight curve
- Zero linear velocity, non-zero angular velocity → Rotate in place
Real-World Applications of Curved Motion
- Obstacle Avoidance: Moving around objects while maintaining a forward trajectory.
- Navigation: Following curved paths, such as turning corners or navigating around arcs.
- Trajectory Control: Combining linear and angular velocities lets you program the robot to follow specific paths like spirals, figure of an eight-type path or arcs, which are useful in mapping and search-and-rescue applications.
Differential Drive Robots
- Arduino Alvik likely uses a differential drive mechanism (each wheel can rotate independently).
- The angular velocity affects how much faster or slower one wheel turns relative to the other, allowing the robot to change direction while moving forward.
Kinematic Modeling of Robot Motion
The function reflects the kinematic equations of a differential drive robot –
v = (vr + vl) / 2
ω = (vr – vl) / w
where,
v = linear velocity (average speed of left and right wheels)
ω = angular velocity (difference in speed of the wheels)
vr & vl = velocities of the right and left wheels
w = distance between the wheels (wheelbase)
This kinematic approach is essential for controlling robot trajectories.
If both parameters are non-zero, then what?
Here are some examples of tasks where both parameters (non-zero linear and angular velocities) are beneficial.
Smooth Turning in Motion
If the robot needs to turn left or right without stopping, you can use a non-zero linear velocity with a small angular velocity. Example: A robot driving down a road and making a gentle curve.
Dynamic Path Following
Robots used for cleaning (like Roomba) or delivery systems follow specific paths. These paths often involve turns while moving forward.
Simulating Realistic Vehicle Motion
For simulating car-like motion (forward and turning at the same time), this combination is essential.
Spiral Scanning
To scan an area in a spiral pattern, the robot needs to move forward (linear velocity) while slowly turning (angular velocity).
Docking and Alignment
Robots often need to align themselves to a target while moving, requiring simultaneous adjustment of both forward and rotational motion.
How to Use Both Parameters
Here’s an example of curved motion –
alvik.drive(10, 45, ‘cm/s’, ‘deg/s’) # Move forward at 10 cm/s while turning at 45 degrees per second
- Linear velocity (10 cm/s): Controls forward speed.
- Angular velocity (45 deg/s): Controls how sharply the robot turns.
This will make the robot follow a curved path.
Why It’s Important for Learning
Even if you don’t need curved motion now, this is foundational for robotics:
- It teaches you how differential drive robots work.
- It allows you to design more complex motion patterns in future projects.
- It’s useful for algorithms like SLAM (Simultaneous Localization and Mapping) or autonomous navigation.
Thus the drive()
function is designed to maximize the flexibility and capability of your robot. While you can set angular velocity to 0 for straight-line motion, the ability to combine linear and angular velocities is a powerful tool for advanced robotics applications.
Now using this code you can extend it as per your imagination. If you have any queries, please write your comment below this post.
Happy Alvik Coding…!
Quick Links
- Achieving control and orientation with Arduino Alvik on rotating platform
- Arduino Alvik: How to write the blinking LED code?
- How to write code for alternate Blinking LEDs with different colors in Arduino Alvik?
- How to move Arduino Alvik forward and backward using simple code?
- How to give turns to Arduino Alvik using simple code?
- Simple black line follower code for Arduino Alvik
- Alvik: Detecting different colors & controlling the robot movements