forked from Rhoban/onshape-to-robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbullet.py
66 lines (56 loc) · 2.05 KB
/
bullet.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
57
58
59
60
61
62
63
64
65
66
import math
import sys
import os
import time
import argparse
import pybullet as p
from .simulation import Simulation
def main():
parser = argparse.ArgumentParser(prog="onshape-to-robot-bullet")
parser.add_argument('-f', '--fixed', action='store_true')
parser.add_argument('-x', '--x', type=float, default=0)
parser.add_argument('-y', '--y', type=float, default=0)
parser.add_argument('-z', '--z', type=float, default=0)
parser.add_argument('directory')
args = parser.parse_args()
robotPath = args.directory
if not robotPath.endswith('.urdf'):
robotPath += '/robot.urdf'
sim = Simulation(robotPath, gui=True, panels=True, fixed=args.fixed)
pos, rpy = sim.getRobotPose()
_, orn = p.getBasePositionAndOrientation(sim.robot)
sim.setRobotPose([pos[0] + args.x, pos[1] + args.y, pos[2] + args.z], orn)
controls = {}
for name in sim.getJoints():
if name.endswith('_speed'):
controls[name] = p.addUserDebugParameter(
name, -math.pi*3, math.pi*3, 0)
else:
infos = sim.getJointsInfos(name)
low = -math.pi
high = math.pi
if 'lowerLimit' in infos:
low = infos['lowerLimit']
if 'upperLimit' in infos:
high = infos['upperLimit']
controls[name] = p.addUserDebugParameter(name, low, high, 0)
lastPrint = 0
while True:
targets = {}
for name in controls.keys():
targets[name] = p.readUserDebugParameter(controls[name])
sim.setJoints(targets)
if time.time() - lastPrint > 0.05:
lastPrint = time.time()
os.system("clear")
frames = sim.getFrames()
for frame in frames:
print(frame)
print("- x=%f\ty=%f\tz=%f" % frames[frame][0])
print("- r=%f\tp=%f\ty=%f" % frames[frame][1])
print("")
print("Center of mass:")
print(sim.getCenterOfMassPosition())
sim.tick()
if __name__ == "__main__":
main()