100% found this document useful (1 vote)
89 views

Lab 2 - Basic Robot Movement and Control - Using Python and Ros

This lab aims to provide students hands-on experience with robot kinematics, dynamics, and movement control using Python and ROS. Students will first learn about forward and inverse kinematics by using mathematical models to predict and adjust a robot arm's end effector position. Next, they will explore how forces, torques, and accelerations impact robotic systems by commanding a simulated robot arm to perform tasks involving lifting objects, moving with friction, and responding to disturbances. Finally, students will set up a ROS workspace and use Gazebo to simulate a robot environment for implementing and testing basic movement control.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
89 views

Lab 2 - Basic Robot Movement and Control - Using Python and Ros

This lab aims to provide students hands-on experience with robot kinematics, dynamics, and movement control using Python and ROS. Students will first learn about forward and inverse kinematics by using mathematical models to predict and adjust a robot arm's end effector position. Next, they will explore how forces, torques, and accelerations impact robotic systems by commanding a simulated robot arm to perform tasks involving lifting objects, moving with friction, and responding to disturbances. Finally, students will set up a ROS workspace and use Gazebo to simulate a robot environment for implementing and testing basic movement control.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

LAB 2: BASIC ROBOT MOVEMENT AND CONTROL

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.

Part 1: Robot Kinematics and Dynamics

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:

P is the position of the end-effector.


q represents joint angles or positions.
Activity:

Practical Demonstration using a Robot Arm or Simulation:

Setup: Initiate a robot arm (or its simulation) with known joint parameters.

Input: Provide specific joint angles or positions to the robot.

Prediction: Before moving the robot, predict where the end-effector will end up using the FK
mathematical model.

Movement: Move the robot to the specified joint parameters.

Observation: Check the final position of the end-effector and compare it to the prediction.

Outcome: The predicted and actual end-effector positions should match.


2. Inverse Kinematics (IK):

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:

P′ is the desired position of the end-effector.

q′ represents the joint angles or positions required to achieve


Activity:

Solving Basic Inverse Kinematics Problems:

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.

Movement: Move the robot to the determined joint configurations.

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).

Factors Influencing Robot Dynamics:

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:

Understanding How Dynamics Plays a Role in Robot Control Strategies:

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:

Command the robot to lift objects of varying 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.

Task 2: Moving with and against Friction:

Place objects on surfaces with varying friction levels (e.g., rubber mat, smooth table, and a rough
carpet).

Command the robot to push the objects.

Observe: How does the required force change with different surfaces?

Lesson: Grasp the role of friction in dictating actuation needs.

Task 3: Rapid Acceleration and Deceleration:

Instruct the robot to move its arm quickly, then stop suddenly.

Observe: What forces act on the robot? How do actuators respond?

Lesson: Learn about the relationship between acceleration, inertia, and control.

Task 4: External Disturbances:

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

1. Installing ROS Packages:

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.

Follow the Steps:

Open the new terminal in your Linux OS and follow the steps

a. Update Your System:

sudo apt update && sudo apt upgrade

b. Setup ROS Repositories:

sudo sh -c 'echo "deb h p://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" >


/etc/apt/sources.list.d/ros-latest.list'

c. Setup Keys:

sudo apt install curl

curl -s h ps://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

d. Install ROS (Replace melodic with your ROS version):

sudo apt update

sudo apt install ros-melodic-desktop-full

e. Environment Setup:

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc

source ~/.bashrc

f. Dependencies for building packages:

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-


essen al

g. Ini alize rosdep:

sudo rosdep init

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.

Follow the steps carefully:

a. Create a catkin workspace directory:

mkdir -p ~/catkin_ws/src

cd ~/catkin_ws/

b. Build the workspace:

Inside the catkin workspace directory:

catkin_make

c. Source the workspace:

Every new terminal you open, you'll need to source your workspace to overlay it atop the ROS
environment.

echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc

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.

Follow the steps:

a. Install Gazebo:

sudo apt-get install ros-melodic-gazebo-ros-pkgs ros-melodic-gazebo-ros-control

b. Get Robot Models:

There are various robot models available for Gazebo. Let's say you're using the Turtlebot:

sudo apt-get install ros-melodic-turtlebot-gazebo

c. Launch Simula on:

To start the Gazebo simula on with the robot model:

roslaunch turtlebot_gazebo turtlebot_world.launch

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:

First code for establishing Subscriber.

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 geometry_msgs.msg import Twist

from sensor_msgs.msg import Imu # Assuming IMU sensor data, can be replaced with other sensor data
types.

class RobotController:

def __init__(self):

