-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimpleRobot.py
51 lines (38 loc) · 1.84 KB
/
SimpleRobot.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
import numpy, openravepy
class SimpleRobot(object):
def __init__(self, env):
self.name = 'simple'
self.robot = env.ReadRobotXMLFile('models/robots/pr2-beta-sim.robot.xml')
env.Add(self.robot)
right_relaxed = [ 0., 0., 0., -2.3, 0., 0., 0.]
left_relaxed = [ 0., 0., 0., -2.3, 0., 0., 0.]
right_manip = self.robot.GetManipulator('rightarm')
self.robot.SetActiveDOFs(right_manip.GetArmIndices())
self.robot.SetActiveDOFValues(right_relaxed)
left_manip = self.robot.GetManipulator('leftarm')
self.robot.SetActiveDOFs(left_manip.GetArmIndices())
self.robot.SetActiveDOFValues(left_relaxed)
self.robot.controller = openravepy.RaveCreateController(self.robot.GetEnv(), 'IdealController')
def GetCurrentConfiguration(self):
t = self.robot.GetTransform()
pose = t[:2,3]
return pose
def ConvertPlanToTrajectory(self, plan):
# Create a trajectory and insert all points
traj = openravepy.RaveCreateTrajectory(self.robot.GetEnv(), 'GenericTrajectory')
doft = openravepy.DOFAffine.X | openravepy.DOFAffine.Y
config_spec = openravepy.RaveGetAffineConfigurationSpecification(doft, self.robot)
traj.Init(config_spec)
idx = 0
for pt in plan:
traj.Insert(idx, pt)
idx = idx + 1
return traj
def ExecuteTrajectory(self, traj):
# Send the trajectory to the controller and wait for execution to complete
max_vel = self.robot.GetAffineTranslationMaxVels()[:2]
max_accel = 3 * max_vel
openravepy.planningutils.RetimeAffineTrajectory(traj, max_vel,
max_accel, False)
self.robot.GetController().SetPath(traj)
self.robot.WaitForController(0)