Skip to content

Commit 4e67c41

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

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

demos/demo_testbench.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
positions = robot.joints.positions
19+
velocities = robot.joints.velocities
20+
21+
# Compute the PD control on the zero position.
22+
torques = kp * (des_pos - positions) - kd * velocities
23+
24+
robot.joints.set_torques(torques)
25+
robot.send_command_and_wait_end_of_cycle(0.001)
26+
27+
c += 1
28+
29+
if c % 1000 == 0:
30+
print("joint pos: ", positions)
31+
print("joint vel: ", velocities)
32+
print("torques: ", torques)
33+
robot.robot_interface.PrintStats()
34+
35+
print("timeout detected")

0 commit comments

Comments
 (0)