Lab 2 - Basic Robot Movement and Control - Using Python and Ros
Lab 2 - Basic Robot Movement and Control - Using Python and Ros
Objective: This lab aims to offer students a detailed understanding of robot kinematics, dynamics, and
the principles of movement control. By leveraging the capabilities of Python and the Robot Operating
System (ROS), students will gain hands-on experience in implementing and controlling robot movements
in both simulated and real environments.
Kinematics deals with the study of motion without considering the forces that cause it. In the context of
robotics, it helps in understanding and predicting the movement of robots based on their joint
configurations.
1. Forward Kinematics (FK):Forward Kinematics refers to the process of determining the position and
orientation of a robot's end-effector (like a tool or gripper) based on its joint angles or positions. It deals
with the prediction of a robot's configuration given the joint parameters.
Mathematical Model:
In a robot arm with multiple joints, the end-effector's position P in the workspace is a function of its
joint parameters, q: P=f(q)
Where:
Setup: Initiate a robot arm (or its simulation) with known joint parameters.
Prediction: Before moving the robot, predict where the end-effector will end up using the FK
mathematical model.
Observation: Check the final position of the end-effector and compare it to the prediction.
Inverse Kinematics is essentially the opposite process of Forward Kinematics. Given a desired position
(and possibly orientation) for the robot's end-effector, IK determines the joint angles or positions that
would achieve that position.
Mathematical Model:
For a desired end-effector position P′ in the workspace, the required joint parameters q′ are determined
as: q′=f−1(P′)
Where:
Setup: Start with a robot arm (or its simulation) in any initial configuration.
Target Position: Define a specific location in the robot's workspace where you want the end-effector to
go.
Calculation: Use the IK mathematical model or algorithms to determine the required joint angles or
positions.
Adjustment: Adjust the robot's joint parameters based on the calculated values.
Validation: Confirm that the robot's end-effector reaches the desired position.
Outcome: The end-effector should be at the specified target location, validating the IK calculations.
Note:
Forward Kinematics is generally straightforward, but Inverse Kinematics can be more complex, especially
for robots with many degrees of freedom. Often, for a given end-effector position, there may be multiple
joint configurations (solutions) or, in some cases, none at all. Hence, computational methods, iterative
algorithms, or optimization techniques are frequently used to solve IK problems in robotics.Introduction
to Dynamics: Study motion considering forces and torques.
Robot Dynamics: Forces, Torques, and Accelerations in Robotic Systems
Robot dynamics is a critical area of study in robotics that involves understanding and analyzing the
forces, torques, and accelerations that act upon or within a robotic system. This is essential because
these factors govern how a robot moves and how it interacts with its environment. While kinematics
provides a geometrical interpretation of robot motion, dynamics integrates the principles of physics to
predict and explain the effects of movements and interactions.
Key Concepts:
Forces: External and internal pushes or pulls experienced by the robot, resulting from interactions with
the environment, gravity, or actuators.
Torques (or Moments): A rotational force acting at a distance from a pivotal point or joint in a robotic
system. In the case of robotic arms, torques are generated at the joints, enabling rotation.
Accelerations: Change in velocity with respect to time. In a robotic context, it can be linear (straight-line
movement) or angular (rotational movement).
Mass and Inertia: The distribution of a robot's weight affects how it responds to forces and torques.
Inertia, particularly rotational inertia, is crucial for understanding how a robot will respond to applied
torques.
Gravity: A constant force acting downwards, affecting the robot's stability and the necessary forces or
torques to move or remain stationary.
Friction: Acts at interfaces like robot feet, wheels, or joints, opposing motion and affecting how much
force is needed to move.
Actuation: Motors, pistons, or other actuators in the robot provide forces and torques that enable
movement. Their dynamics include responsiveness, maximum force/torque, and efficiency.
External Loads: When robots lift or push objects, or when external factors push or pull on the robot.
Activity:
Setup: Use a robot arm (or its simulation) equipped with force sensors at its joints and a variety of
objects with different weights and shapes.
Task 1: Lifting Objects of Different Weights:
Observe: How much force and torque is needed for each object? How does this compare to the object's
weight?
Lesson: Understand the correlation between object weight (gravity's effect) and the required
force/torque.
Place objects on surfaces with varying friction levels (e.g., rubber mat, smooth table, and a rough
carpet).
Observe: How does the required force change with different surfaces?
Instruct the robot to move its arm quickly, then stop suddenly.
Lesson: Learn about the relationship between acceleration, inertia, and control.
While the robot is holding an object steady, apply an external push or pull.
Observe: How does the robot respond? What changes in forces/torques are recorded?
Lesson: Realize the importance of feedback and dynamic adjustments in robot control.
Discussion:
Discuss the importance of considering dynamics when designing robot control algorithms.
How do real-world physical factors influence the robot's planned vs. actual movements?
Explore advanced topics like feedforward control (using predictions to guide movements) and feedback
control (using sensor data to correct movements).
Conclusion:
Dynamics in robotics provides the foundation for effective and safe robot movement. By understanding
the forces, torques, and accelerations acting on a robot, engineers can design precise, stable, and
responsive control strategies, ensuring that robots can perform tasks efficiently and safely in a range of
environments.
Implemen ng Basic Robot Movement with Python and ROS
ROS (Robot Opera ng System) is a middleware that offers various tools, libraries, and conven ons to
simplify the task of crea ng complex robot behavior across a wide variety of robo c pla orms. Before
diving into robot simula on, essen al ROS packages must be installed.
Open the new terminal in your Linux OS and follow the steps
c. Setup Keys:
e. Environment Setup:
source ~/.bashrc
rosdep update
2. Crea ng a ROS Workspace:
A workspace is a directory where you modify, build, and install ROS packages. The main workspace in
ROS is called the catkin workspace.
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
Every new terminal you open, you'll need to source your workspace to overlay it atop the ROS
environment.
source ~/.bashrc
3. Se ng up a Robot Simula on Environment:
Gazebo is a popular simula on tool for ROS which can simulate popula ons of robots in complex indoor
and outdoor environments.
a. Install Gazebo:
There are various robot models available for Gazebo. Let's say you're using the Turtlebot:
Now, Gazebo should launch showing the simulated environment with your robot.
Note: At this point, you have set up a basic robot movement simula on environment using ROS and
Gazebo. You can now proceed to implement robot movement and control algorithms with Python and
ROS in next lab.
A. Python Script for Robot Control:
This script will u lize Python alongside ROS interfaces to command the robot's movement. It'll send
velocity commands to move the robot and will subscribe to sensor data to get feedback.
Prerequisite: Ensure you have the rospy package installed since it provides a Python library for ROS.
#!/usr/bin/env python
import rospy
from sensor_msgs.msg import Imu # Assuming IMU sensor data, can be replaced with other sensor data
types.
class RobotController:
def __init__(self):
rospy.init_node('robot_controller')
self.rate = rospy.Rate(10) # 10 Hz
def move_forward(self):
"""
"""
# Create a Twist message, which has linear and angular veloci es.
move_cmd = Twist()
self.cmd_vel_pub.publish(move_cmd)
"""
"""
def run(self):
"""
"""
self.move_forward()
self.rate.sleep()
if __name__ == "__main__":
controller = RobotController()
controller.run()
How it works:
It sets up a publisher to send velocity commands (cmd_vel) and a subscriber to get sensor feedback (in
this case, from an IMU sensor).
In the main loop (run method), the script con nuously sends a forward mo on command.
To run the script, save it, give it execute permissions using chmod +x script_name.py, and then execute
with rosrun or roslaunch if you have a launch file set up.
Experiment for Robot Movement
Kinema cs and dynamics form the founda on upon which robot movements are understood and
controlled. When designing robo c systems, it's impera ve to be equipped with a comprehensive
understanding of these concepts.
#!/usr/bin/env python
import rospy
class AdvancedRobotController:
def __init__(self):
rospy.init_node('advanced_robot_controller')
self.rate = rospy.Rate(10) # 10 Hz
"""
"""
move_cmd = Twist()
self.cmd_vel_pub.publish(move_cmd)
"""
"""
rotate_cmd = Twist()
rotate_cmd.linear.x = 0.0 # No forward mo on
self.cmd_vel_pub.publish(rotate_cmd)
"""
"""
move_cmd = Twist()
move_cmd.linear.x = speed
move_cmd.angular.z = angular_speed
self.cmd_vel_pub.publish(move_cmd)
self.rate.sleep()
self.stop_mo on()
rospy.sleep(0.5)
"""
"""
stop_cmd = Twist()
self.cmd_vel_pub.publish(stop_cmd)
def run(self):
"""
"""
# Move forward
self.move_forward()
# Rotate in place
self.rotate_in_place()
trajectory = [
self.follow_trajectory(trajectory)
self.stop_mo on()
if __name__ == "__main__":
controller = AdvancedRobotController()
controller.run()
Explana on:
follow_trajectory: Follows a predefined trajectory where each item is a tuple of linear speed, dura on,
and angular speed.
Again, remember to provide execute permissions to the script using chmod +x script_name.py and run it
using ROS commands (rosrun or roslaunch).
Evalua on:
This lab material serves as a comprehensive guide to the topic, blending both theore cal understanding
and prac cal implementa on in the realm of robot movement and control.