Uploaded by Rayan Alghamdi

TURTLEBOT3_Rayan Alghamdi

advertisement
ROBOTICS
ASSIGNMENT #1
A written Report about a Real-Life Robot Project.
TURTLEBOT3
Course Name:
ROBOTICS
Student Name: Rayan Alghamdi
Student N.O :
442140357
I
Table of Contents
1. INTRODUCTION ...............................................................................................................2
2. Project Overview .................................................................................................................2
•
Project Objectives ............................................................................................................................. 2
•
Project Challenges............................................................................................................................. 2
•
Project Timeline................................................................................................................................. 2
3. History behind Building the TurtleBot3. ...........................................................................3
•
Background 3
•
Inspiration 3
4. Body - Sensors, Actuators, Mechanical, and Electrical Parts .........................................3
•
Sensors
3
•
Actuators
4
•
Mechanical components ................................................................................................................... 4
•
ELECTRICAL / ELECTRONIC COMPONENTS........................................................................................ 4
5. Code behind running the TurtleBot3. ................................................................................5
•
Programming Language: .................................................................................................................... 5
•
Functionality Overview: ..................................................................................................................... 5
6. General explanation of the TurtleBot3 code. ....................................................................6
•
Code division .................................................................................................................................... 6
•
Code algorithms ................................................................................................................................ 6
7. Detailed explanation of the TurtleBot3 code. ....................................................................6
•
Example#1: Python snippet code ....................................................................................................... 7
•
Example#2: C++snippet code ............................................................................................................ 8
•
Example#3: C++ snippet code .......................................................................................................... 10
8. References...........................................................................................................................10
Page 1 of 10
TURTLEBOT3
1. INTRODUCTION
The assignment requires conducting research on a real-life robot project. The “TurtleBot3” robot was selected
as a potential option for this assignment due to its accessibility and ease of use. It is an open-source robot
platform that has been designed for educational, research, and development purposes. Its widespread popularity
in the robotics community is attributed to its user-friendly design and accessibility.
2. Project Overview
The TurtleBot3 Robot Project is an interdisciplinary collaboration involving Open Robotics, ROBOTIS, and
other partners aimed at developing a compact and cost-effective mobile robot, based on the Robot Operating
System (ROS), intended to be utilized in educational, research, hobbyist, and product prototyping contexts.
• Project Objectives
The primary objective of this endeavor is to provide a flexible platform that can be tailored and expanded to
meet diverse application and scenario requirements, encompassing areas such as home service robotics,
autonomous navigation, manipulation, and artificial intelligence. The specific aims of the project include:
o Significantly reducing the physical footprint and financial burden associated with the robot, while
maintaining its capabilities and standards of quality.
o Facilitating modularity and compatibility with various hardware and software constituents.
o Supporting the integration of an array of sensors and actuators, including those for LIDAR, IMU,
camera, gripper, among others.
o Harnessing the vast ROS ecosystem and community to facilitate simplified development and
deployment of robotic applications.
• Project Challenges
The undertaking is faced with numerous challenges, which encompass:
o
o
o
o
•
The design of a robot that harmoniously combines performance, durability, and affordability.
The seamless integration of diverse components, ensuring their compatibility and reliability.
The development and testing of an assortment of functionalities and algorithms specific to the robot.
The provision of comprehensive documentation and tutorials for both end-users and developers.
Project Timeline
o
o
o
o
o
The evolutionary timeline of the project can be outlined as follows:
The foundation of the project was laid by Open Robotics and ROBOTIS in 2016.
The first prototype of the TurtleBot3 robot was formally introduced at the ROSCon conference in 2017.
The robot achieved its official launch in 2018, becoming commercially available for purchase.
Continuous updates and enhancements are being made to the project by both the developers and the
wider community, ensuring its ongoing development and improvement.
Page 2 of 10
3. History behind Building the TurtleBot3.
•
The
Background
conception of the TurtleBot3 arose from the need to rectify certain deficiencies and integrate
advancements based on valuable user input, drawing upon the foundations established by the preceding
iterations of the TurtleBot. Originally instigated by Willow Garage, a renowned robotics research laboratory,
the TurtleBot project was undertaken with the objective of producing a reasonably priced and easily accessible
robot platform that can be utilized for research and educational purposes.
To carry forward the TurtleBot's enduring legacy, Open Robotics and ROBOTIS collaborated to develop the
TurtleBot3. This collaboration brought forth notable improvements, such as a more compact and lightweight
design, enhanced sensor integration, and an updated version of the Robot Operating System (ROS) framework.
These enhancements were introduced with the intention of furnishing an even more streamlined and potent
platform that serves the pursuit of knowledge and experimental exploration in the field of robotics.
• Inspiration
The project also found inspiration from various pertinent research and technologies. Notable influences
encompassed the utilization of the Logo programming language and the turtlesim node. These resources were
integral in teaching computer programming and ROS (Robot Operating System) concepts through the use of a
simulacrum turtle robot. Additionally, attention was drawn to the DYNAMIXEL smart actuator, renowned for
its exceptional servo motor capabilities that allow for manipulation by a microcontroller, as well as monitoring
functionalities. Acknowledgment was also given to the Raspberry Pi and Jetson Nano, two compact yet
formidable single-board computers, capable of executing ROS and additional software. Lastly, the
implementation of a 360-degree distance sensor and the integration of 3D printing technology were also
deemed crucial to facilitate the robot's perception of its surroundings and offer customization options in relation
to shape and size.
4. Body - Sensors, Actuators, Mechanical, and Electrical Parts
• Sensors
The robot utilizes a variety of sensors to perceive and monitor both its surrounding environment and its
internal state. These sensors encompass:
o LIDAR, a laser-based device adept at gauging the distances and angles of objects proximate to the
robot.
o IMU, functioning as an inertial measurement unit, enables the measurement of the robot's orientation,
acceleration, and angular velocity.
o Camera, serving as an optical sensor, captures visual data in the form of images and videos of the scene
laying ahead of the robot.
o Encoders comprising sensors employed to assess the rotation and velocity of both wheels and motors,
further contribute to the robot's perception capabilities.
o Current sensor to facilitates the quantification of electric current flow within the circuit.
Page 3 of 10
• Actuators
The TurtleBot3 utilizes a range of distinct actuators in order to execute a multitude of actions and motions,
among these actuators are:
o DYNAMIXEL MOTORS, which are intelligent actuation devices capable of being regulated and
observed by a microcontroller.
o WHEELS, which are circular components that are employed in conjunction with the motors are
facilitate locomotion of the robot along surfaces.
o CASTER, a spherical component located at the rear of the robot, serves the purpose of averting any
instances of toppling over.
o GRIPPER, characterized as a mechanical apparatus, enables the robot to securely seize and
manipulate various objects.
• Mechanical components
The TurtleBot3 is composed of various mechanical components that contribute to its form and configuration
such as:
o Modular Plates, which are flat components that permit flexible connections and configurations for
the creation of the TurtleBot3 physical framework.
o SPACERS, SCREWS, INSERTS, are employed to effectively fasten and secure the plates along
with other constituent elements.
o BATTERY HOLDER, to serves the dual purpose of housing and attaching the battery to the
TurtleBot3 body.
o LIDAR MOUNT, which securely affixes the LIDAR sensor atop the TurtleBot3body.
• ELECTRICAL / ELECTRONIC COMPONENTS
The robot is equipped with a variety of electronic components and circuitry necessary for its power supply
and operation. These components include:
o BATTERY, which serves as a storage and supply unit for electrical energy.
o MOTOR DRIVER is employed to regulate the speed and direction of the motors.
o VOLTAGE REGULATOR is responsible for converting the initial voltage to a steady output
voltage.
o SINGLE-BOARD COMPUTER is also utilized to run the Robot Operating System (ROS) and other
software essential for the robot's functioning
o ARDUINO MICROCONTROLLER is integrated into the system Acting as a communication
intermediary between the sensors, actuators, and code execution.
o PROTO-BOARD is implemented to facilitate the interconnection of various components and wires
o The overall circuit control is augmented with the inclusion of switches, LEDs, resistors, connectors,
and wires, serving to manage, indicate, safeguard, and establish connections within the circuitry.
Page 4 of 10
5. Code behind running the TurtleBot3.
• Programming Language:
The TurtleBot3 project is a robotic system that employs a combination of Python and C++
programming languages. The Robot Operating System (ROS) serves as the core framework for
TurtleBot3, which supports multiple programming languages. Within the ROS ecosystem, Python and
C++ are the primary languages used for development. The TurtleBot3 codebase comprises various
components and functionalities that may be implemented using both Python and C++. This approach
leverages the strengths of each language for different aspects of the robotic system. The specific choice
of language may also depend on the task or module within the TurtleBot3 software architecture. The
TurtleBot3 code implements the main functionalities of the TurtleBot3, such as:
o
Initialization, which is the process of setting up the robot’s parameters and variables.
o
Communication, which is the process of exchanging data and messages between TurtleBot3
and other devices.
o
Control, which is the process of regulating the robot’s actions and movements.
o
Navigation, which is the process of planning and executing the robot’s path and pose.
o
Manipulation, which is the process of grasping and moving objects with the robot’s gripper.
• Functionality Overview:
The TurtleBot3 code governs a spectrum of functionalities, including sensor data processing, path planning,
and motor control. It enables the robot to perform tasks like autonomous navigation, obstacle avoidance, and
map creation.
The code controls the TurtleBot3 behavior and interactions with its environment by using the ROS
framework, which is a software platform that provides libraries and tools for developers such as:
o
Consists of several ROS nodes, which are programs that perform specific tasks and
communicate with each other.
o
The TurtleBot3 code uses several ROS topics, which are channels that transmit data and
messages between nodes.
o
Subscribes and publishes to different ROS topics, which means that it receives and sends data
and messages to another node.
o
Uses several ROS services, which are requests and responses that are exchanged between
nodes.
o
Calling and providing different ROS services, which means that it asks and answers questions
to other nodes.
o
Using several ROS actions, which are goals and feedback that are exchanged between nodes.
o
The TurtleBot3 sends and receives different ROS actions, which means that it sets and
monitors objectives for other nodes.
Page 5 of 10
6. General explanation of the TurtleBot3 code.
• Code division
The code can be divided into four main sections: header files, macros, class
definition, and main function.
o
Header files are files that contain declarations and definitions of variables, functions, classes,
and libraries that are used in the code.
o
Macros are preprocessor directives that define constants or expressions that are replaced by
the compiler before the code is executed.
o
Class definition is a block of code that defines the attributes and methods of a custom data
type, in this case, the turtlebot3 object.
o
Main function is a special function that is the entry point of the program and contains the main
logic of the code.
• Code algorithms
The uses of several algorithms and techniques to achieve the desired functionality
of the robot, such as:
o
PID control, which is a feedback control technique that adjusts the output of the system based
on the error between the desired and actual values.
o
Odometry, which is a method of estimating the position and orientation of the robot based on
the data from the encoders and the IMU.
o
SLAM, which is a technique of simultaneously mapping the environment and localizing the
robot within it using the data from the LIDAR and the camera.
o
Path planning, which is a process of finding a feasible and optimal path for the robot to reach
a goal location while avoiding obstacles.
o
Inverse kinematics, which is a method of calculating the joint angles of the gripper based on
the desired position and orientation of the end-effector.
7. Detailed explanation of the TurtleBot3 code.
In continuation of section five, three code snippets are presented along with their
explanations. The first example was implemented using Python, while the second and third
examples were coded using C++.
This approach leverages the strengths of each language for different aspects of the robotic
system. The specific choice of language may also depend on the task or module within the
TurtleBot3 software architecture.
Page 6 of 10
• Example#1: Python snippet code
Demonstration of a simple example of TurtleBot3 motor control.
o Sensor Integration: Reads data from sensors and preprocesses it.
o Perception: Involves computer vision algorithms for object recognition and understanding the surroundings.
o Planning: Utilizes path planning algorithms to determine the best route for the robot.
o Control: Implements motor control algorithms to execute planned movements.
# Example#1 Sample code snippet for TurtleBot3 motor control
import rospy
from geometry_msgs.msg import Twist
def move_forward():
rospy.init_node('turtlebot3_movement')
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
rate = rospy.Rate(10) # 10Hz
while not rospy.is_shutdown():
move_cmd = Twist()
move_cmd.linear.x = 0.2 # Move forward at 0.2 m/s
pub.publish(move_cmd)
rate.sleep()
if __name__ == '__main__':
try:
move_forward()
except rospy.ROSInterruptException:
pass
A Breakdown into logical sections to explain the purpose and functionality of each section.
Section 1: Importing Libraries
import rospy
from geometry_msgs.msg import Twist
This section imports the necessary libraries. `rospy` is a Python client library for ROS, and `Twist` is a
message type representing linear and angular velocities used for robot movement.
Section 2: Function Definition
def move_forward():
Defines a function named to encapsulate the logic for moving the TurtleBot3 forward.
Section 3: ROS Node Initialization
rospy.init_node('turtlebot3_movement')
Initializes a ROS node named 'turtlebot3_movement'. In ROS, a node is a process that performs computation.
Section 4: Publisher Initialization
pub = rospy.Publisher('/cmd_vel', Twist, queue_size=10)
Initializes a ROS publisher for sending messages to the '/cmd_vel' topic. This topic is commonly used for
controlling the velocity of a robot.
Section 5: Rate Initialization
rate = rospy.Rate(10) # 10Hz
Sets the publishing rate to 10 Hz. This determines how often the robot's velocity command is updated.
Page 7 of 10
Section 6: Main Loop
while not rospy.is_shutdown():
Starts a loop that continues until the ROS node is shutdown.
Section 7: Twist Message Initialization
move_cmd = Twist()
Creates an instance of the `Twist` message to store linear and angular velocity commands.
Section 8: Setting Linear Velocity
move_cmd.linear.x = 0.2 # Move forward at 0.2 m/s
Sets the linear velocity of the TurtleBot3 to 0.2 m/s, indicating a forward movement.
Section 9: Publishing Velocity Command
pub.publish(move_cmd)
Publishes the velocity command to the '/cmd_vel' topic.
Section 10: Rate Control
rate.sleep()
Controls the loop rate to achieve the desired publishing frequency (10 Hz in this case).
Section 11: Main Function Execution
if __name__ == '__main__':
try:
move_forward()
except rospy.ROSInterruptException:
pass
The main function is executed. It calls the `move_forward()` function within a try-except block to handle
potential ROS interrupt exceptions.
• Example#2: C++snippet code
The code segment defines the header files, macros, and class definition for the turtlebot3
object.
o
The header files include the ROS library and the messages and services that are used in the code, such as
the twist, odometry, and dynamixel state list messages.
o
The macros define the constants that are used in the code, such as the wheel radius, wheel separation,
encoder min and max values, and RPM constant value.
o
The class definition defines the attributes and methods of the turtlebot3 object, such as the node handle,
subscribers, publishers, clients, variables, and functions.
o
The class definition also defines the constructor and destructor of the turtlebot3 object, which are special
methods that are called when the object is created and destroyed.
o
The class definition also defines the callback functions of the turtlebot3 object, which are functions that
are executed when a specific event occurs, such as receiving a message from a topic.The code segments
can be explained in more detail as follows:
Page 8 of 10
Example#2: This code initializes a ROS node, sets up a publisher to control the TurtleBot3's
velocity, and enters a loop where it continuously publishes forward movement commands at a
specified rate. The provided script is a basic example and would typically be extended to
handle more complex robotic behaviors.
1. // Example#2 :This is a snippet of code that initializes the robot's parameters and variables
2.
3. #include <ros/ros.h> // This is a header file that includes the ROS library
4. #include <dynamixel_workbench_msgs/DynamixelStateList.h> // This is a header file that includes the DYNAMIXEL state
message
5. #include <geometry_msgs/Twist.h> // This is a header file that includes the twist message
6. #include <nav_msgs/Odometry.h> // This is a header file that includes the odometry message
7. #include <tf/tf.h> // This is a header file that includes the tf library
8. #include <tf/transform_broadcaster.h> // This is a header file that includes the transform broadcaster
9.
10. #define WHEEL_RADIUS 0.033 // This is a macro that defines the wheel radius in meters
11. #define WHEEL_SEPARATION 0.287 // This is a macro that defines the wheel separation in meters
12. #define ENCODER_MIN -2147483648 // This is a macro that defines the minimum value of the encoder
13. #define ENCODER_MAX 2147483648 // This is a macro that defines the maximum value of the encoder
14. #define RPM_CONSTANT_VALUE 0.229 // This is a macro that defines the constant value to convert RPM to m/s
15.
16. class Turtlebot3 // This is a class that defines the turtlebot3 object
17. {
18. public:
19.
Turtlebot3(); // This is a constructor that creates the turtlebot3 object
20.
~Turtlebot3(); // This is a destructor that destroys the turtlebot3 object
21.
bool init(); // This is a method that initializes the robot's parameters and variables
22.
void close(); // This is a method that closes the robot's communication and resources
23.
bool controlMotor(const float wheel_velocity[2]); // This is a method that controls the motor speed and direction
24.
bool readEncoder(int32_t &left_value, int32_t &right_value); // This is a method that reads the encoder values
25.
bool updateOdometry(); // This is a method that updates the odometry values
26.
bool resetOdometry(); // This is a method that resets the odometry values
27.
void publishOdometry(); // This is a method that publishes the odometry values
28.
void commandVelocityCallback(const geometry_msgs::TwistConstPtr &msg); // This is a callback function that
receives the command velocity message
29.
void dynamixelStateListCallback(const dynamixel_workbench_msgs::DynamixelStateListConstPtr &msg); // This is a
callback function that receives the dynamixel state list message
30. private:
31.
ros::NodeHandle nh_; // This is a private variable that defines the node handle
32.
ros::Subscriber cmd_vel_sub_; // This is a private variable that defines the command velocity subscriber
33.
ros::Subscriber dynamixel_state_list_sub_; // This is a private variable that defines the dynamixel state list
subscriber
34.
ros::Publisher odom_pub_; // This is a private variable that defines the odometry publisher
35.
ros::ServiceClient dynamixel_command_client_; // This is a private variable that defines the dynamixel command
client
36.
tf::TransformBroadcaster tf_broadcaster_; // This is a private variable that defines the transform broadcaster
37.
std::string joint_states_name_[2]; // This is a private variable that defines the joint states name array
38.
double wheel_separation_; // This is a private variable that defines the wheel separation
39.
double wheel_radius_; // This is a private variable that defines the wheel radius
40.
bool init_encoder_; // This is a private variable that defines the initialization flag of the encoder
41.
bool init_odometry_; // This is a private variable that defines the initialization flag of the odometry
42.
int32_t last_diff_tick_[2]; // This is a private variable that defines the last difference tick array
43.
double last_rad_[2]; // This is a private variable that defines the last radian array
44.
double odom_pose_[3]; // This is a private variable that defines the odometry pose array
45.
double odom_vel_[3]; // This is a private variable that defines the odometry velocity array
46.
double goal_linear_velocity_; // This is a private variable that defines the goal linear velocity
47.
double goal_angular_velocity_; // This is a private variable that defines the goal angular velocity
48.
double cmd_vel_timeout_; // This is a private variable that defines the command velocity timeout
49.
double prev_update_time_; // This is a private variable that defines the previous update time
50.
double dynamixel_power_; // This is a private variable that defines the dynamixel power
Page 9 of 10
• Example#3: C++ snippet code
A snippet C++ code segment That defines the controlMotor method of the turtlebot3 object,
which is a method that controls the motor speed and direction.
o
o
o
o
o
o
o
o
The method takes an array of two floats as an input, which represents the desired wheel
velocities in m/s.
The method returns a boolean value as an output, which indicates whether the operation was
successful or not.
The method declares and initializes some local variables, such as the id array, the
goal_velocity array, and the dynamixel_command object.
The id array contains the IDs of the left and right motors, which are defined as constants in
another file.
The goal_velocity array contains the desired motor velocities in RPM, which are calculated by
dividing the wheel velocities by the RPM constant value.
The dynamixel_command object is an instance of the dynamixel command service, which is
used to send commands to the dynamixel motors.
The method uses a for loop to iterate over the two motors and send the corresponding goal
velocities to them.
The method uses the dynamixel_command_client_ variable, which is a private variable that
defines the dynamixel motor.
1. // This is a snippet of code that controls the motor speed and direction
2.
3. bool Turtlebot3::controlMotor(const float wheel_velocity[2])
4. {
5.
bool result = false;
6.
const char* log = NULL;
7.
8.
uint8_t id[2] = {0, 0};
9.
id[0] = DXL_LEFT_ID;
10.
id[1] = DXL_RIGHT_ID;
11.
12.
int32_t goal_velocity[2] = {0, 0};
13.
goal_velocity[0] = wheel_velocity[LEFT] / RPM_CONSTANT_VALUE;
14.
goal_velocity[1] = wheel_velocity[RIGHT] / RPM_CONSTANT_VALUE;
15.
16.
dynamixel_workbench_msgs::DynamixelCommand dynamixel_command;
17.
dynamixel_command.request.command = "";
18.
19.
for (int index = 0; index < 2; index++)
20.
{
21.
dynamixel_command.request.id = id[index];
22.
dynamixel_command.request.addr_name = "Goal_Velocity";
23.
dynamixel_command.request.value = goal_velocity[index];
24.
25.
result = dynamixel_command_client_.call(dynamixel_command);
26.
if (result == false)
27.
{
28.
ROS_ERROR("%s", dynamixel_command.response.comm_result.c_str());
29.
return false;
30.
}
31.
}
32.
33.
return true;
34. }
35.
8. References
emanual.robotis.com --- instructables.com --- https://github.com/ROBOTIS-GIT/turtlebot3
Page 10 of 10
Download