Skip to content

ROS package to move a turtle with the keyboard using MATLAB and Python. This repo is part of the first practice lab for robotics class at Universidad Nacional de Colombia

License

Notifications You must be signed in to change notification settings

cychitivav/hello_turtle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello turtle package

In this repository is the development of the first laboratory guide for robotics subject at the Universidad Nacional Colombia.

Requirements

  • ROS Noetic
  • Turtlesim package (Pre-installed with ROS)
  • ROS toolbox for MATLAB
  • Pynput libray for python (pip install pynput or pip3 install pynput)
  • Numpy libray (optional)

If you don't want to use numpy, change np.pi of teleop file to 3.1415...

Package creation

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

MATLAB-ROS connection

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.

Execution

Open two terminals and run the following commands:

First terminal

Run master node

roscore

Second terminal

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.

rosgraph

Python keyboard control

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.

Execution

Open three terminals and run the following commands:

First terminal

roscore

Second terminal

rosrun turtlesim turtlesim_node

Third terminal

rosrun hello_turtle myTeleopKey.py

Note: Don't forget source devel/setup.bash

Controls

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

Roslaunch

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 

About

ROS package to move a turtle with the keyboard using MATLAB and Python. This repo is part of the first practice lab for robotics class at Universidad Nacional de Colombia

Topics

Resources

License

Stars

Watchers

Forks