In this repository is the development of the first laboratory guide for robotics subject at the Universidad Nacional Colombia.
- ROS Noetic
- Turtlesim package (Pre-installed with ROS)
- ROS toolbox for MATLAB
- Pynput libray for python (
pip install pynput
orpip3 install pynput
) - Numpy libray (optional)
If you don't want to use numpy, change np.pi of teleop file to 3.1415...
In order to create a new package, we used the next command (in the workspace folder):
catkin create pkg hello_turtle -m "Cristian Chitiva" "cychitivav@unal.edu.co" -m "Brayan Estupinan" "blestupinanp@unal.edu.co" -l "MIT" --catkin-deps rospy turtlesim
It is necessary have catkin tools installed in your system (
sudo apt install python3-catkin-tools
).
This package depends on the turtlesim package, so we need to install it first (commonly is pre-installed with ROS Noetic), also is necessary have the rospy package installed to create python files for ROS. To install this dependencies you can use the following command (in the workspace folder):
rosdep install --from-paths src --ignore-src -y
In the first part of the lab, the MATLAB ROS toolbox is used to become familiar with the connection between MATLAB and ROS. Initially a subscriber to the pose topic is created to view the current pose of the turtle (turtlesim package). Also, to implement MATLAB's connection to ROS services, the teleport_relative service is called to move the turtle to any position.
Open two terminals and run the following commands:
Run master node
roscore
Run turtlesim node
rosrun turtlesim turtlesim_node
And finally, run this in MATLAB command window
run matlab/matlab_ros_connection.m
run matlab/matlab_rossubs.m
run matlab/matlab_rossrv.m
or in the terminal
matlab -nosplash -nodesktop -r "run matlab/matlab_ros_connection.m, run matlab/matlab_rossubs.m, run matlab/matlab_rossrv.m"
In the matlab ros connector file we created a script that connects MATLAB to ROS and create a publisher to send Twist message by the topic cmd_vel. The second script contains the code to create a subscriber to the topic pose and to get the current pose of the turtle(latest message). Finally, the third script contains the code to create a service client to call the service teleport_absolute and to send the message to move the turtle to a new position; in this script is the command rosshutdown to close the connection with ROS.
AIn order to practice the commands to create publishers, subscribers and services from python, a script was created to move the turtle of the turtlesim node using the keyboard. To achieve this we used the pynput library and optionally the numpy library to rotate the turtle exactly pi radians.
Open three terminals and run the following commands:
roscore
rosrun turtlesim turtlesim_node
rosrun hello_turtle myTeleopKey.py
Note: Don't forget source devel/setup.bash
To move the turtle from the terminal use the following keys:
* w: move forward
* a: rotate left
* s: move backward
* d: rotate right
* Space: Rotate turtle
* r: Reset position
Note: You must have focused the terminal where the myTeleopKey.py node is running
To run all nodes with a only command we created a launch file. To run this launch file we used the following command:
roslaunch hello_turtle runKeyTeleop.launch