-
Notifications
You must be signed in to change notification settings - Fork 9
M3 Python API Tutorial
Antoine Hoarau edited this page Apr 15, 2015
·
12 revisions
First, make sure your favorite python editor loads the M3 python environment (i.e Launch it from a terminal, not the icon shortcut).
I recommend to use spyder and ipython, there're pretty great (more flexible than eclipse+pydev).
sudo apt-get install spyder ipython
Get the robot class in the m3 python
import m3.humanoid as m3h
meka = m3h.M3Humanoid()
Now we have to tell the realtime pc (mega-mob) that we ant to send commands to it First let’s connect to the m3rt_server
### Connect to the m3rt_server
import m3.rt_proxy as m3p
proxy = m3p.M3RtProxy()
#start the proxy (i.e. connect)
proxy.start()
# Now that we are connected to the m3rt_server
# We need to say we want to get status/cmd
# Get status
proxy.subscribe_status(meka)
# Send command
proxy.publish_command(meka)
# (Optional) Get param (allow to modify parameters in realtime)
proxy.publish_param(meka)
## Please note that if you publish parameters, you local version of robot_config will be issued to the server.
## So make sure first that the m3ens folder (that contains robot_config) is the same on the realtime pc, otherwise the remote config will be overridden by your local config.
# Now meka is ready to receive some commands
Mode Theta and Theta_gc (with gravity compensation):
## Set the mode Theta with gravity compensation
meka.set_mode_theta_gc('right_arm')
## Set the desired value in degrees for each joint
meka.set_theta_deg('right_arm', [0 0 0 30 0 0 0])
## Set the desired velocity [0;1]
meka.set_slew_rate_proportional('right_arm',[1.0]*meka.get_num_dof('right_arm'))
## Set the desired rigidity of the join [0;1]
meka.set_stiffness('right_arm', [1.0]*meka.get_num_dof('right_arm'))
Mode Torque and Torque_gc:
## Set the mode torque
meka.set_mode_torque('right_arm')
## Set the desired value in mNm for each joint
meka.set_torque('right_arm', [0 0 0 800 0 0 0]) # 7 values for the 7 joints
## Set the desired rigidity of the join [0;1]
meka.set_stiffness('right_arm', [1.0]*meka.get_num_dof('right_arm'))
Mode thetadot and thetadot_gc:
meka.set_mode_thetadot_gc('right_arm')
## Set the desired value in degrees/s for each joint
meka.set_thetadot('right_arm', [0 0 0 0 0 0 0]) # Stay immobile
## Set the desired rigidity of the join [0;1]
meka.set_stiffness('right_arm', [1.0]*meka.get_num_dof('right_arm'))
# Send command/ receive status for all the subscribed components
proxy.step()
# Stop the connection
proxy.stop()
Author: Antoine Hoarau [email protected]