Sc mc python examples

From DIDEAS Wiki
Revision as of 23:03, 17 December 2010 by Ceb (talk | contribs) (prepare the hardware)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

PF Users Navigation:

Edit


special command sequences that are interesting

Below are some special command that result in some interesting robot behavior. These special commands can be provided via 'do_command.py', or 'pfcmdmenu.exe', or directly in python with the method 'do_command' in the module 'pfcmd.py'.

The special command sequences below are listed in braces as comma separated values. For example for the sequence [100, 200, 300]

With do_command.py you would type:

do_command.py -p <serial port> -s 100 200 300

With pfcmdmenu.exe, in the string box :

100 200 300

With python, assuming pf is an instance of pfcmd.py:

result = pf.do_command('special', [100, 200, 300])


read robot status

  • [104] # read SC status info
  • [1101] # get motor mode
  • [1106] # get encoder positions
  • [1420] # get MC SM state
  • [1342] # get AAS monitor enable (if enabled ankle encoder must have a valid value else MC statemachine is locked to state 103)
  • [1105] # get motor velocity
  • [1116] # read MC ADCs
  • [1120] # get overload status values
  • [230] # get IMU enable

An example reading SC status with do_command.py and special command 104, on serial port 17:

do_command.py -p 17 -n 10 -s 104

prepare the hardware

Take the robot out of its boot mode so that it can be controlled externally. Generally the following special commands achieve this:

  • [231, 0] # IMU off - to minimize possible loss of commands over the FUP (may want to leave on or turn on later with 231, 1)
  • [173,77,7] # demux statemachine to idle mode
  • [170,77,17] # primary statemachine to the 'do nothing state'
  • [1342, 0] # disable the ankle angle encoder monitor
  • [1421, 17] # MC statemachine to a 'do nothing success state'
  • [123, 1] # if the FET board green LED is not lit, then turning on the "AC enable" should fix that.

move robot back - fort in voltage mode

After preparing the hardware above, can use special command 1115 to command a fixed voltage across the motor:

  • [1115, 1000, 0, 6] # qVq = 1000, mode = 6 (voltage
  • sleep 1 sec
  • [1115, -1000, 0, 6] # qVq=-1000
  • sleep 1 sec
  • [1115, 0,0,0] # short the motor leads

enter trajectory mode

The trajectory mode will servo the robot to the goal position. This is achieved by adjusting the sent point of a virtual spring (whos parmeters) are adjusted. The goal point for the VS is set based on diffeence equstion that produces an exponential response to a position step input.

  • [1318, 100] # set goal position to 100 need to be careful to limit the goal position to valid positions!!!
  • [1421, 41] # go to trajectory control mode, robot immediatly jumps!
  • sleep 1 sec
  • [1318, 500] # servo to position 500

python examples


########################## 
# BASIC CODE REQUIRE TO ESTABLISH A ROBOT CONNECTION
###########################
# update the python path variable
import python_paths_default  
import python_paths as pyenv

import pfcmd        # robot communication module

COM_PORT = 17  # use device manager to determine port #
pf = pfcmd.PFCmd(0, 0);     # instance of communication module
pf.connect(COM_PORT, 115200);   # baudrate=115200
####################################################
# send special commands to 'prepare the hardware'
####################################################

pf.do_command('special',[173, 77, 7]);
pf.do_command('special',[170, 77, 17]);
pf.do_command('special',[1421, 8]);           
pf.do_command('special',[173, 77, 6]);    
pf.do_command('special',[170, 77, 17]);
####################################################
# move robot with voltage mode
####################################################
for i in range(0,10) :
        print i
        pf.do_command('special',[1115, 2000, 0 ,6]);
        time.sleep(1.0)
        pf.do_command('special',[1115, -2000, 0 ,6]);
        time.sleep(1.0)

pf.do_command('special',[1115, 0]);
####################################################
# do some trajectory control
####################################################

pf.do_command('special',[1318, 0]);  # set goal position
pf.do_command('special',[1421, 41]);  # enter trajectory mode

if 1 :  # commands to set the trajectory parameters
    pf.do_command('special',[1319, 1, 2500, -2400]);  # set current limits  +2.5 and -2.4 amps
    pf.do_command('special',[1315, 1000]);  # set tau to 100mS
    pf.do_command('special',[1317, 100, 10]);  # set impedance stiffness and damping
    

for i in range(0,10) :
    pf.do_command('special',[1318, 500]);   # change goal position
    time.sleep(0.5);
    pf.do_command('special',[1318, 50]);
    time.sleep(0.5);


pf.do_command('special',[1421, 17]);  # back to MC idle state
pf.do_command('special',[1115, 0]);   # short leads