Skip to content

Commit 2e02ad7

Browse files
committed
atl_mantis-edu front and rear status LEDS
1 parent 89b9203 commit 2e02ad7

File tree

5 files changed

+99
-19
lines changed

5 files changed

+99
-19
lines changed

boards/atl/mantis-edu/init/rc.board_defaults

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ param set-default EKF2_MULTI_MAG 1
1414
param set-default SENS_IMU_MODE 0
1515
param set-default SENS_MAG_MODE 0
1616

17+
param set-default EV_TSK_STAT_DIS 1
18+
1719
set LOGGER_ARGS "-m mavlink"
1820

1921
# Start esc

boards/atl/mantis-edu/src/board_config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@
118118
#define BOARD_TAP_ESC_MODE 2 // select closed-loop control mode for the esc
119119
// #define BOARD_USE_ESC_CURRENT_REPORT
120120

121+
// LED mapping
122+
#define BOARD_FRONT_LED_MASK (1 << 0) | (1 << 3)
123+
#define BOARD_REAR_LED_MASK (1 << 1) | (1 << 2)
124+
121125
/* HEATER */
122126
#define GPIO_HEATER_OUTPUT /* PA7 T14CH1 */ (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_2MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTA|GPIO_PIN7)
123127

src/modules/events/set_leds.cpp

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (c) 2017 PX4 Development Team. All rights reserved.
3+
* Copyright (c) 2017-2021 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -40,14 +40,93 @@
4040

4141
#include "status_display.h"
4242

