Skip to content

Commit 20af456

Browse files
author
Marc
committed
set joints method
1 parent b5bd2b1 commit 20af456

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/parallel_parameter_search/simulators.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import rospy
88
from wolfgang_pybullet_sim.simulation import Simulation
99
from wolfgang_pybullet_sim.ros_interface import ROSInterface
10-
from parallel_parameter_search.utils import set_param_to_file, load_yaml_to_param
10+
from parallel_parameter_search.utils import set_param_to_file, load_yaml_to_param
1111

1212
from darwin_description.darwin_webots_controller import DarwinWebotsController
13-
13+
from bitbots_msgs.msg import JointCommand
1414

1515
class AbstractSim:
1616

@@ -41,6 +41,16 @@ def reset(self):
4141
def get_time(self):
4242
raise NotImplementedError
4343

44+
def set_joints(self, joint_command_msg):
45+
raise NotImplementedError
46+
47+
def set_joints_dict(self, dict):
48+
msg = JointCommand()
49+
for key in dict.keys():
50+
msg.joint_names.append(key)
51+
msg.positions.append(dict[key])
52+
self.set_joints(msg)
53+
4454
class PybulletSim(AbstractSim):
4555

4656
def __init__(self, namespace, gui, urdf_path=None, foot_link_names=[]):
@@ -49,7 +59,7 @@ def __init__(self, namespace, gui, urdf_path=None, foot_link_names=[]):
4959
# load simuation params
5060
rospack = rospkg.RosPack()
5161
print(self.namespace)
52-
load_yaml_to_param("/" +self.namespace, 'wolfgang_pybullet_sim', '/config/config.yaml', rospack)
62+
load_yaml_to_param("/" + self.namespace, 'wolfgang_pybullet_sim', '/config/config.yaml', rospack)
5363
self.gui = gui
5464
self.sim: Simulation = Simulation(gui, urdf_path=urdf_path, foot_link_names=foot_link_names)
5565
self.sim_interface: ROSInterface = ROSInterface(self.sim, namespace="/" + self.namespace + '/', node=False)
@@ -84,6 +94,7 @@ def set_joints(self, joint_command_msg):
8494
def get_timestep(self):
8595
return self.sim.timestep
8696

97+
8798
def fix_webots_folder(sim_proc_pid):
8899
# Fix for webots folder name on some systems
89100
time.sleep(1) # Wait for webots

src/parallel_parameter_search/walk_optimization.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ def objective(self, trial):
6060
self.reset()
6161

6262
cost = 0
63-
# todo add scenarios where the speed command changes multiple times while the robot is already walking
6463
# standing as first test, is not in loop as it will only be done once
65-
early_term, cost_try = self.evaluate_direction(0, 0, 0, trial, 1, 2)
64+
early_term, cost_try = self.evaluate_direction(0, 0, 0, trial, 1, 0)
6665
cost += cost_try
6766
if early_term:
6867
# terminate early and give 100 cost for each try left
@@ -256,9 +255,8 @@ def compute_cost(self, x, y, yaw):
256255
cost = abs(current_pose[0] - correct_pose[0]) \
257256
+ abs(current_pose[1] - correct_pose[1]) \
258257
+ abs(current_pose[2] - correct_pose[
259-
2]) * yaw_factor # todo take closest distance in cricle through 0 into account
258+
2]) * yaw_factor # todo take closest distance in circle through 0 into account
260259
# method doesn't work for going forward and turning at the same times
261-
# todo better computation of correct end pose, maybe use foot position. wakling provides foot position
262260
if yaw != 0: # and (x != 0 or y != 0):
263261
# just give 0 cost for surviving
264262
cost = 0
@@ -327,7 +325,6 @@ def __init__(self, namespace, gui, walk_as_node, sim_type='pybullet'):
327325
if sim_type == 'pybullet':
328326
self.sim = PybulletSim(self.namespace, gui)
329327
elif sim_type == 'webots':
330-
# todo
331328
self.sim = WebotsSim(self.namespace, gui)
332329
else:
333330
print(f'sim type {sim_type} not known')
@@ -337,7 +334,7 @@ def suggest_walk_params(self, trial):
337334

338335

