Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

pariaspe
Copy link
Member

Basic Info

Info Please fill out this column
Issue(s) this addresses #103
ROS2 version tested on Humble
Aerial platform tested on

Description of contribution in a few bullet points

  • Goal handle and result are now static attributes that are shared between class instances
  • Catching exception on result status when result is None (not received yet)
  • Added new test

@pariaspe pariaspe linked an issue Dec 22, 2022 that may be closed by this pull request
@pariaspe
Copy link
Member Author

Current changes affect to all BehaviorHandler instances, even if the namespace or the Behavior are different.

import time
from enum import Enum

import rclpy

from as2_python_api.drone_interface import DroneInterface


class BehaviorStatus(Enum):
    IDLE = 0
    RUNNING = 1
    PAUSED = 2


rclpy.init()

drone_interface = DroneInterface("", verbose=False)
drone_interface_2 = DroneInterface("other", verbose=False)

time.sleep(1)

print("STATUS:", BehaviorStatus(drone_interface.takeoff.status).name)  # IDLE
print("STATUS:", BehaviorStatus(drone_interface_2.takeoff.status).name)  # IDLE

print("START")
drone_interface.takeoff.start(1.0, 0.5, False)

time.sleep(2)
print("STATUS:", BehaviorStatus(drone_interface.takeoff.status).name)  # RUNNING
print("STATUS:", BehaviorStatus(drone_interface_2.takeoff.status).name)  # IDLE

print("PAUSE")
drone_interface_2.takeoff.pause()

time.sleep(2)
print("STATUS:", BehaviorStatus(drone_interface.takeoff.status).name)  # RUNNING
print("STATUS:", BehaviorStatus(drone_interface_2.takeoff.status).name)  # IDLE

print("RESUME")
drone_interface.takeoff.resume(False)
time.sleep(2)
print("STATUS:", BehaviorStatus(drone_interface.takeoff.status).name)  # RUNNING
print("STATUS:", BehaviorStatus(drone_interface_2.takeoff.status).name)  # IDLE

print("WAIT TO RESULT")
drone_interface.takeoff.wait_to_result()

print(drone_interface.takeoff.result)  # as2_msgs.action.TakeOff_Result(takeoff_success=True)
print(drone_interface_2.takeoff.result)  # as2_msgs.action.TakeOff_Result(takeoff_success=True)

print("Exit")
drone_interface.shutdown()
drone_interface_2.shutdown()

However, it is interesting to share the result and goal_handle somehow. Probably, it might be much better to use _action/result subscription. What do you think @miferco97 @RPS98 ?

@pariaspe
Copy link
Member Author

UPDATE

I'm closing this solution since it's doesn't work if both drone interfaces aren't instantiate from the same file.

First python script

rclpy.init()

drone_interface = DroneInterface("", verbose=False)

print("START")
drone_interface.takeoff.start(1.0, 0.5, False)
time.sleep(2)

print("PAUSE")
drone_interface.takeoff.pause()
time.sleep(2)

print("RESUME")
drone_interface.takeoff.resume(False)
time.sleep(2)

print("WAIT TO RESULT")
drone_interface.takeoff.wait_to_result()

print(drone_interface.takeoff.result)  # as2_msgs.action.TakeOff_Result(takeoff_success=True)

drone_interface.shutdown()

Second python script

rclpy.init()

drone_interface = DroneInterface("", verbose=False)

i = 0
while True:
    print(f"{i} STATUS: {BehaviorStatus(drone_interface.takeoff.status).name}")
    try:
        print(f"{i} RESULT: {ResultStatus(drone_interface.takeoff.result_status).name} - {drone_interface.takeoff.result}")
    except BehaviorHandler.ResultUnknown:
        print(f"{i} RESULT: {ResultStatus(drone_interface.takeoff.result_status).name} {None}")
    i += 1
    time.sleep(1)

which prints:

....
7 STATUS: IDLE
7 RESULT: STATUS_UNKNOWN None
8 STATUS: IDLE
8 RESULT: STATUS_UNKNOWN None
9 STATUS: IDLE
9 RESULT: STATUS_UNKNOWN None
10 STATUS: RUNNING                                   ----------> START
10 RESULT: STATUS_UNKNOWN None
11 STATUS: RUNNING
11 RESULT: STATUS_UNKNOWN None
12 STATUS: PAUSED                                    -----------> PAUSE
12 RESULT: STATUS_UNKNOWN None
13 STATUS: PAUSED
13 RESULT: STATUS_UNKNOWN None
14 STATUS: PAUSED
14 RESULT: STATUS_UNKNOWN None
15 STATUS: RUNNING                                   ----------> RESUME
15 RESULT: STATUS_UNKNOWN None
16 STATUS: RUNNING
16 RESULT: STATUS_UNKNOWN None
17 STATUS: RUNNING
17 RESULT: STATUS_UNKNOWN None
18 STATUS: RUNNING
18 RESULT: STATUS_UNKNOWN None
19 STATUS: RUNNING
19 RESULT: STATUS_UNKNOWN None
20 STATUS: RUNNING
20 RESULT: STATUS_UNKNOWN None
21 STATUS: RUNNING
21 RESULT: STATUS_UNKNOWN None
22 STATUS: IDLE                                      ----------> SUCESS
22 RESULT: STATUS_UNKNOWN None
23 STATUS: IDLE
23 RESULT: STATUS_UNKNOWN None
24 STATUS: IDLE
24 RESULT: STATUS_UNKNOWN None
25 STATUS: IDLE
25 RESULT: STATUS_UNKNOWN None
26 STATUS: IDLE
26 RESULT: STATUS_UNKNOWN None

Status is always UNKNOWN!

@miferco97
Copy link
Member

@pariaspe do we have any update on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[as2_python_api] Make behavior status shared

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.