Skip to content

Commit a034937

Browse files
committed
add python testbench demo
Signed-off-by: Gwenn Le Bihan <[email protected]>
1 parent c1d612f commit a034937

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

demos/demo_testbench.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
3+
np.set_printoptions(suppress=True, precision=2)
4+
5+
import libodri_control_interface_pywrap as oci
6+
7+
robot = oci.robot_from_yaml_file("config_testbench.yaml")
8+
9+
des_pos = np.array([np.pi / 2, -np.pi / 2])
10+
11+
robot.initialize(des_pos)
12+
13+
kp, kd = 0.125, 0.0025
14+
c = 0
15+
while not robot.is_timeout:
16+
robot.parse_sensor_data()
17+
18+
imu_attitude = robot.imu.attitude_euler
19+
positions = robot.joints.positions
20+
velocities = robot.joints.velocities
21+
22+
# Compute the PD control on the zero position.
23+
torques = kp * (des_pos - positions) - kd * velocities
24+
25+
robot.joints.set_torques(torques)
26+
robot.send_command_and_wait_end_of_cycle(0.001)
27+
28+
c += 1
29+
30+
if c % 1000 == 0:
31+
print("joint pos: ", positions)
32+
print("joint vel: ", velocities)
33+
print("torques: ", torques)
34+
robot.robot_interface.PrintStats()
35+
36+
print("timeout detected")

0 commit comments

Comments
 (0)