Simple ROS packages to control and simulate the rotation of a two axis camera with a joystick.
The following repository holds two ROS packages that simulate and control a 2DOF camera turret which can be controlled with a joystick.
Each package includes:
- camera_turret: It holds a ROS-Gazebo package to simulate the control of the two axis camera with a joystick.
- camera_turret_3D_printer: It holds a ROS package to move the 3D printed two axis camera with a joystick using an Arduino.
Just follow the next steps:
- Install the
camera_turret_3D_printer
package - 3D print the camera-turret and assemble the pieces
- Setup the electronics
- Plug in the joystick
- Plug in the camera
- Execute
roslaunch launchMe.launch
- Wait until everything is ready
- Press the directional keys on the joystick
- The camera-turret should be moving!
For those of you who don't own a 2 axis camera, look at STL files of this repository. Here I included the STL files I used to create the model you see here, so you can 3D print the same camera-turret I used:
The servomotors' control is done using an Arduino UNO. However, keep in mind that the power output of the Arduino UNO microcontroller is limited, so an external power supply is recommended in order to avoid damaging the microcontroller. Please follow this schematics in order to setup your electronics:
Don't forget to load the program included here in your Arduino UNO.
There are three main parts you should care about:
- script: It holds the code for remapping the joystick's keystrokes into position commands received by the Arduino UNO microcontroller.
- Arduino: It holds the Arduino's file to receive and control the servomotors.
- launch file: It holds the code that will be executed by roslaunch and it will set up all the nodes accordingly.
The way this ROS package works is as follows:
- The
joy_node
reads the pressed axes and buttons and sends them to thejoy_to_command
node joy_to_command
continuously reads thejoy_node
's data, updates the angle of each servomotor and sends the angle to theserial_node
.serial_node
continuously reads the commands and positions each servomotors accordingly
You should install/have the following:
- ROS-lunar
- Python
- Joy (ROS package)
- USB joystick
- USB camera
- Arduino UNO
- Two servomotors
Just follow the next steps:
- Install the
camera_turret
package - Plug in the joystick
- Execute
roslaunch launchMe.launch
- Wait until Gazebo is loaded
- Press the directional keys on the joystick
- The camera-turret should be moving!
There are three main parts you should care about:
- script: It holds the code for remapping the joystick's keystrokes into position commands received by the camera-turret.
- urdf: It holds the URDF file that defines the camera-turret's dynamics and kinematics.
- launch file: It holds the code that will be executed by roslaunch and it will set up all the nodes and simulation accordingly.
This repository can be divided into two main components, the simulation and the ROS environment. Below code is for a more in-depth explanation, which you shouldn't care about as it is done automatically by the system when using roslaunch launchMe.launch
.
For controlling the "robot", we want to pass a couple of positional commands to control the 2DOF of the system. As in this case we will be connecting the ROS environment to a simulated world, we add the libgazebo_ros_control.so
plugin to the URDF to allow a communication between ROS and Gazebo and we add some transmission_interface
s to allow for a positional control.
Once the urdf is prepared, we create a simple script ("joy_to_command.py") that converts the readings from a joystick into an actual commands for the "robot". The reading of the joysticks is handled by the "Joy_node" which is loaded from the "Joy" ROS package. All this gives a result the following graph:
The camera-turret is composed of 3 links, the base_link, the mobile_link and the camera_link. There are two joints, one between the base_link and the mobile_link and another one between the mobile_link and the camera_link. Below you can find the described setup:
Once everything is setup, the whole result should be the following:
You should install/have the following:
- ROS-lunar
- Gazebo
- Python
- Joy (ROS package)
- USB joystick