43+
#include <board_config.h>
44+
#include <px4_log.h>
45+
#include <matrix/math.hpp>
46+
#include <drivers/drv_led.h>
47+
48+
using namespace time_literals;
49+
4350
namespace events
4451
{
4552
namespace status
4653
{
4754

4855
void StatusDisplay::set_leds()
4956
{
50-
// Put your LED handling here
57+
bool gps_lock_valid = _vehicle_status_flags_sub.get().condition_global_position_valid;
58+
bool home_position_valid = _vehicle_status_flags_sub.get().condition_home_position_valid;
59+
int nav_state = _vehicle_status_sub.get().nav_state;
60+
61+
#if defined(BOARD_FRONT_LED_MASK)
62+
63+
// try to publish the static LED for the first 10s
64+
// this avoid the problem if a LED driver did not subscribe to the topic yet
65+
if (hrt_absolute_time() < 10_s) {
66+
67+
// set the base color for front LED
68+
_led_control.led_mask = BOARD_FRONT_LED_MASK;
69+
_led_control.color = led_control_s::COLOR_WHITE;
70+
_led_control.mode = led_control_s::MODE_ON;
71+
72+
publish();
73+
}
74+
75+
#endif // BOARD_FRONT_LED_MASK
76+
77+
#if defined(BOARD_REAR_LED_MASK)
78+
// set the led mask for the status led which are the back LED
79+
_led_control.led_mask = BOARD_REAR_LED_MASK;
80+
81+
if (nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_RTL
82+
|| nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_LAND) {
83+
_led_control.color = led_control_s::COLOR_PURPLE;
84+
85+
} else if (nav_state == vehicle_status_s::NAVIGATION_STATE_ALTCTL) {
86+
_led_control.color = led_control_s::COLOR_BLUE;
87+
88+
} else if (nav_state == vehicle_status_s::NAVIGATION_STATE_AUTO_MISSION) {
89+
_led_control.color = led_control_s::COLOR_GREEN;
90+
91+
} else {
92+
_led_control.color = led_control_s::COLOR_YELLOW; // TODO fix yellow and purple error
93+
}
94+
95+
// blink if no GPS and home are set
96+
if (gps_lock_valid && home_position_valid) {
97+
_led_control.mode = led_control_s::MODE_ON;
98+
99+
} else {
100+
_led_control.mode = led_control_s::MODE_BLINK_NORMAL;
101+
}
102+
103+
// handle battery warnings, once a state is reached it can not be reset
104+
if (_battery_status_sub.get().warning == battery_status_s::BATTERY_WARNING_CRITICAL || _critical_battery) {
105+
_led_control.color = led_control_s::COLOR_RED;
106+
_led_control.mode = led_control_s::MODE_BLINK_FAST;
107+
_critical_battery = true;
108+
109+
} else if (_battery_status_sub.get().warning == battery_status_s::BATTERY_WARNING_LOW || _low_battery) {
110+
_led_control.color = led_control_s::COLOR_RED;
111+
_led_control.mode = led_control_s::MODE_FLASH;
112+
_low_battery = true;
113+
}
114+
115+
if (nav_state != _old_nav_state
116+
|| gps_lock_valid != _old_gps_lock_valid
117+
|| home_position_valid != _old_home_position_valid
118+
|| _battery_status_sub.get().warning != _old_battery_status_warning) {
119+
120+
publish();
121+
}
122+
123+
#endif // BOARD_REAR_LED_MASK
124+
125+
// copy actual state
126+
_old_nav_state = nav_state;
127+
_old_gps_lock_valid = gps_lock_valid;
128+
_old_home_position_valid = home_position_valid;
129+
_old_battery_status_warning = _battery_status_sub.get().warning;
51130
}
52131

53132
} /* namespace status */

src/modules/events/status_display.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (c) 2017 PX4 Development Team. All rights reserved.
3+
* Copyright (c) 2017-2021 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -96,7 +96,6 @@ void StatusDisplay::process()
9696
void StatusDisplay::publish()
9797
{
9898
_led_control.timestamp = hrt_absolute_time();
99-
10099
_led_control_pub.publish(_led_control);
101100
}
102101

src/modules/events/status_display.h

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/****************************************************************************
22
*
3-
* Copyright (c) 2017-2018 PX4 Development Team. All rights reserved.
3+
* Copyright (c) 2017-2021 PX4 Development Team. All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
66
* modification, are permitted provided that the following conditions
@@ -47,7 +47,6 @@
4747
#include <uORB/topics/battery_status.h>
4848
#include <uORB/topics/cpuload.h>
4949
#include <uORB/topics/led_control.h>
50-
#include <uORB/topics/vehicle_attitude.h>
5150
#include <uORB/topics/vehicle_status.h>
5251
#include <uORB/topics/vehicle_status_flags.h>
5352

@@ -80,25 +79,22 @@ class StatusDisplay
8079
/** publish LED control */
8180
void publish();
8281

83-
// TODO: review if there is a better variant that allocates this in the memory
84-
uORB::SubscriptionData<battery_status_s> _battery_status_sub{ORB_ID(battery_status)};
85-
uORB::SubscriptionData<cpuload_s> _cpu_load_sub{ORB_ID(cpuload)};
86-
uORB::SubscriptionData<vehicle_status_s> _vehicle_status_sub{ORB_ID(vehicle_status)};
82+
uORB::SubscriptionData<battery_status_s> _battery_status_sub{ORB_ID(battery_status)};
83+
uORB::SubscriptionData<cpuload_s> _cpu_load_sub{ORB_ID(cpuload)};
84+
uORB::SubscriptionData<vehicle_status_s> _vehicle_status_sub{ORB_ID(vehicle_status)};
8785
uORB::SubscriptionData<vehicle_status_flags_s> _vehicle_status_flags_sub{ORB_ID(vehicle_status_flags)};
88-
uORB::SubscriptionData<vehicle_attitude_s> _vehicle_attitude_sub{ORB_ID(vehicle_attitude)};
8986

90-
struct led_control_s _led_control = {};
87+
led_control_s _led_control{};
9188

9289
private:
93-
bool _old_gps_lock_valid = false;
94-
bool _old_home_position_valid = false;
95-
bool _low_battery = false;
96-
bool _critical_battery = false;
97-
int _old_nav_state = -1;
98-
int _old_battery_status_warning = -1;
99-
10090
uORB::Publication<led_control_s> _led_control_pub{ORB_ID(led_control)};
10191

92+
bool _old_gps_lock_valid{false};
93+
bool _old_home_position_valid{false};
94+
bool _low_battery{false};
95+
bool _critical_battery{false};
96+
int _old_nav_state{-1};
97+
int _old_battery_status_warning{-1};
10298
};
10399

104100
} /* namespace status */

0 commit comments

Comments
 (0)