-
Notifications
You must be signed in to change notification settings - Fork 13
/
moving_base_control.py
56 lines (49 loc) · 1.57 KB
/
moving_base_control.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Common code for handling free-floating moving bases"""
from klampt.math import so3
def get_moving_base_xform(robot):
"""For a moving base robot model, returns the current base rotation
matrix R and translation t."""
return robot.link(5).getTransform()
def set_moving_base_xform(robot,R,t):
"""For a moving base robot model, set the current base rotation
matrix R and translation t. (Note: if you are controlling a robot
during simulation, use send_moving_base_xform_command)
"""
q = robot.getConfig()
for i in range(3):
q[i] = t[i]
roll,pitch,yaw = so3.rpy(R)
q[3]=yaw
q[4]=pitch
q[5]=roll
robot.setConfig(q)
def send_moving_base_xform_linear(controller,R,t,dt):
"""For a moving base robot model, send a command to move to the
rotation matrix R and translation t using linear interpolation
over the duration dt.
Note: with the reflex model, can't currently set hand commands
and linear base commands simultaneously
"""
q = controller.getCommandedConfig()
for i in range(3):
q[i] = t[i]
roll,pitch,yaw = so3.rpy(R)
q[3]=yaw
q[4]=pitch
q[5]=roll
controller.setLinear(q,dt)
def send_moving_base_xform_PID(controller,R,t):
"""For a moving base robot model, send a command to move to the
rotation matrix R and translation t by setting the PID setpoint
Note: with the reflex model, can't currently set hand commands
and linear base commands simultaneously
"""
q = controller.getCommandedConfig()
for i in range(3):
q[i] = t[i]
roll,pitch,yaw = so3.rpy(R)
q[3]=yaw
q[4]=pitch
q[5]=roll
v = controller.getCommandedVelocity()
controller.setPIDCommand(q,v)