morse-simulator / morse

The Modular OpenRobots Simulation Engine
http://morse-simulator.github.io/
Other
353 stars 156 forks source link

Grasping / Sensor Bug #565

Closed seantrott closed 9 years ago

seantrott commented 9 years ago

I am using the Human component in MORSE, with the intent of demonstrating grasping motions like "picking up" and "putting down". I've set up my scene with a MORSE human, as well as a "socket" service to control this human from a simulator file.

However, when I call the "grasp" function from the simulated human instance, an error arises within the grasp function itself:

In line 49 of grasping_robot.py (possibly line 47 on some versions), this code fails: "near_sensor = hand_empty.sensors['Near']"

This error is: """ line 49, in grasp near_sensor = hand_empty.sensors['Near'] KeyError: 'requested item "Near" does not exist' """

I think it has to do with an error in instantiating the Sensors list. I am going to try and append my own Sensor to the human, but it seems to be a bug in MORSE.

adegroote commented 9 years ago

Can you provide a minimal builder script showing the issue ?

adegroote commented 9 years ago

Can you test my fix_565 branch ?

seantrott commented 9 years ago

I will copy the code now to test. Here is an example of the builder script, as well as the simulator script:

Here is the builder code: motion2 = Waypoint() motion2.properties(ObstacleAvoidance = False) motion2.properties(ControlType="Position") motion2.add_interface('socket') motion2.add_service('socket') motion2.add_stream('socket') human_pose = Pose() human_pose.add_interface('socket') human = Human(name="john_instance") human.use_world_camera() human.append(motion2) human.append(human_pose) human.disable_keyboard_control() human.add_service('socket')

And here is the code to call grasp:

    inst = getattr(self.simulator, self.name)
    inst.grasp(True, 'bottle1_instance')

Alternatively:

    inst.grasp(True)
seantrott commented 9 years ago

I copied/pasted the code referenced here (https://github.com/adegroote/morse/commit/d703ba5882279b93736db95340026d429fc4ee2e) into the relevant files. There's no longer an error on line 49, which governs the sensors, but now there is an error on line 54, when I call:

grasp(True, 'bottle1_instance') ""File "/usr/local/lib/python3.4/site-packages/morse/robots/grasping_robot.py", line 54, in grasp if (grasping_robot['DraggedObject'] is None or grasping_robot['DraggedObject'] == '') : KeyError: 'value = gameOb[key]: KX_GameObject, key "DraggedObject" does not exist' ""

If I just call: inst.grasp(True)

There's no error, but the human also doesn't pick up the closest object (there is a bottle next to him), which I thought grasp() was supposed to do if no object name was specified.

adegroote commented 9 years ago

You need also adegroot@84bfa31d9 which is in the branch (which fix the previous error) Otherwise, the human should pick the object if the object is in the 'range' of the Near sensor. Maybe we need to put a bigger ranger for the Near sensor using 'sens.distance = xxx' in the make_grasper method

seantrott commented 9 years ago

Ah, I see, thanks - though the "adegroot@84bfa31" link leads to a 404 error?

adegroote commented 9 years ago

It is https://github.com/adegroote/morse/commit/84bfa31d9b8a34349077027bb6ce6326b37e6222

seantrott commented 9 years ago

Thanks for your feedback on all this. I added that line of code to grasping_robot.py, and it addressed the error I referenced above. However, I think there might be an issue with the Sensors; when I call:

grasp(True, 'bottle1_instance')

The MORSE log prints this line during its output: [ 44.809] [robots.grasping_robot] no object named bottle1_instance in []

Above, the "[]" referenced is meant to be the list of objects near the Human, obtained in grasping_robot.grasp:

"near_sensor.hitObjectList"

I added a line changing the Sensor distance dramatically in make_grasp, but the method still can't seem to locate any "near" objects.

adegroote commented 9 years ago

Do you have call setgraspable on the object you're interested in ? see

http://www.openrobots.org/morse/doc/1.2/user/others/passive_objects.html

seantrott commented 9 years ago

Yes, when I initialize the bottle instance I set it:

bottle1 = PassiveObject('environments/indoors-1/indoor-1', 'Bottle1')
bottle1.properties(Object=True, Label="bottle1_instance", Type='bottle', Graspable=True)    
bottle1.setgraspable()
bottle1.translate(x=0, y=0, z=1)

It seems that the sensor doesn't recognize it as being "near". I have the sens.distance set to 10.

adegroote commented 9 years ago

Probably miss something in my patch, will try to fix it tomorrow

adegroote commented 9 years ago

Can you test with one more patch https://github.com/adegroote/morse/commit/33cf6fda2c2294853e3a4ac799feac248b90c6ce ?

seantrott commented 9 years ago

Thanks, so this worked somewhat. I determined that you need to pass in the variable name of the object, not the object label (e.g., "bottle1", not "bottle1_instance".) and it doesn't work even when I rename the variable name to "bottle1_instance".

But the human does pick up the bottle when I call:

grasp(True, 'bottle1').

However, once he picks up the bottle, he moves randomly across the screen and disappears from view. Any idea on why this might be? I get the message that the GRASP action is successful, and as soon as he picks it up, he starts moving away.

adegroote commented 9 years ago

It seems odd. It looks like a physics bugs, when some physical objects interacts in bad way and the physical engine diverges. I will retest tomorrow, but I don't think I get this behaviour. Debugging it would be harder (as I don't want to touch too much the physics related to human).

Considering the name, the doc mentions properly the 'object name', so it seems to be the expected behaviour.

seantrott commented 9 years ago

I see, thanks. I tried putting the Simulator to sleep after the grasping motion is completed, but it had no effect.