anki / cozmo-python-sdk

Anki Cozmo Python SDK
Other
661 stars 427 forks source link

Issues when chaining multiple driving actions #206

Closed dominikheinz closed 5 years ago

dominikheinz commented 5 years ago

Hello,

I am currently working on a university project involving Cozmo. We are implementing lane-tracking/autonomous driving. Every time Cozmo's camera receives a new frame, different analyzing steps are made to decide where he should drive. When it is detected that he is about to face a cross road, he is supposed to drive straight for a given amount, then turn left. As long as there is no crossing, Cozmo is driving using the robot.drive_wheel_motors function, which works fine. Here is our code:

# Registering the camera handler
    robot_obj.add_event_handler(cozmo.world.EvtNewCameraImage, lane_tracking_obj.process_frame)

Within the process_frame method the following code is executed:

[...]
if not RobotStatusController.is_at_crossing:

    crossing_type = CrossingTypeIdentifier.analyze_frame(bin_img)
    self.navigator_controller.handle_crossing(crossing_type)

[...]

Where as handle_crossing is simply calling the following method:

def turn_next_left(self):
        RobotStatusController.is_at_crossing = True
        self.robot.stop_all_motors()
        self.robot.drive_straight(util.distance_mm(80), util.speed_mmps(Settings.cozmo_drive_speed)).wait_for_completed()
        self.robot.turn_in_place(util.degrees(90)).wait_for_completed()
        RobotStatusController.is_at_crossing = False

We are prompted with the following exception:

/home/void/Documents/Projects/CozmoPSE/gruppe4-cozmo/Engines/RobotController/DriveController.py:25: RuntimeWarning: coroutine 'Action.wait_for_completed' was never awaited
  self.robot.drive_straight(util.distance_mm(80), util.speed_mmps(Settings.cozmo_drive_speed)).wait_for_completed()
Task exception was never retrieved
future: <Task finished coro=<Dispatcher._dispatch_event() done, defined at /home/void/.local/share/virtualenvs/gruppe4-cozmo-rndZJdD9/lib/python3.7/site-packages/cozmo/event.py:415> exception=RobotBusy('Robot is already performing 1 action(s) <DriveStraight state=action_running distance=<Distance 80.00 mm (3.15 inches)> speed=<Speed 70.00 mmps> should_play_anim=True>')>
Traceback (most recent call last):
  File "/home/void/.local/share/virtualenvs/gruppe4-cozmo-rndZJdD9/lib/python3.7/site-packages/cozmo/event.py", line 426, in _dispatch_event
    result = event._dispatch_to_func(handler.f)
  File "/home/void/.local/share/virtualenvs/gruppe4-cozmo-rndZJdD9/lib/python3.7/site-packages/cozmo/event.py", line 210, in _dispatch_to_func
    return f(self, **self._params())
  File "/home/void/Documents/Projects/CozmoPSE/gruppe4-cozmo/Engines/LaneTracking/LaneTrackingEngine.py", line 66, in process_frame
    self.navigator_controller.handle_crossing(crossing_type)
  File "/home/void/Documents/Projects/CozmoPSE/gruppe4-cozmo/Engines/RobotController/NavigatorController.py", line 19, in handle_crossing
    self.drive_controller.turn_next_left() # ToDo Change Direction
  File "/home/void/Documents/Projects/CozmoPSE/gruppe4-cozmo/Engines/RobotController/DriveController.py", line 26, in turn_next_left
    self.robot.turn_in_place(util.degrees(90)).wait_for_completed()
  File "/home/void/.local/share/virtualenvs/gruppe4-cozmo-rndZJdD9/lib/python3.7/site-packages/cozmo/robot.py", line 2173, in turn_in_place
    num_retries=num_retries)
  File "/home/void/.local/share/virtualenvs/gruppe4-cozmo-rndZJdD9/lib/python3.7/site-packages/cozmo/action.py", line 553, in _send_single_action
    (len(self._in_progress), action))
cozmo.exceptions.RobotBusy: Robot is already performing 1 action(s) <DriveStraight state=action_running distance=<Distance 80.00 mm (3.15 inches)> speed=<Speed 70.00 mmps> should_play_anim=True>

We are wondering why this happens, mainly because the example scripts 02_drive_and_turn.py is doing pretty much the same thing. Isn't cozmo supposed to wait until the drive_straight routine finished executing before he is starting to do the turn_in_place ?

Furthermore we are wondering if we are using the event system as it is supposed to be used? Are we missing something?

EDIT1: After further investigation (we logged all action & behavior events) we managed to find out that turn_in_place fails with the following failure reason:

Action Stopped: <TurnInPlace state=action_failed angle=<Angle 1.57 radians (90.00 degrees)>, speed=None, accel=None, tolerance=None is_absolute=False failure_reason='Action failed due to tracks locked' failure_code=tracks_locked result=ActionResults.TRACKS_LOCKED>

This is really surprising because we are not performing any action on this track beforehand.

msintov commented 5 years ago

Hi @dominikheinz ,

The typical solution to solve TRACKS_LOCKED issues is to pass in a parameter of 0 for the track that was previously being controlled.

A few related forum posts follow: https://forums.anki.com/t/action-failed-due-to-tracks-locked/17367 https://forums.anki.com/t/action-failed-failure-reason-action-failed-due-to-tracks-locked/2543 https://forums.anki.com/t/animationtrigger-fails-due-to-tracks-locked-but-which-track-is-it/13674

Hopefully this helps. I'm closing this issue for now but please feel free to post again. Also, the forums are the best way to get help from the community and Anki as well.

Thank you!

Michelle