Note: This tutorial assumes that you have completed the previous tutorials: Preparing a new script (python).
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Using other commands (python)

Description: This tutorial teaches you how to use other commands beside the move command.

Tutorial Level: BEGINNER

Apart from the Move command, cob_script_server provides some basic functionality for other subsystems of the robot, e.g.: You can play a wave file or say text using a text to speech system, you can also change the color of the LEDs in Care-O-bot's torso, get some user input, etc. ...

Speech

cob_script_server provides two functions for producing sound:

Speak(<parameter_name>,<mode (optional)>)
SpeakStr(<text_to_be_spoken>,<mode>)

The Speak function

The first function allows you to produce a sound specified by <parameter_name> in an output mode specified by <mode>. Possible modes are:

  • "DEFAULT" - use the default mode set by the global parameter speech_mode. The global parameter is set in <cob_script_server>/launch/sound.yaml and has to be one of the other possible modes.

  • "WAV_DE" - play wav-Files with German text. The directory for the wave file is set in global parameter wav_de_path.

  • "WAV_EN" - play wav-FIles with English text. The directory for the wave file is set in a global parameter wav_en_path.

  • "FEST_EN" - use free text-to-speech system Festival. It should already be installed on your computer as some other ROS packages depend on it.

  • "CEPS_EN" - use commercial text-to-speech Cepstral with the English voice David. Of course this only works if you have bought and installed the voice on your computer.

  • "CEPS_DE" - use commercial text-to-speech Cepstral with the German voice Matthias. Of cause this only works if you have bought and installed the voice on your computer.

  • "MUTE" - play no sound at all but show a message each time a sound would be played. This is a good option for not beeing annoyed while testing your script.

The basic idea behind these different modes is that you can change the mode any time you want. For example you could have a presentation for English-speaking people one day and for German-speaking people another day. Say that for the English version you would like to use Festival text-to-speech but having no German voice installed you would like to use wave files for the German presentation. Here is what you have to do:

  • Set up all sentences for the English presentation in <cob_script_server>/launch/sound.yaml. For our grasp script the file might look like this:

       1  speech_en/grasp_tutorial_01: "Hello, my name is Care-O-bot!"
       2  speech_en/grasp_tutorial_02: "I will get you something to drink."
       3  speech_en/grasp_tutorial_03: "Here is your drink!"
    

    Note that all english sentences are are in a seperate namespace called speech_en

  • For the German presentation, record your wave files, name them in the same way as your parameters an put them in the folder specified by the paramter wav_de_path. For our grasp script the directory might look like this:

     $ ls
         grasp_tutorial_01.wav
         grasp_tutorial_02.wav
         grasp_tutorial_03.wav

    For this tutorial the wav files are already provided in folder <cob_script_server>/common_files/wav_de/. Please ensure that the absolute(!) path to this directory is available as wav_de_path in sound.yaml.

Now go on and add some speech commands to your grasp script. For example you could add a greeting message in the beginning. When the drink is ready you speak another sentence saying that the user can now take the drink. Find out how it works best! - or try this solution:

   1     def GraspObject(self):
   2         rospy.loginfo("Grasping an object from table...")
   3         # speak greeting
   4         self.sss.Speak("grasp_tutorial_01")
   5         self.sss.Speak("grasp_tutorial_02")
   6 
   7         # prepare for grasping
   8         myhandle = self.sss.Move("arm","pregrasp",False)
   9         self.sss.Move("sdh","cylopen")
  10         myhandle.wait()
  11         # grasp the object
  12         self.sss.Move("arm","grasp")
  13         self.sss.Move("sdh","cylclosed")
  14         # put object on tray
  15         myhandle = self.sss.Move("arm","grasp-to-tablet",False)
  16         self.sss.Move("tray","up")
  17         myhandle.wait()
  18         self.sss.Move("sdh","cylopen")
  19         # draw arm back to folded position
  20         myhandle = self.sss.Move("arm","tablet-to-folded",False)
  21         self.sss.Move("sdh","cylclosed")
  22         myhandle.wait()
  23 
  24         # inform user that he may take the drink
  25         self.sss.Speak("grasp_tutorial_03")

The SpeakStr function

The Speak function requires that you have a parameter for every text you want to speak. If you just want add some spoken words to your script very quickly or if you want to change your messages dynamically during runtime, you can use SpeakStr function. The difference to the Speak function is, that you hand over the string to be spoken directly as a parameter. Of cause this only works for text-to-speech systems (not for wave files). Therefore the <mode> parameter is required for this function. Possible modes are:

  • "FEST_EN" - use free text-to-speech system Festival. It should already be installed on your computer as some other ROS packages depend on it.

  • "CEPS_EN" - use commercial text-to-speech Cepstral with the English voice David. Of cause this only works if you have bought and installed the voice on your computer.

  • "CEPS_DE" - use commercial text-to-speech Cepstral with the German voice Matthias. Of cause this only works if you have bought and installed the voice on your computer.

If you like, make a few tests with SpeakStr function. Add some funny texts to your grasp script!

Setting LED color

cob_script_server also allows you to change the color of the LEDs in Care-O-bot's torso. The command is

SetLight(<color_parameter>)

Once again the parameters for the different colors are set in a seperate file, <cob_script_server>/launch/light.yaml this time. Each LED parameter consists of three numbers which are more or less an RGB notation. Unfortunately the brightness of the different colors is not the same, so a nice white light is [250,999,300].

You can use the LEDs to give a visual feedback of the robot's status or task. For example you could set the LEDs to yellow everytime the arm is moving (signals "attention!") and back to green when the arm stopps. Another idea would be to use a certain color (e.g. blue) to indicate that user interaction (e.g. taking the bottle) is allowed or required.

Waiting for input or confirmation

Sometimes it is helpful to suspend a script until the user confirms by pressing a key. Of cause a real autonomous robot wouldn't need something like that but for testing it's nice to have. cob_script_server provides a function

input_string = wait_for_input()

to wait for confirmation. The function is blocking until the Return key is hit. If the user enters a string and hits Return afterwards, you can read out the input from variable input_string. Note that the Return key itself produces a linefeed character (\n). This is important if you want to compare strings afterwards.

Say you want to lower the tray once the drink has been taken by the user. As you do not know when this will happen you could wait for some helpful guy to press a button to indicate that the drink is gone. In order to do so, add the following lines to the end of the grasp script

   1         # wait for signal that the drink has been taken
   2         self.sss.wait_for_input()
   3         self.sss.Move("tray","down")

Congratulations! You have written your first grasp script using cob_script_server!

Wiki: cob_script_server/Tutorials/Using other commands (python) (last edited 2015-11-12 12:59:03 by EliasMarks)