# Ini alize the node with a name, 'robot_controller'

rospy.init_node('robot_controller')

# Create a publisher object. This will send commands to the robot.

# Assuming the robot subscribes to 'cmd_vel' for velocity commands.

self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)

# Create a subscriber object to get sensor data from the robot.

# Here we're using IMU data as an example.

self.imu_sub = rospy.Subscriber('imu', Imu, self.imu_callback)

# Set the rate of command publishing

self.rate = rospy.Rate(10) # 10 Hz

def move_forward(self):

"""

Send a command to move the robot forward.

"""

# Create a Twist message, which has linear and angular veloci es.

move_cmd = Twist()

move_cmd.linear.x = 0.5 # Move forward with a speed of 0.5 m/s


move_cmd.angular.z = 0.0 # No rota on

# Publish the command

self.cmd_vel_pub.publish(move_cmd)

def imu_callback(self, data):

"""

Callback for IMU data.

"""

# This is where we process the incoming sensor data.

# For now, just print it.

rospy.loginfo("IMU data: %s", data)

def run(self):

"""

The main run loop.

"""

while not rospy.is_shutdown():

# Keep moving forward

self.move_forward()

self.rate.sleep()

if __name__ == "__main__":

controller = RobotController()

controller.run()

How it works:

The script ini alizes a ROS node called robot_controller.

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.

Python Script for Robot Control:

#!/usr/bin/env python

import rospy

from geometry_msgs.msg import Twist

class AdvancedRobotController:

def __init__(self):

# Ini alize the node with the name 'advanced_robot_controller'

rospy.init_node('advanced_robot_controller')

# Create a publisher to send commands to the robot

self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=10)

# Set the rate of command publishing

self.rate = rospy.Rate(10) # 10 Hz

def move_forward(self, speed=0.5):

"""

Move the robot forward at the specified speed.

"""

move_cmd = Twist()

move_cmd.linear.x = speed # Set speed, default is 0.5 m/s

move_cmd.angular.z = 0.0 # No rota on

self.cmd_vel_pub.publish(move_cmd)

def rotate_in_place(self, angular_speed=0.5):

"""

Rotate the robot in place at the specified angular speed.

"""

rotate_cmd = Twist()
rotate_cmd.linear.x = 0.0 # No forward mo on

rotate_cmd.angular.z = angular_speed # Set rota on speed

self.cmd_vel_pub.publish(rotate_cmd)

def follow_trajectory(self, trajectory=[]):

"""

Make the robot follow a predefined trajectory.

Each item in the trajectory is a (speed, dura on, angular_speed) tuple.

"""

for speed, dura on, angular_speed in trajectory:

move_cmd = Twist()

move_cmd.linear.x = speed

move_cmd.angular.z = angular_speed

end_ me = rospy.Time.now() + rospy.Dura on(dura on)

while rospy.Time.now() < end_ me and not rospy.is_shutdown():

self.cmd_vel_pub.publish(move_cmd)

self.rate.sleep()

# Stop briefly between trajectory points for clarity

self.stop_mo on()

rospy.sleep(0.5)

def stop_mo on(self):

"""

Stop any robot movement.

"""

stop_cmd = Twist()

self.cmd_vel_pub.publish(stop_cmd)

def run(self):

"""

The main run loop demonstrates robot mo ons.

"""
# Move forward

self.move_forward()

rospy.sleep(3) # Move for 3 seconds

# Rotate in place

self.rotate_in_place()

rospy.sleep(3) # Rotate for 3 seconds

# Follow a predefined trajectory

trajectory = [

(0.5, 2, 0), # Move forward at 0.5 m/s for 2 seconds

(0, 2, 0.5), # Rotate in place for 2 seconds

(0.5, 2, -0.5) # Move in a curve for 2 seconds

self.follow_trajectory(trajectory)

# Stop the robot

self.stop_mo on()

if __name__ == "__main__":

controller = AdvancedRobotController()

controller.run()

Explana on:

The script ini alizes a ROS node called advanced_robot_controller.

Func ons are defined for different robot movements:

move_forward: Makes the robot move straight.

rotate_in_place: Rotates the robot at its posi on.

follow_trajectory: Follows a predefined trajectory where each item is a tuple of linear speed, dura on,
and angular speed.

stop_mo on: Stops any mo on of the robot.

The run func on demonstrates each of these movements sequen ally.

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:

 Wri en test on kinema cs and dynamics concepts.


 Evalua on of Python scripts wri en for robot control.
 Prac cal demonstra on of robot movements in a simulator or on real hardware.

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.

You might also like