make robot talk running script on terminal

If you need technical help with anything you've bought from Dawn Robotics, please post here.

make robot talk running script on terminal

Postby Adeste » Tue Feb 17, 2015 9:20 am

Hi

I have a script to make my bot talk containing

Code: Select all
def robot(text):
        os.system("espeak ' " + text + " ' ")


This works fine if run locally on the bot. Obviously if run remotely it tries to access the OS on my terminal.
In general I would like to investigate calling of modules both locally and on my terminal from a script running on my terminal. Any ideas? Thanks
Adeste
 
Posts: 12
Joined: Fri Dec 26, 2014 9:37 am

Re: make robot talk running script on terminal

Postby Alan » Wed Feb 18, 2015 3:02 pm

Hi Adeste,

To get this working on your robot, I would say that the quickest and easiest way would be to modify the websockets 'on_message' routine in robot_web_server.py to handle another command such as 'speak'. Then you can use py_websockets_bot to send a command to the robot like this

Code: Select all
bot._websocket.send( "speak", "Hello" )


Hope that makes sense. Let me know if you need more info.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am

Re: make robot talk running script on terminal

Postby Adeste » Fri Feb 20, 2015 7:35 am

Thanks Alan,

It makes perfect sense.

Cheers Ade
Adeste
 
Posts: 12
Joined: Fri Dec 26, 2014 9:37 am

Re: make robot talk running script on terminal

Postby Adeste » Sun Mar 01, 2015 11:07 pm

Hi
Editing the robot_web_server.py file seems to make no difference. The only version I can find of robot_web_server.py is in in raspberry_pi_camera_bot.
My script starts:

[code] #! /usr/bin/python

import time
import argparse
import py_websockets_bot
import os


#---------------------------------------------------------------------------------------------------
if __name__ == "__main__":

# Set up a parser for command line arguments
parser = argparse.ArgumentParser( "Moves the robot around" )
parser.add_argument( "hostname", default="192.168.42.1", nargs='?', help="The ip address of the robot" )

args = parser.parse_args()
bot = py_websockets_bot.WebsocketsBot( args.hostname )


def move():

# Connect to the robot
#bot = py_websockets_bot.WebsocketsBot( args.hostname )


# Drive rotate
bot.set_motor_speeds( 30.0, 0.0 )
time.sleep( 1 )
Adeste
 
Posts: 12
Joined: Fri Dec 26, 2014 9:37 am

Re: make robot talk running script on terminal

Postby Alan » Mon Mar 02, 2015 8:55 am

Hi Adeste,

Your control script looks ok, although I can't see any reference to speaking?

Something that might help is if you put some print statements in robot_web_server.py and then run it from the command line on your robot. This way you can see if messages are getting through.

To run robot_web_server.py from the command line, log into your Pi and run the following commands

sudo service robot_web_server stop
cd /home/pi/raspberry_pi_camera_bot
sudo ./robot_web_server.py

Hope that helps.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am

Re: make robot talk running script on terminal

Postby Adeste » Mon Mar 02, 2015 5:04 pm

Hi Alan thanks for quick reply.
Adeste
 
Posts: 12
Joined: Fri Dec 26, 2014 9:37 am

Re: make robot talk running script on terminal

Postby Adeste » Mon Mar 02, 2015 6:11 pm

Hi Alan
ran the commands suggested the bot then ceases to respond unless I reboot. It works fine then.

I get
Code: Select all
pi@raspberrypi ~/raspberry_pi_camera_bot $ sudo ./robot_web_server.py
sockjs.tornado will use json module
Starting web server...
Read 0XACED 0.38
Expected 0XACED 0.38


Do I need to stop the webserver before running a script?

I assume the webserver is running. ok
I do not understand how my script communicates with it as the command
bot.set_motor_speeds( 30.0, 0.0 ) has underscores in it.

While in the webserver script
Code: Select all
elif lineData[ 0 ] == "SetMotorSpeeds" and len( lineData ) >= 3:
                   
                    leftMotorSpeed = 0.0
                    rightMotorSpeed = 0.0


there are no underscores in "SetMotorSpeeds"? So how is my script calling the webserver? My scripts run as expected from terminal or local (after a reboot). I am clearly missing something out?
You say run put print statements in webserver script and run from bot command line. How does that test communication from my terminal. It does prove my webserver is running.

If i edit the line
Code: Select all
elif lineData[ 0 ] == "SetMotorSpeeds" and len( lineData ) >= 3:


to

Code: Select all
elif lineData[ 0 ] == "####SetMotorSpeeds" and len( lineData ) >= 3:


the command
Code: Select all
bot.set_motor_speeds( 30.0, 0.0 )
works is that because I need to reboot? and then it would not?

Thanks :-)
Adeste
 
Posts: 12
Joined: Fri Dec 26, 2014 9:37 am

Re: make robot talk running script on terminal

Postby Alan » Thu Mar 05, 2015 12:02 pm

Hi Adeste,

You can see the internals of the set_motor_speeds command by looking at line 467 of __init__.py in the py_websockets_bot library. Basically, this routine sends a string through a websocket (a network connection).

I think you're correct that the reason changing the SetMotorSpeeds line in robot_web_server.py doesn't do anything is because you need to restart the web server. You shouldn't need to reboot, just stop it from the command line (by pressing control+C if you've started it by typing sudo ./robot_web_server.py) and then start it up again. Putting in print statements like

print "Hello"

or

print "lineData[ 0 ] is", lineData[ 0 ]

can be really useful for trying to understand what the code is doing.

Regards

Alan
Alan
Site Admin
 
Posts: 311
Joined: Fri Jun 14, 2013 10:09 am


Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest