Developing ROS programs for the Sphero robot

Written by Ricardo Tellez

09/03/2017

 

You probably know the Sphero robot. It is a small robot with the shape of a ball.

In case that you have one, you must know that it is possible to control it using ROS, by installing in your computer the Sphero ROS packages developed by Melonee Wise and connecting to the robot using the bluetooth of the computer.

Now, you can use the ROS Development Studio to create ROS control programs for that robot, testing as you go by using the integrated simulation. Let’s see how to do that.

First step, develop your Sphero program in the simulation environment

The ROS Development Studio (RDS) provides off-the-shelf a simulation of Sphero within a maze environment. The simulation provides the same interface as the ROS module created by Melonee, so you can test your programs on the environment, and once working properly, transfer it to the real robot.

We created the simulation to teach ROS to the students of the Robot Ignite Academy. They have to learn ROS enough to make the Sphero get out of the maze by using odometry and IMU. What follows applies to both the development of Sphero control programs using the Robot Ignite Academy, or the development using the ROS Development Studio.

Screenshot from 2017-03-09 19:28:57

 

Using the simulation

  • To use the Sphero simulation in the Robot Ignite Academy, go to the ROS in 5 days course and select the Sphero Course Project. The Sphero simulation must appear on the screen.
  • To use the Sphero simulation on RDS go to rds.theconstructsim.com and sign in. If you select the Public simulations, you will quickly identify the Sphero simulation.

Screenshot from 2017-03-09 19:22:51

 

Press the red Play button. A new screen will appear giving you details about the simulation and asking you which launch file you want to launch. The main.launch selected by default is the correct one, so just press Run.

Screenshot from 2017-03-09 19:23:18

 

In either case, after a few seconds the simulation will appear together with the development environment for creating the programs for Sphero and testing them.

Screenshot from 2017-03-09 19:34:15

 

On the left hand side you have a notebook containing information about the robot and how to program it with ROS. This notebook contains just some examples, but it can be completed and/or modified at your will. As you can see it is an iPython notebook and follows its standard. So it is up to you to modify it, add new information or else. Remember that any change you do to the notebook will be saved in a simulation in your private area of RDS, so you can come back later and launch it with your modifications.

Screenshot from 2017-03-09 19:39:20

 

You must know that the code included in the notebook is directly executable by selecting the cell of the code (do a single click on it) and pressing the small play button at the top of the notebook. This means that, once you press that button, the code will be executed and start controlling the Sphero simulated robot for a few time-steps (remember to have the simulation activated (Play button of the simulation activated) to see the robot move).

On the center area, you can see the IDE. It is the development environment for developing the code. You can browse there all the packages related to the simulation or any other packages that you may create.

Screenshot from 2017-03-09 19:41:32

 

On the right hand side, you can see the simulation and beneath it, the shell. The simulation shows the Sphero robot as well as the environment of the maze. On the shell, you can issue commands in the computer that contains the simulation of the robot. For instance, you can use the shell to launch the keyboard controller and move the Sphero around. Try typing the following:

$ roslaunch sphero_gazebo keyboard_teleop.launch

Now you must be able to move the robot around the maze by pressing some keys of the keyboard (instructions provided on the screen).

 

Screenshot from 2017-03-09 19:45:51

 

You can also launch there Rviz, and then watch the robot, the frames and any other additional information you may want of the robot. Type the following:

$ rosrun rviz rviz

Then press the Screen red icon located at the bottom-left of the screen (named the graphical tools). A new tab should appear, showing how the Rviz is loading. After a while, you can configure the Rviz to show the information you desire.

Screenshot from 2017-03-09 19:52:10

 

There are many ways you can configure the screen to provide more focus to what interests you the most.

Screenshot from 2017-03-09 20:07:11

 

Screenshot from 2017-03-09 20:07:44

Second step, transfer your program to the real robot

Once you have finished your program in the simulation environment, it is time to test it with the real robot. For that, you will need several steps:

Install the Sphero ROS node in your local computer

 

At this point, you should have a local computer that has ROS installed on it, that can also communicate with the Sphero. Now it is time to get your programs developed in the simulation environment and execute them in the local computer controlling the real Sphero.

Download your Sphero program to the local computer

Once you have your Linux computer connected to the Sphero robot, you can test your Sphero program. For that, first you need to download the code you did on the simulator to your local computer:

  • On your local computer, create a catkin_ws. You can find instructions about how to do it here.
  • Go to the IDE of the simulation environment and select the ROS packages that contain your Sphero code. Then press right click and select Download option. Download the packages to the catkin_ws/src directory of your local machine.
  • Uncompress the packages in that directory.
  • Then compile the packages. For that do the following:
    • cd ~/catkin_ws
    • catkin_make
  • Now you are ready to launch your ROS code and make it work with the real robot! Launch your code the same way you did in the simulation environment
  • Do not expect that your code will work in the real robot exactly as in the simulation. There are usually differences between simulation and real robots. You will have to discover them by practicing. So if something goes wrong just repeat the loop of design of the programs and test.

Conclusions

We have shown here how you can reproduce the professional way of developing software for robots, by using simulations first to create and test the programs, and then, transfer the running programs to the real robot.

There exists an easier way to run the programs developed at the RDS which consists of stablishing a connection between the RDS and the real robot. This option is only available to paying users of RDS.

Video: showing how The Construct instructs about ROS and performs tests in simulation and real Sphero transfer with the students:

Topics:
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

1 Comment

  1. BusterJuicy

    Hi. I see that you don’t update your blog too often.
    I know that writing articles is time consuming
    and boring. But did you know that there is a tool that allows you to
    create new posts using existing content (from article directories or other pages from your niche)?

    And it does it very well. The new articles are
    unique and pass the copyscape test. You should try miftolo’s tools

    Reply

Trackbacks/Pingbacks

  1. On not using ROS for your robotics product | The Construct - […] may not require to use ROS (however, here there is the code that ROSifies a Sphero robot, and here a post about […]

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This