Skip to content

Commit

Permalink
[+] Add LED debug in flight_manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Cadart Nicolas committed Feb 8, 2019
1 parent baa78bc commit 1c87209
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ ROS project fro an ardrone landing on mobile platform.

### flight_manager_node

- complete state machine
- add LED animations depending on current state
- test node on drone
- test node on drone with real navigation


## Ar Track Alvar
Expand Down
23 changes: 18 additions & 5 deletions src/flight_manager_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tf2_geometry_msgs import PoseStamped, PointStamped
from ar_track_alvar_msgs.msg import AlvarMarkers
from ardrone_autonomy.msg import Navdata
from ardrone_autonomy.srv import LedAnim

from ardrone_carrier.msg import NavigationGoal, ArdroneCommand

Expand Down Expand Up @@ -50,6 +51,7 @@ class FlightManager:
def __init__(self):
""" Object constructor. """
# ROS subscribers and publishers
self.led_srv = rospy.ServiceProxy("/ardrone/setledanimation", LedAnim)
self.takeoff_pub = rospy.Publisher("/ardrone/takeoff", Empty, queue_size=1)
self.land_pub = rospy.Publisher("/ardrone/land", Empty, queue_size=1)
self.nav_pub = rospy.Publisher("/pose_goal", NavigationGoal, queue_size=1)
Expand Down Expand Up @@ -284,13 +286,21 @@ def _change_state(self, new_state, warn=False, previous=None):
else:
rospy.loginfo("{} --> {}".format(previous_state_str, new_state.name))

# change state
self.state = new_state
# GREEN when drone is ready and landed
if new_state == STATE.OFF:
self.led_srv(type=8, freq=1.0, duration=5)

# specific behavior when reaching a given state
# TODO : set LED animations depending on new state
# BLINK_GREEN_RED when we are looking for target
if new_state == STATE.FINDING:
self.research_pose_count = 0
self.led_srv(type=0, freq=3.0, duration=0)

# BLINK_GREEN when drone is tracking or landing on target
if new_state in {STATE.TRACKING, STATE.LANDING}:
self.led_srv(type=1, freq=3.0, duration=0)

# change state
self.state = new_state

# ======================= ROS callbacks =======================

Expand All @@ -317,9 +327,10 @@ def _navdata_callback(self, msg):
"""
# update drone state (only if test mode is deactivated)
self.drone_state = msg.state if TAKEOFF_ALLOWED else 0
# check battery
# check battery, and RED and print msg if it is too low
if msg.batteryPercent < 15. and msg.header.seq % 200:
rospy.logwarn("Low battery : {}% !".format(msg.batteryPercent))
self.led_srv(type=7, freq=1.0, duration=0)

def _command_callback(self, msg):
"""
Expand All @@ -333,6 +344,8 @@ def _command_callback(self, msg):
rospy.logerr("Received unkown command : {}".format(msg.command))
return

# ORANGE when receiving a new order
self.led_srv(type=3, freq=10, duration=1)
valid_command = True

# send landing order
Expand Down

0 comments on commit 1c87209

Please sign in to comment.