339336
class DarwinWalkOptimization(AbstractWalkOptimization):
340-
def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
337+
def __init__(self, namespace, gui, walk_as_node, sim_type='pybullet'):
341338
super(DarwinWalkOptimization, self).__init__(namespace, 'darwin', walk_as_node)
342339
self.reset_height_offset = 0.09
343340
self.directions = [[0.05, 0, 0],
@@ -355,6 +352,7 @@ def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
355352
urdf_path = self.rospack.get_path('darwin_description') + '/urdf/robot.urdf'
356353
self.sim = PybulletSim(self.namespace, gui, urdf_path=urdf_path,
357354
foot_link_names=['MP_ANKLE2_L', 'MP_ANKLE2_R'])
355+
self.sim.set_joints_dict({"LShoulderRoll": 0.5, "LElbow": -1.15, "RShoulderRoll": -0.5, "RElbow": 1.15})
358356
elif sim_type == 'webots':
359357
self.sim = WebotsSim(self.namespace, gui)
360358
else:
@@ -365,7 +363,7 @@ def suggest_walk_params(self, trial):
365363

366364

367365
class OP3WalkOptimization(AbstractWalkOptimization):
368-
def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
366+
def __init__(self, namespace, gui, walk_as_node, sim_type='pybullet'):
369367
super(OP3WalkOptimization, self).__init__(namespace, 'op3', walk_as_node)
370368
self.reset_height_offset = 0.12
371369
self.directions = [[0.05, 0, 0],
@@ -393,7 +391,7 @@ def suggest_walk_params(self, trial):
393391

394392

395393
class NaoWalkOptimization(AbstractWalkOptimization):
396-
def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
394+
def __init__(self, namespace, gui, walk_as_node, sim_type='pybullet'):
397395
super(NaoWalkOptimization, self).__init__(namespace, 'nao', walk_as_node)
398396
self.reset_height_offset = 0.12
399397
self.directions = [[0.05, 0, 0],
@@ -410,7 +408,7 @@ def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
410408
if sim_type == 'pybullet':
411409
urdf_path = self.rospack.get_path('nao_description') + '/urdf/robot.urdf'
412410
self.sim = PybulletSim(self.namespace, gui, urdf_path=urdf_path,
413-
foot_link_names=['r_ank_roll_link', 'l_ank_roll_link'])
411+
foot_link_names=['l_ankle', 'r_ankle'])
414412
elif sim_type == 'webots':
415413
self.sim = WebotsSim(self.namespace, gui)
416414
else:
@@ -421,7 +419,7 @@ def suggest_walk_params(self, trial):
421419

422420

423421
class ReemcWalkOptimization(AbstractWalkOptimization):
424-
def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
422+
def __init__(self, namespace, gui, walk_as_node, sim_type='pybullet'):
425423
super(ReemcWalkOptimization, self).__init__(namespace, 'reemc', walk_as_node)
426424
self.reset_height_offset = 0.12
427425
self.directions = [[0.05, 0, 0],
@@ -438,7 +436,7 @@ def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
438436
if sim_type == 'pybullet':
439437
urdf_path = self.rospack.get_path('reemc_description') + '/urdf/robot.urdf'
440438
self.sim = PybulletSim(self.namespace, gui, urdf_path=urdf_path,
441-
foot_link_names=['r_ank_roll_link', 'l_ank_roll_link'])
439+
foot_link_names=['leg_left_6_link', 'leg_right_6_link'])
442440
elif sim_type == 'webots':
443441
self.sim = WebotsSim(self.namespace, gui)
444442
else:
@@ -449,7 +447,7 @@ def suggest_walk_params(self, trial):
449447

450448

451449
class TalosWalkOptimization(AbstractWalkOptimization):
452-
def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
450+
def __init__(self, namespace, gui, walk_as_node, sim_type='pybullet'):
453451
super(TalosWalkOptimization, self).__init__(namespace, 'talos', walk_as_node)
454452
self.reset_height_offset = 0.12
455453
self.directions = [[0.05, 0, 0],
@@ -466,7 +464,7 @@ def __init__(self, namespace, gui, walk_as_node, sim_type='webots'):
466464
if sim_type == 'pybullet':
467465
urdf_path = self.rospack.get_path('talos_description') + '/urdf/robot.urdf'
468466
self.sim = PybulletSim(self.namespace, gui, urdf_path=urdf_path,
469-
foot_link_names=['r_ank_roll_link', 'l_ank_roll_link'])
467+
foot_link_names=['leg_left_6_link', 'leg_right_6_link'])
470468
elif sim_type == 'webots':
471469
self.sim = WebotsSim(self.namespace, gui)
472470
else:

0 commit comments

Comments
 (0)