Page 1 of 1

Servo Configuration [Chassis Bundle]

PostPosted: Fri Sep 26, 2014 1:23 am
by AverageMan
Hi guys

Just a few questions on the servos for the camera pan/tilt kit as part of the chassis bundle, when you get a minute.

1) Is there a way I can change the config to make the servos move faster when I use the web interface thumbstick? When I tap the thumbstick it moves very quickly to the set position, but moving manually is slower.

2) Can the set position when tapping the thumbstick for the camera tilt/pan be set to a different position? I had a play with the 192.168.1.42/config.html file, changing the sliders, but it doesn't seem to save my setting.

3) Is it possible to add my own buttons to the web interface? I'm guessing this is just a matter of messing around with the html side of things, copying existing code? I'd like a few buttons to set the camera in different positions, and also to control some kind of python script to use LEDs connected to the Pi (via a port expander)

Thanks a lot,

Rich

Re: Servo Configuration [Chassis Bundle]

PostPosted: Mon Sep 29, 2014 3:42 pm
by Alan
Hi Rich,

1) The neck speed is controlled by the constant MAX_ABS_NECK_SPEED in robot_controller.py. If you change that and then restart the web server or the Pi, then the neck speed will change. See my answer to question 3) though for a possible alternative.

2) I think that the config page settings won't take effect until you hit the 'Save' button in the bottom left (may be hard to see on a mobile or tablet). You can test that they've worked by setting the upper and lower bounds to the same value and hitting save, the neck should then hold in place.

3) You're correct that you just need to fiddle with the files in the www folder and then restart the web server to change the web interface. Restarting the web interface can be done by running the following from the Pi command line

Code: Select all
sudo service robot_web_server restart


Now, looking inside index.html you should see that most communication with the robot is done using the websocket interface which consists of the socket object and socket.send command. Commands are just text strings, and there are 3 different commands you can send for the neck

  • PanTilt joystickPosX joystickPosY (this is the command sent by the right stick)
  • Centre (centres the neck to 90 degrees pan, 90 degrees tilt. Sent when you tap the right stick)
  • SetNeckAngles panAngle tiltAngle (I added this for py_websockets_bot. You could use this to link a button to set neck directions)

Now, if you want to add a new command then you would need to modify the ConnectionHandler on_message routine in robot_web_server.py. So for example, if you wanted to add a RunScript command you would add something like

Code: Select all
socket.send( "RunScript SCRIPT_NAME" )


to index.html, and then in robot_web_server.py you'd add another elif clause

Code: Select all
elif lineData[ 0 ] == "RunScript" and len( lineData ) >= 2:    # Checks for command name and args

    scriptName = lineData[ 1 ]
    # Run the script (perhaps open and exec?)


All of this is a bit hacky at the moment I'm afraid, but hopefully it makes a bit of sense :). If I get the time then I'd like to add in something like the script running capabilities of WebIOPi.

Regards

Alan