Compare commits

...

8 Commits

Author SHA1 Message Date
Brown.Z 5090a31c83 GPS_Backend: make_gps_time增加check_new_itow函数,修复NMEA RTC时间不对问题 2 years ago
Brown.Z ec7d59334e AC_ZR_App: 增加电池初始电量计算 3 years ago
Brown.Z 18df2c6d2c ArduCopter:增加zr_app文件,周期循环函数,在UserCode中调用 3 years ago
Brown.Z 80e93f3f71 AC_ZR_App: 增加降落减速;ZR参数名调整 3 years ago
Brown.Z 050d98eb0e 增加proximity uavcan 3 years ago
Brown.Z 16b69e95b1 增加UAVCAN RGB LED 3 years ago
zbr3550 c96c4654d5 增加注册到期时间判断 3 years ago
zbr3550 309fb6f12b 增加AC_ZR_App,增加一些参数 3 years ago
  1. 28
      ArduCopter/APM_Config.h
  2. 18
      ArduCopter/AP_Arming.cpp
  3. 3
      ArduCopter/AP_Arming.h
  4. 8
      ArduCopter/Copter.h
  5. 6
      ArduCopter/GCS_Mavlink.cpp
  6. 2
      ArduCopter/Parameters.cpp
  7. 1
      ArduCopter/Parameters.h
  8. 3
      ArduCopter/UserCode.cpp
  9. 17
      ArduCopter/mode.cpp
  10. 2
      ArduCopter/mode.h
  11. 8
      ArduCopter/mode_loiter.cpp
  12. 1
      ArduCopter/wscript
  13. 31
      ArduCopter/zr_app.cpp
  14. 3
      bd-pix4.sh
  15. 3
      cubeblack.sh
  16. 2
      just_build.sh
  17. 255
      libraries/AC_ZR_APP/AC_ZR_App.cpp
  18. 70
      libraries/AC_ZR_APP/AC_ZR_App.h
  19. 328
      libraries/AC_ZR_APP/Des.cpp
  20. 22
      libraries/AC_ZR_APP/Des.h
  21. 2
      libraries/AP_GPS/GPS_Backend.cpp
  22. 13
      libraries/AP_Notify/AP_Notify.cpp
  23. 2
      libraries/AP_Notify/AP_Notify.h
  24. 2
      libraries/AP_Notify/NotifyDevice.h
  25. 157
      libraries/AP_Notify/RGBLed.cpp
  26. 6
      libraries/AP_Notify/RGBLed.h
  27. 9
      libraries/AP_Notify/ToneAlarm.cpp
  28. 5
      libraries/AP_Notify/ToshibaLED_I2C.cpp
  29. 1
      libraries/AP_Notify/ToshibaLED_I2C.h
  30. 26
      libraries/AP_Notify/UAVCAN_RGB_LED.cpp
  31. 7
      libraries/AP_Notify/UAVCAN_RGB_LED.h
  32. 8
      libraries/AP_Proximity/AP_Proximity.cpp
  33. 1
      libraries/AP_Proximity/AP_Proximity.h
  34. 250
      libraries/AP_Proximity/AP_Proximity_UAVCAN.cpp
  35. 72
      libraries/AP_Proximity/AP_Proximity_UAVCAN.h
  36. 41
      libraries/AP_UAVCAN/AP_UAVCAN.cpp
  37. 13
      libraries/AP_UAVCAN/AP_UAVCAN.h
  38. 4
      libraries/AP_UAVCAN/dsdl/zrzk/equipment/indication/30100.ZrRGB.uavcan
  39. 23
      libraries/AP_UAVCAN/dsdl/zrzk/equipment/range_sensor/26110.Proximity.uavcan
  40. 2
      modules/mavlink
  41. 3
      periph_copy.sh

28
ArduCopter/APM_Config.h

@ -13,18 +13,18 @@ @@ -13,18 +13,18 @@
//#define PARACHUTE DISABLED // disable parachute release to save 1k of flash
//#define NAV_GUIDED DISABLED // disable external navigation computer ability to control vehicle through MAV_CMD_NAV_GUIDED mission commands
//#define PRECISION_LANDING DISABLED // disable precision landing using companion computer or IRLock sensor
//#define BEACON_ENABLED DISABLED // disable beacon support
//#define SPRAYER_ENABLED DISABLED // disable the crop sprayer feature (two ESC controlled pumps the speed of which depends upon the vehicle's horizontal velocity)
#define BEACON_ENABLED DISABLED // disable beacon support
#define SPRAYER_ENABLED DISABLED // disable the crop sprayer feature (two ESC controlled pumps the speed of which depends upon the vehicle's horizontal velocity)
//#define WINCH_ENABLED DISABLED // disable winch support
//#define GRIPPER_ENABLED DISABLED // disable gripper support
#define GRIPPER_ENABLED DISABLED // disable gripper support
//#define RPM_ENABLED DISABLED // disable rotations per minute sensor support
//#define STATS_ENABLED DISABLED // disable statistics support
//#define MODE_ACRO_ENABLED DISABLED // disable acrobatic mode support
//#define MODE_AUTO_ENABLED DISABLED // disable auto mode support
//#define MODE_BRAKE_ENABLED DISABLED // disable brake mode support
//#define MODE_CIRCLE_ENABLED DISABLED // disable circle mode support
//#define MODE_DRIFT_ENABLED DISABLED // disable drift mode support
//#define MODE_FLIP_ENABLED DISABLED // disable flip mode support
#define MODE_DRIFT_ENABLED DISABLED // disable drift mode support
#define MODE_FLIP_ENABLED DISABLED // disable flip mode support
//#define MODE_FOLLOW_ENABLED DISABLED // disable follow mode support
//#define MODE_GUIDED_ENABLED DISABLED // disable guided mode support
//#define MODE_GUIDED_NOGPS_ENABLED DISABLED // disable guided/nogps mode support
@ -34,8 +34,8 @@ @@ -34,8 +34,8 @@
//#define MODE_SMARTRTL_ENABLED DISABLED // disable smartrtl mode support
//#define MODE_SPORT_ENABLED DISABLED // disable sport mode support
//#define MODE_SYSTEMID_ENABLED DISABLED // disable system ID mode support
//#define MODE_THROW_ENABLED DISABLED // disable throw mode support
//#define MODE_ZIGZAG_ENABLED DISABLED // disable zigzag mode support
#define MODE_THROW_ENABLED DISABLED // disable throw mode support
#define MODE_ZIGZAG_ENABLED DISABLED // disable zigzag mode support
//#define OSD_ENABLED DISABLED // disable on-screen-display support
//#define LANDING_GEAR_ENABLED DISABLED // disable landing gear support
@ -51,11 +51,11 @@ @@ -51,11 +51,11 @@
// Put your variable definitions into the UserVariables.h file (or another file name and then change the #define below).
//#define USERHOOK_VARIABLES "UserVariables.h"
// Put your custom code into the UserCode.cpp with function names matching those listed below and ensure the appropriate #define below is uncommented below
//#define USERHOOK_INIT userhook_init(); // for code to be run once at startup
//#define USERHOOK_FASTLOOP userhook_FastLoop(); // for code to be run at 100hz
//#define USERHOOK_50HZLOOP userhook_50Hz(); // for code to be run at 50hz
//#define USERHOOK_MEDIUMLOOP userhook_MediumLoop(); // for code to be run at 10hz
//#define USERHOOK_SLOWLOOP userhook_SlowLoop(); // for code to be run at 3.3hz
//#define USERHOOK_SUPERSLOWLOOP userhook_SuperSlowLoop(); // for code to be run at 1hz
//#define USERHOOK_AUXSWITCH ENABLED // for code to handle user aux switches
#define USERHOOK_INIT userhook_init(); // for code to be run once at startup
#define USERHOOK_FASTLOOP userhook_FastLoop(); // for code to be run at 100hz
#define USERHOOK_50HZLOOP userhook_50Hz(); // for code to be run at 50hz
#define USERHOOK_MEDIUMLOOP userhook_MediumLoop(); // for code to be run at 10hz
#define USERHOOK_SLOWLOOP userhook_SlowLoop(); // for code to be run at 3.3hz
#define USERHOOK_SUPERSLOWLOOP userhook_SuperSlowLoop(); // for code to be run at 1hz
// #define USERHOOK_AUXSWITCH ENABLED // for code to handle user aux switches
//#define USER_PARAMS_ENABLED ENABLED // to enable user parameters

18
ArduCopter/AP_Arming.cpp

@ -550,7 +550,11 @@ bool AP_Arming_Copter::alt_checks(bool display_failure) @@ -550,7 +550,11 @@ bool AP_Arming_Copter::alt_checks(bool display_failure)
// has side-effect that logging is started
bool AP_Arming_Copter::arm_checks(AP_Arming::Method method)
{
const auto &ahrs = AP::ahrs();
if(!mandatory_deadline_checks(false)){ // 检查注册是否到期
return false;
}
// always check if inertial nav has started and is ready
if (!ahrs.healthy()) {
@ -840,3 +844,17 @@ bool AP_Arming_Copter::disarm(const AP_Arming::Method method, bool do_disarm_che @@ -840,3 +844,17 @@ bool AP_Arming_Copter::disarm(const AP_Arming::Method method, bool do_disarm_che
return true;
}
bool AP_Arming_Copter::mandatory_deadline_checks(bool display_failure)
{
uint32_t date;
if (!copter.zr_app.check_deadline(date))
{
// check_failed(true, "无法解锁,授权于 %u-%u-%u 到期!", date / 10000, (date % 10000) / 100, date % 100);
check_failed(true, "Trial time has expired at %lu-%lu-%lu", date / 10000, (date % 10000) / 100, date % 100);
// check_failed(display_failure, "Trial time has expired at %d-%d-%d !", date / 10000, (date % 10000) / 100, date % 100);
return false;
}else{
return true;
}
}

3
ArduCopter/AP_Arming.h

@ -48,9 +48,10 @@ protected: @@ -48,9 +48,10 @@ protected:
bool gcs_failsafe_check(bool display_failure);
bool winch_checks(bool display_failure) const;
bool alt_checks(bool display_failure);
void set_pre_arm_check(bool b);
bool mandatory_deadline_checks(bool display_failure); // 飞机到期时间检查
private:
// actually contains the pre-arm checks. This is wrapped so that

8
ArduCopter/Copter.h

@ -70,6 +70,8 @@ @@ -70,6 +70,8 @@
#include <AP_ADSB/AP_ADSB.h> // ADS-B RF based collision avoidance module library
#include <AP_Proximity/AP_Proximity.h> // ArduPilot proximity sensor library
#include <AC_ZR_APP/AC_ZR_App.h>
// Configuration
#include "defines.h"
#include "config.h"
@ -1000,8 +1002,14 @@ private: @@ -1000,8 +1002,14 @@ private:
Mode *mode_from_mode_num(const Mode::Number mode);
void exit_mode(Mode *&old_flightmode, Mode *&new_flightmode);
AC_ZR_App zr_app;
public:
void failsafe_check(); // failsafe.cpp
void zr_app_50hz();
void zr_app_10hz();
void zr_app_1hz();
};
extern Copter copter;

6
ArduCopter/GCS_Mavlink.cpp

@ -607,6 +607,12 @@ void GCS_MAVLINK_Copter::send_banner() @@ -607,6 +607,12 @@ void GCS_MAVLINK_Copter::send_banner()
char frame_and_type_string[30];
copter.motors->get_frame_and_type_string(frame_and_type_string, ARRAY_SIZE(frame_and_type_string));
send_text(MAV_SEVERITY_INFO, "%s", frame_and_type_string);
uint32_t deadline = 0;
copter.zr_app.get_deadline_params(deadline);
send_text(MAV_SEVERITY_INFO, "Date:%lu",deadline);
send_text(MAV_SEVERITY_INFO, "ID:%lu",copter.zr_app.get_zr_sysid());
}
void GCS_MAVLINK_Copter::handle_command_ack(const mavlink_message_t &msg)

2
ArduCopter/Parameters.cpp

@ -722,6 +722,8 @@ const AP_Param::Info Copter::var_info[] = { @@ -722,6 +722,8 @@ const AP_Param::Info Copter::var_info[] = {
// @Path: Parameters.cpp
GOBJECT(g2, "", ParametersG2),
GOBJECT(zr_app, "ZR", AC_ZR_App),
// @Group:
// @Path: ../libraries/AP_Vehicle/AP_Vehicle.cpp
{ AP_PARAM_GROUP, "", Parameters::k_param_vehicle, (const void *)&copter, {group_info : AP_Vehicle::var_info} },

1
ArduCopter/Parameters.h

@ -376,6 +376,7 @@ public: @@ -376,6 +376,7 @@ public:
// 254,255: reserved
k_param_vehicle = 257, // vehicle common block of parameters
k_param_zr_app = 258, // 253 - Logging Group
// the k_param_* space is 9-bits in size
// 511: reserved

3
ArduCopter/UserCode.cpp

@ -19,6 +19,7 @@ void Copter::userhook_FastLoop() @@ -19,6 +19,7 @@ void Copter::userhook_FastLoop()
void Copter::userhook_50Hz()
{
// put your 50Hz code here
zr_app_50hz();
}
#endif
@ -26,6 +27,7 @@ void Copter::userhook_50Hz() @@ -26,6 +27,7 @@ void Copter::userhook_50Hz()
void Copter::userhook_MediumLoop()
{
// put your 10Hz code here
zr_app_10hz();
}
#endif
@ -40,6 +42,7 @@ void Copter::userhook_SlowLoop() @@ -40,6 +42,7 @@ void Copter::userhook_SlowLoop()
void Copter::userhook_SuperSlowLoop()
{
// put your 1Hz code here
zr_app_1hz();
}
#endif

17
ArduCopter/mode.cpp

@ -575,8 +575,11 @@ void Mode::land_run_vertical_control(bool pause_descent) @@ -575,8 +575,11 @@ void Mode::land_run_vertical_control(bool pause_descent)
bool ignore_descent_limit = false;
if (!pause_descent) {
// @Brown, loiter land auto deceleration
int16_t land_speed_now = get_land_deceleration();
// do not ignore limits until we have slowed down for landing
ignore_descent_limit = (MAX(g2.land_alt_low,100) > get_alt_above_ground_cm()) || copter.ap.land_complete_maybe;
ignore_descent_limit = (MAX(g2.land_alt_low,2000) > get_alt_above_ground_cm()) || copter.ap.land_complete_maybe; // 最低高度100改2000,最低20m开始降速
float max_land_descent_velocity;
if (g.land_speed_high > 0) {
@ -592,7 +595,8 @@ void Mode::land_run_vertical_control(bool pause_descent) @@ -592,7 +595,8 @@ void Mode::land_run_vertical_control(bool pause_descent)
cmb_rate = sqrt_controller(MAX(g2.land_alt_low,100)-get_alt_above_ground_cm(), pos_control->get_pos_z_p().kP(), pos_control->get_max_accel_z_cmss(), G_Dt);
// Constrain the demanded vertical velocity so that it is between the configured maximum descent speed and the configured minimum descent speed.
cmb_rate = constrain_float(cmb_rate, max_land_descent_velocity, -abs(g.land_speed));
// cmb_rate = constrain_float(cmb_rate, max_land_descent_velocity, -abs(g.land_speed));
cmb_rate = constrain_float(cmb_rate, max_land_descent_velocity, -abs(land_speed_now)); // 替换速度
#if PRECISION_LANDING == ENABLED
const bool navigating = pos_control->is_active_xy();
@ -1024,3 +1028,12 @@ uint16_t Mode::get_pilot_speed_dn() @@ -1024,3 +1028,12 @@ uint16_t Mode::get_pilot_speed_dn()
{
return copter.get_pilot_speed_dn();
}
/**
* @brief
* @author ZRZK
* @return uint16_t
*/
uint16_t Mode::get_land_deceleration()
{
return copter.zr_app.get_land_deceleration(get_alt_above_ground_cm(),get_pilot_speed_dn());
}

2
ArduCopter/mode.h

@ -295,6 +295,8 @@ public: @@ -295,6 +295,8 @@ public:
GCS_Copter &gcs();
void set_throttle_takeoff(void);
uint16_t get_pilot_speed_dn(void);
uint16_t get_land_deceleration();
// end pass-through functions
};

8
ArduCopter/mode_loiter.cpp

@ -87,8 +87,11 @@ void ModeLoiter::run() @@ -87,8 +87,11 @@ void ModeLoiter::run()
float target_yaw_rate = 0.0f;
float target_climb_rate = 0.0f;
// @Brown, loiter land auto deceleration
int16_t land_speed_now = get_land_deceleration();
// set vertical speed and acceleration limits
pos_control->set_max_speed_accel_z(-get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
// pos_control->set_max_speed_accel_z(-get_pilot_speed_dn(), g.pilot_speed_up, g.pilot_accel_z);
pos_control->set_max_speed_accel_z(-land_speed_now, g.pilot_speed_up, g.pilot_accel_z); // 替换速度
// process pilot inputs unless we are in radio failsafe
if (!copter.failsafe.radio) {
@ -106,7 +109,8 @@ void ModeLoiter::run() @@ -106,7 +109,8 @@ void ModeLoiter::run()
// get pilot desired climb rate
target_climb_rate = get_pilot_desired_climb_rate(channel_throttle->get_control_in());
target_climb_rate = constrain_float(target_climb_rate, -get_pilot_speed_dn(), g.pilot_speed_up);
// target_climb_rate = constrain_float(target_climb_rate, -get_pilot_speed_dn(), g.pilot_speed_up);
target_climb_rate = constrain_float(target_climb_rate, -land_speed_now, g.pilot_speed_up); // 替换速度
} else {
// clear out pilot desired acceleration in case radio failsafe event occurs and we do not switch to RTL for some reason
loiter_nav->clear_pilot_desired_acceleration();

1
ArduCopter/wscript

@ -31,6 +31,7 @@ def build(bld): @@ -31,6 +31,7 @@ def build(bld):
'AP_OSD',
'AC_AutoTune',
'AP_KDECAN',
'AC_ZR_APP',
],
)

31
ArduCopter/zr_app.cpp

@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
#include "Copter.h"
void Copter::zr_app_1hz()
{
static bool before_fly = true;
if(motors->armed()){
if(before_fly){
before_fly = false;
}
relay.on(3); // 电子开关,保持通路
// camera.set_in_arm_mode(true);
}else{
relay.off(3);
if(before_fly){
uint8_t bat_cnt = zr_app.get_battery_capacity(1,battery.voltage());
battery.reset_remaining(0,(float)bat_cnt );
// gcs().send_text(MAV_SEVERITY_INFO, "bat:%.2f,pst%d,%.2f",battery.voltage(),bat_cnt,(float)bat_cnt);
}
}
}
void Copter::zr_app_10hz()
{
}
void Copter::zr_app_50hz(){
}

3
bd-pix4.sh

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
./waf configure --board Pixhawk4
./waf copter
cp ./build/Pixhawk4/bin/arducopter.apj /mnt/f/_01-work/100=data/固件/编译/pixhakw4-master.px4

3
cubeblack.sh

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
./waf configure --board cubeblack
./waf copter
cp ./build/CubeBlack/bin/arducopter.apj /mnt/e/_00-inbox/_temp/cubeblack.px4

2
just_build.sh

@ -0,0 +1,2 @@ @@ -0,0 +1,2 @@
./waf copter
cp build/Pixhawk4/bin/arducopter.apj /mnt/hgfs/firmware/编译/c415.px4

255
libraries/AC_ZR_APP/AC_ZR_App.cpp

@ -0,0 +1,255 @@ @@ -0,0 +1,255 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "AC_ZR_App.h"
AC_ZR_App *AC_ZR_App::_singleton;
// table of user settable parameters
const AP_Param::GroupInfo AC_ZR_App::var_info[] = {
// @Param: _TYPE
// @DisplayName: user type
// @Description: parameters test
// @Values: 0:None,1:other
// @RebootRequired: True
// @User: zrzk
AP_GROUPINFO("_TYPE", 0, AC_ZR_App, _type, 1),
AP_GROUPINFO("_SYS_TYPE", 1, AC_ZR_App, sysid_type, 0 ),
AP_GROUPINFO("_SYS_ID", 2, AC_ZR_App, sysid_board_id, 98765432U),
AP_GROUPINFO("_SYS_DL1", 3, AC_ZR_App, sysid_dl1, 0x8175),
AP_GROUPINFO("_SYS_DL2", 4, AC_ZR_App, sysid_dl2, 0x6fda),
AP_GROUPINFO("_SYS_DL3", 5, AC_ZR_App, sysid_dl3, 0xf38f),
AP_GROUPINFO("_SYS_DL4", 6, AC_ZR_App, sysid_dl4, 0xbf48),
// @Param: _SL_*
// @DisplayName: ZR_SL_*
// @Description: 降落减速设置,3个梯度
// @Values: 值单位cm和cm/s
// @RebootRequired: True
// @User: zrzk
AP_GROUPINFO("_SL_ALT_HI", 7, AC_ZR_App, land_slow_alt_high, 3000),
AP_GROUPINFO("_SL_ALT_MI", 8, AC_ZR_App, land_slow_alt_mid, 1500),
AP_GROUPINFO("_SL_ALT_LO", 9, AC_ZR_App, land_slow_alt_low, 150),
AP_GROUPINFO("_SL_SPD_HI", 10, AC_ZR_App, land_slow_speed_dn_high, 150),
AP_GROUPINFO("_SL_SPD_MI", 11, AC_ZR_App, land_slow_speed_dn_mid, 50),
AP_GROUPINFO("_SL_SPD_LO", 12, AC_ZR_App, land_slow_speed_dn_low, 30),
AP_GROUPEND
};
// constructor
AC_ZR_App::AC_ZR_App()
{
AP_Param::setup_object_defaults(this, var_info);
if (_singleton != nullptr) {
AP_HAL::panic("AC_ZR_App must be singleton");
}
_singleton = this;
}
/**
* @brief
*
* @param deadline
*/
void AC_ZR_App::get_deadline_params(uint32_t &deadline)
{
uint8_t tempbuf[8];
tempbuf[1] = sysid_dl1 & 0xff;
tempbuf[0] = (sysid_dl1 & 0xff00) >> 8;
// gcs().send_text(MAV_SEVERITY_INFO, "tempbuf0: %d ,tempbuf1:%d",tempbuf[0] ,tempbuf[1]);
tempbuf[3] = sysid_dl2 & 0xff;
tempbuf[2] = (sysid_dl2 & 0xff00) >> 8;
//gcs().send_text(MAV_SEVERITY_INFO, "tempbuf2: %d ,tempbuf3:%d",tempbuf[2] ,tempbuf[3]);
tempbuf[5] = sysid_dl3 & 0xff;
tempbuf[4] = (sysid_dl3 & 0xff00) >> 8;
//gcs().send_text(MAV_SEVERITY_INFO, "tempbuf4: %d ,tempbuf5:%d",tempbuf[4] ,tempbuf[5]);
tempbuf[7] = sysid_dl4 & 0xff;
tempbuf[6] = (sysid_dl4 & 0xff00) >> 8;
//gcs().send_text(MAV_SEVERITY_INFO, "tempbuf6: %d ,tempbuf7:%d",tempbuf[6] ,tempbuf[7]);
uint8_t out_data_temp[8];
Des des;
uint8_t deskey_zr[8]= {90, 114, 90, 107, 85, 97, 86, 103}; //{ "ZrZkUaVg" };
uint8_t deskey_zhd[8]= {90, 114, 90, 104, 68, 85, 97, 86}; //{ "ZrZhDUaV" };
int8_t type = (int)ZR_FRAME_TYPE;
if(type == 3 ){ // 中海达加密模式
des.des(&tempbuf[0], &deskey_zhd[0], 1, &out_data_temp[0]);
}else{
des.des(&tempbuf[0], &deskey_zr[0], 1, &out_data_temp[0]);
}
// des.des(&tempbuf[0], &des.deskey[0], 1, &out_data_temp[0]);
//gcs().send_text(MAV_SEVERITY_INFO, "out_data_temp6: %d ,out_data_temp7:%d",out_data_temp[6] ,out_data_temp[7]);
if (out_data_temp[6] == 122 && out_data_temp[7] == 114) //'zr'
{
deadline = 20000000 + ((out_data_temp[0] - 0x30) * 10 + (out_data_temp[1] - 0x30)) * 10000 +
((out_data_temp[2] - 0x30) * 10 + (out_data_temp[3] - 0x30)) * 100 +
((out_data_temp[4] - 0x30) * 10 + (out_data_temp[5] - 0x30));
}
else
{
deadline = 20200101;
gcs().send_text(MAV_SEVERITY_INFO, "D_Error: The registration code is wrong!");
}
}
/**
* @brief
*
* @param date
* @return true
* @return false
*/
bool AC_ZR_App::check_deadline(uint32_t &date)
{
uint32_t deadline =0;
const AP_GPS &gps = AP::gps();
if(gps.status() < 2){ // 室内测试没卫星的情况,允许解锁测试
return true;
}
get_deadline_params(deadline);
date = deadline;
uint32_t gps_date =0;
if((gps.time_week() ==0)||(gps.time_week_ms() ==0)){
return false;
}
uint64_t timestamp = gps.istate_time_to_epoch_ms(gps.time_week(),gps.time_week_ms())/1000;
//tick -timestamp - uint:s
time_t tick = (time_t)timestamp;
tm gpstime = *localtime(&tick);
uint16_t year = gpstime.tm_year+1900;
uint8_t month = gpstime.tm_mon+1;
uint8_t day = gpstime.tm_mday;
gps_date = year*10000+month*100+day;
if (deadline>= gps_date)
{
return true;
}
else
{
return false;
}
}
uint32_t AC_ZR_App::get_zr_sysid()
{
return (uint32_t)sysid_board_id;
}
/**
* @brief
*
* @param alt_cm
* @param sys_speed_dn
* @return uint16_t
*/
uint16_t AC_ZR_App::get_land_deceleration(int32_t alt_cm,int16_t sys_speed_dn)
{
int16_t speed_dn_now = sys_speed_dn; // 没到减速阶段则使用系统降落速度
if(alt_cm < land_slow_alt_low){ // 最低处减速
speed_dn_now = land_slow_speed_dn_low;
}
else if(alt_cm < land_slow_alt_mid){ // 中高处减速
speed_dn_now = land_slow_speed_dn_mid;
}
else if(alt_cm < land_slow_alt_high){ // 高处减速
speed_dn_now = land_slow_speed_dn_high;
}
return abs(speed_dn_now);
}
uint8_t AC_ZR_App::BinarySearch2f(float a[], float value, int low, int high)
{
static uint8_t cacl_volt_pst = 0;
if (low > high)
return cacl_volt_pst;
cacl_volt_pst = (low + high) / 2;
if (fabs(a[cacl_volt_pst] - value)<0.01)
//if (abs(a[mid] - value) < 30)
return cacl_volt_pst;
else if (a[cacl_volt_pst] > value)
return BinarySearch2f(a, value, low, cacl_volt_pst - 1);
else
return BinarySearch2f(a, value, cacl_volt_pst + 1, high);
}
uint8_t AC_ZR_App::get_battery_capacity(uint8_t type,float volt)
{
uint8_t bat_cnt = 100;
// float cycle_pst = (1 - bat_cycled * 0.0002);
switch (type)
{
case 0:
/* code */
break;
case 1:
static float batt_mah_teb[] =
{
16.80, 17.40, 18.00, 18.51, 18.80, 19.00, 19.19, 19.34, 19.53, 19.73,
19.88, 20.04, 20.16, 20.29, 20.47, 20.56, 20.63, 20.69, 20.75, 20.80,
20.85, 20.90, 20.96, 21.02, 21.07, 21.13, 21.18, 21.24, 21.29, 21.34,
21.40, 21.45, 21.49, 21.54, 21.59, 21.64, 21.69, 21.72, 21.76, 21.79,
21.84, 21.88, 21.92, 21.96, 22.01, 22.06, 22.11, 22.16, 22.21, 22.26,
22.31, 22.37, 22.43, 22.48, 22.54, 22.59, 22.65, 22.70, 22.76, 22.81,
22.86, 22.91, 22.95, 23.01, 23.07, 23.13, 23.19, 23.24, 23.30, 23.36,
23.41, 23.46, 23.51, 23.58, 23.65, 23.71, 23.79, 23.88, 23.94, 24.00,
24.07, 24.14, 24.21, 24.26, 24.32, 24.36, 24.40, 24.43, 24.45, 24.48,
24.50, 24.52, 24.54, 24.57, 24.60, 24.64, 24.69, 24.76, 24.84, 24.90,
25.20
};
bat_cnt = BinarySearch2f(batt_mah_teb,volt,0,100);
// gcs().send_text(MAV_SEVERITY_INFO,"cnt:%d,mid:%d",bat_cnt,cacl_volt_pst);
break;
case 2:
static float batt_mah_teb_7s[] =
{
21.60, 21.80, 22.04, 22.28, 22.52, 22.74, 22.95, 23.19, 23.32, 23.52,
23.65, 23.81, 23.94, 24.02, 24.10, 24.18, 24.22, 24.25, 24.30, 24.39,
24.46, 24.52, 24.60, 24.67, 24.74, 24.80, 24.86, 24.93, 24.97, 25.03,
25.08, 25.13, 25.18, 25.23, 25.27, 25.32, 25.36, 25.41, 25.45, 25.50,
25.54, 25.58, 25.63, 25.69, 25.74, 25.79, 25.85, 25.91, 25.98, 26.05,
26.10, 26.16, 26.21, 26.28, 26.35, 26.40, 26.47, 26.54, 26.61, 26.67,
26.74, 26.79, 26.85, 26.93, 27.00, 27.07, 27.13, 27.19, 27.26, 27.32,
27.38, 27.46, 27.52, 27.59, 27.66, 27.75, 27.80, 27.87, 27.94, 28.03,
28.10, 28.16, 28.21, 28.28, 28.33, 28.38, 28.43, 28.46, 28.50, 28.53,
28.56, 28.59, 28.61, 28.64, 28.67, 28.71, 28.77, 28.86, 28.97, 29.13,
29.30
};
bat_cnt = BinarySearch2f(batt_mah_teb_7s,volt,0,100);
// gcs().send_text(MAV_SEVERITY_INFO,"cnt:%d,mid:%d",bat_cnt,cacl_volt_pst);
break;
default:
break;
}
return bat_cnt;
}

70
libraries/AC_ZR_APP/AC_ZR_App.h

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <AP_HAL/AP_HAL.h>
#include <AP_Param/AP_Param.h>
#include <GCS_MAVLink/GCS.h>
#include <GCS_MAVLink/GCS_MAVLink.h>
#include <sys/time.h>
#include <time.h>
#include "Des.h"
#ifndef ZR_FRAME_TYPE
#define ZR_FRAME_TYPE 0
#endif
class AC_ZR_App
{
public:
AC_ZR_App();
/* Do not allow copies */
AC_ZR_App(const AC_ZR_App &other) = delete;
AC_ZR_App &operator=(const AC_ZR_App&) = delete;
static AC_ZR_App *get_singleton() {
return _singleton;
}
void get_deadline_params(uint32_t &deadline);
bool check_deadline(uint32_t &date);
uint32_t get_zr_sysid();
uint16_t get_land_deceleration(int32_t alt_cm,int16_t sys_speed_dn);
uint8_t get_battery_capacity(uint8_t type,float volt);
static const struct AP_Param::GroupInfo var_info[];
protected:
AP_Int8 _type;
AP_Int8 sysid_type; // modify by @Brown
AP_Int32 sysid_board_id;
AP_Int32 sysid_dl1;
AP_Int32 sysid_dl2;
AP_Int32 sysid_dl3;
AP_Int32 sysid_dl4;
AP_Int16 land_slow_alt_high;
AP_Int16 land_slow_alt_mid;
AP_Int16 land_slow_alt_low;
AP_Int16 land_slow_speed_dn_high;
AP_Int16 land_slow_speed_dn_mid;
AP_Int16 land_slow_speed_dn_low;
private:
static AC_ZR_App *_singleton;
uint8_t BinarySearch2f(float a[], float value, int low, int high);
};

328
libraries/AC_ZR_APP/Des.cpp

@ -0,0 +1,328 @@ @@ -0,0 +1,328 @@
#include "Des.h"
const uint8_t initial_tr[64] =
{
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7,
56, 48, 40, 32, 24, 16, 8, 0,
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6};
const uint8_t final_tr[64] =
{
39, 7, 47, 15, 55, 23, 63, 31,
38, 6, 46, 14, 54, 22, 62, 30,
37, 5, 45, 13, 53, 21, 61, 29,
36, 4, 44, 12, 52, 20, 60, 28,
35, 3, 43, 11, 51, 19, 59, 27,
34, 2, 42, 10, 50, 18, 58, 26,
33, 1, 41, 9, 49, 17, 57, 25,
32, 0, 40, 8, 48, 16, 56, 24};
const uint8_t swap[64] =
{
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, 61, 62, 63, 64,
1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32};
const uint8_t key_tr1[56] =
{
56, 48, 40, 32, 24, 16, 8,
0, 57, 49, 41, 33, 25, 17,
9, 1, 58, 50, 42, 34, 26,
18, 10, 2, 59, 51, 43, 35,
62, 54, 46, 38, 30, 22, 14,
6, 61, 53, 45, 37, 29, 21,
13, 5, 60, 52, 44, 36, 28,
20, 12, 4, 27, 19, 11, 3};
const uint8_t key_tr2[64] =
{
0, 0, 13, 4, 16, 10, 23, 0,
0, 0, 2, 9, 27, 14, 5, 20,
0, 0, 22, 7, 18, 11, 3, 25,
0, 0, 15, 1, 6, 26, 19, 12,
0, 0, 40, 54, 51, 30, 36, 46,
0, 0, 29, 47, 39, 50, 44, 32,
0, 0, 43, 52, 48, 38, 55, 33,
0, 0, 45, 31, 41, 49, 35, 28};
const uint8_t etr[64] =
{
0, 0, 31, 4, 0, 1, 2, 3,
0, 0, 3, 8, 4, 5, 6, 7,
0, 0, 7, 12, 8, 9, 10, 11,
0, 0, 11, 16, 12, 13, 14, 15,
0, 0, 15, 20, 16, 17, 18, 19,
0, 0, 19, 24, 20, 21, 22, 23,
0, 0, 23, 28, 24, 25, 26, 27,
0, 0, 27, 0, 28, 29, 30, 31};
const uint8_t ptr[32] =
{
31, 14, 39, 44, 60, 23, 55, 36,
4, 30, 46, 53, 12, 37, 62, 21,
5, 15, 47, 29, 63, 54, 6, 20,
38, 28, 61, 13, 45, 22, 7, 52};
const uint8_t s[8][64] =
{
{14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13},
{15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9},
{10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12},
{7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14},
{2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3},
{12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13},
{4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12},
{13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11}};
const uint8_t rots[16] =
{
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1};
const uint8_t bit_msk[8] =
{
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
/************************************************************************/
/* */
/* Module title: des */
/* Module type: des mainrutine */
/* */
/* Author: YXH */
/* Date: 2012-07-13 */
/* */
/* Last changed by: YXH */
/* Date: 2012-07-13 */
/* */
/* Functional Description: Encipher and decipher 64 bits string */
/* according to a 64 bits key string */
/* The string format is shown below */
/* */
/* input parameter 1: pointer to 64 bits input string */
/* 2: pointer to 64 bits key string */
/* 3: boolean if false indicating enciphering */
/* if true dechiphering 1解密 */
/* 4: pointer to a 64 bits output string */
/************************************************************************/
/* */
/* msb lsb */
/* bit bit */
/* +-- -- -- -- -- -- -- --+ */
/* addr !1st 8th! */
/* +-- -- -- -- -- -- -- --+ */
/* addr+1 !9th 16th! */
/* +-- -- -- -- -- -- -- --+ */
/* : : */
/* : : */
/* +-- -- -- -- -- -- -- --+ */
/* addr+7 !57th 64th! */
/* +-- -- -- -- -- -- -- --+ */
/* */
/************************************************************************/
void Des::des(uint8_t* plain_strng, uint8_t* key, uint8_t d, uint8_t* ciph_strng)
{
uint8_t a_str[8], b_str[8], x_str[8];
uint8_t i, j, * pkey, temp;
for (i = 0; i < 8; ++i)
{
if (key[i] != main_key[i])
{
compute_subkeys(key);
i = 7;
}
}
transpose(plain_strng, a_str, initial_tr, 64);
for (i = 1; i < 17; ++i)
{
for (j = 0; j < 8; ++j) { b_str[j] = a_str[j]; }
if (!d) /*enchipher*/
pkey = &sub_keys[i - 1][0];
else /*dechipher*/
pkey = &sub_keys[16 - i][0];
for (j = 0; j < 4; ++j) { a_str[j] = b_str[j + 4]; }
f(pkey, a_str, x_str);
for (j = 0; j < 4; ++j) { a_str[j + 4] = b_str[j] ^ x_str[j]; }
}
temp = a_str[0]; a_str[0] = a_str[4]; a_str[4] = temp;
temp = a_str[1]; a_str[1] = a_str[5]; a_str[5] = temp;
temp = a_str[2]; a_str[2] = a_str[6]; a_str[6] = temp;
temp = a_str[3]; a_str[3] = a_str[7]; a_str[7] = temp;
transpose(a_str, ciph_strng, final_tr, 64);
}
/************************************************************************/
/* */
/* Module title: transpose */
/* Module type: des subrutine */
/* */
/* Author: YXH */
/* Date: 2012-07-13 */
/* */
/* Last changed by: YXH */
/* Date: 2012-07-13 */
/* */
/* Functional Description: Permute n bits in a string, according */
/* to a table describing the new order. */
/* 0 < n <= 64 */
/* */
/* input parameter 1: pointer to first byte in input string */
/* 2: pointer to first byte in output string */
/* 3: pointer to table describing new order */
/* 4: number of bits to be permuted */
/************************************************************************/
void Des:: transpose(uint8_t* idata, uint8_t* odata, const uint8_t* tbl, uint8_t n)
{
const uint8_t* tab_adr;
int i, bi_idx;
tab_adr = &bit_msk[0];
i = 0;
do
{
odata[i++] = 0;
} while (i < 8);
i = 0;
do
{
bi_idx = *tbl++;
if (idata[bi_idx >> 3] & tab_adr[bi_idx & 7])
{
odata[i >> 3] |= tab_adr[i & 7];
}
} while (++i < n);
}
/************************************************************************/
/* */
/* Module title: rotate_l */
/* Module type: des subrutine */
/* */
/* Author: YXH */
/* Date: 2012-07-13 */
/* */
/* Last changed by: YXH */
/* Date: 2012-07-13 */
/* */
/* Functional Description: rotate 2 concatenated strings of 28 */
/* bits one position to the left. */
/* */
/* input parameter 1: pointer to first byte in key string */
/* */
/************************************************************************/
void Des::rotate_l(uint8_t* key)
{
uint8_t str_x[8];
uint8_t i;
for (i = 0; i < 8; ++i) str_x[i] = key[i];
for (i = 0; i < 7; ++i)
{
key[i] = (key[i] << 1);
if ((i < 6) && ((str_x[i + 1] & 128) == 128))
key[i] |= 1;
}
if (str_x[0] & 0x80)
key[3] |= 0x10;
else
key[3] &= ~0x10;
if (str_x[3] & 0x08)
key[6] |= 0x01;
else
key[6] &= ~0x01;
}
/************************************************************************/
/* */
/* Module title: compute_subkeys */
/* Module type: des subrutine */
/* */
/* Author: YXH */
/* Date: 2012-07-13 */
/* */
/* Last changed by: YXH */
/* Date: 2012-07-13 */
/* */
/* Functional Description: Computes the 16 sub keys for use in the */
/* DES algorithm */
/* */
/* input parameter 1: pointer to first byte in key string */
/* output : fills the array sub_keys[16][8] with */
/* sub keys and stores the input key in */
/* main_key[8] */
/************************************************************************/
void Des::compute_subkeys(uint8_t* key)
{
uint8_t i, j, ikey[8], okey[8];
for (i = 0; i < 8; ++i)
{
main_key[i] = key[i];
}
transpose(key, ikey, key_tr1, 56);
for (i = 0; i < 16; ++i)
{
for (j = 0; j < rots[i]; ++j) { rotate_l(ikey); }
transpose(ikey, okey, key_tr2, 64);
for (j = 0; j < 8; ++j)
{
sub_keys[i][j] = okey[j];
}
}
}
/************************************************************************/
/* */
/* Module title: f */
/* Module type: des subrutine */
/* */
/* Author: YXH */
/* Date: 2012-07-13 */
/* */
/* Last changed by: YXH */
/* Date: 2012-07-13 */
/* */
/* Functional Description: The chipher function */
/* */
/* input parameter 1: pointer to first byte in key string */
/* 2: pointer to a 32 bit input string */
/* 3: pointer to a 32 bit output string */
/************************************************************************/
void Des::f(uint8_t* skey, uint8_t* a_str, uint8_t* x_str)
{
uint8_t e_str[8], y_str[8], z_str[8];
uint8_t k;
transpose(a_str, e_str, etr, 64);
for (k = 0; k < 8; ++k)
{
y_str[k] = (e_str[k] ^ skey[k]) & 63;
z_str[k] = s[k][y_str[k]];
}
transpose(z_str, x_str, ptr, 32);
}

22
libraries/AC_ZR_APP/Des.h

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
#pragma once
#include <stdint.h>
class Des
{
private:
/* data */
public:
// uint8_t deskey[8] = {90, 114, 90, 107, 85, 97, 86, 103}; //{ "ZrZkUaVg" };
// uint8_t deskey[8] = {90, 114, 90, 104, 68, 85, 97, 86}; //{ "ZrZhDUaV" };
uint8_t DES_Encrypt_key[8];
uint8_t DES_Decrypt_key[8];
uint8_t sub_keys[16][8]; //sub_keys[16][8]
uint8_t main_key[8];
void des(uint8_t *, uint8_t *, uint8_t, uint8_t *);
void FLASH_Read_KEYS(uint8_t key_index);
void transpose(uint8_t *, uint8_t *, const uint8_t *, uint8_t);
void rotate_l(uint8_t *);
void compute_subkeys(uint8_t *);
void f(uint8_t *, uint8_t *, uint8_t *);
};

2
libraries/AP_GPS/GPS_Backend.cpp

@ -107,6 +107,8 @@ void AP_GPS_Backend::make_gps_time(uint32_t bcd_date, uint32_t bcd_milliseconds) @@ -107,6 +107,8 @@ void AP_GPS_Backend::make_gps_time(uint32_t bcd_date, uint32_t bcd_milliseconds)
state.time_week = ret / AP_SEC_PER_WEEK;
state.time_week_ms = (ret % AP_SEC_PER_WEEK) * AP_MSEC_PER_SEC;
state.time_week_ms += msec;
check_new_itow(state.time_week_ms, 10); // 数据长度先取10,测试时间没问题
}
/*

13
libraries/AP_Notify/AP_Notify.cpp

@ -40,6 +40,8 @@ @@ -40,6 +40,8 @@
#include "ScriptingLED.h"
#include "DShotLED.h"
#include <GCS_MAVLink/GCS.h>
extern const AP_HAL::HAL& hal;
AP_Notify *AP_Notify::_singleton;
@ -252,7 +254,7 @@ void AP_Notify::add_backends(void) @@ -252,7 +254,7 @@ void AP_Notify::add_backends(void)
}
for (uint32_t i = 1; i < Notify_LED_MAX; i = i << 1) {
switch(_led_type & i) {
switch(_led_type & i) {
case Notify_LED_None:
break;
case Notify_LED_Board:
@ -422,6 +424,15 @@ void AP_Notify::handle_led_control(const mavlink_message_t &msg) @@ -422,6 +424,15 @@ void AP_Notify::handle_led_control(const mavlink_message_t &msg)
}
}
void AP_Notify::set_rgb_mode(uint8_t mode)
{
for (uint8_t i = 0; i < _num_devices; i++) {
if (_devices[i] != nullptr) {
_devices[i]->set_rgb_mode(mode);
}
}
}
// handle RGB from Scripting or AP_Periph
void AP_Notify::handle_rgb(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz)
{

2
libraries/AP_Notify/AP_Notify.h

@ -186,6 +186,8 @@ public: @@ -186,6 +186,8 @@ public:
uint8_t get_buzz_volume() const { return _buzzer_volume; }
uint8_t get_led_len() const { return _led_len; }
int8_t get_rgb_led_brightness_percent() const;
static void set_rgb_mode(uint8_t mode); // @Brown
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
HAL_Semaphore sf_window_mutex;

2
libraries/AP_Notify/NotifyDevice.h

@ -30,6 +30,8 @@ public: @@ -30,6 +30,8 @@ public:
// RGB control multiple leds independently
// give RGB value for single led
virtual void rgb_set_id(uint8_t r, uint8_t g, uint8_t b, uint8_t id) {}
virtual void set_rgb_mode(uint8_t mode) {} // @Brown
// this pointer is used to read the parameters relative to devices
const AP_Notify *pNotify;

157
libraries/AP_Notify/RGBLed.cpp

@ -35,16 +35,25 @@ RGBLed::RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t @@ -35,16 +35,25 @@ RGBLed::RGBLed(uint8_t led_off, uint8_t led_bright, uint8_t led_medium, uint8_t
// set_rgb - set color as a combination of red, green and blue values
void RGBLed::_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
{
if (red != _red_curr ||
green != _green_curr ||
blue != _blue_curr) {
// call the hardware update routine
if(rgb_source() == use_ws2812){
if (hw_set_rgb(red, green, blue)) {
_red_curr = red;
_green_curr = green;
_blue_curr = blue;
}
}else{
if (red != _red_curr ||
green != _green_curr ||
blue != _blue_curr) {
// call the hardware update routine
if (hw_set_rgb(red, green, blue)) {
_red_curr = red;
_green_curr = green;
_blue_curr = blue;
}
}
}
}
RGBLed::rgb_source_t RGBLed::rgb_source() const
@ -204,6 +213,9 @@ void RGBLed::update() @@ -204,6 +213,9 @@ void RGBLed::update()
case traffic_light:
current_colour_sequence = get_colour_sequence_traffic_light();
break;
case use_ws2812:
get_colour_ws2812();
break;
}
const uint8_t brightness = get_brightness();
@ -218,10 +230,19 @@ void RGBLed::update() @@ -218,10 +230,19 @@ void RGBLed::update()
const uint8_t colour = (current_colour_sequence >> (step*3)) & 7;
uint8_t red_des = (colour & RED) ? brightness : _led_off;
uint8_t green_des = (colour & GREEN) ? brightness : _led_off;
uint8_t blue_des = (colour & BLUE) ? brightness : _led_off;
uint8_t red_des ;
uint8_t green_des ;
uint8_t blue_des;
if(rgb_source() == use_ws2812){
red_des = (_red_ws != _led_off) ? brightness : 0;
green_des = (_green_ws != _led_off) ? brightness : 0;
blue_des = (_blue_ws != _led_off) ? brightness : 0;
}else{
red_des = (colour & RED) ? brightness : _led_off;
green_des = (colour & GREEN) ? brightness : _led_off;
blue_des = (colour & BLUE) ? brightness : _led_off;
}
set_rgb(red_des, green_des, blue_des);
}
@ -292,3 +313,123 @@ void RGBLed::rgb_control(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz) @@ -292,3 +313,123 @@ void RGBLed::rgb_control(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz)
_led_override.g = g;
_led_override.b = b;
}
void RGBLed::set_rgb_mode(uint8_t mode)
{
if (!pNotify->_rgb_led_override) {
// ignore LED_CONTROL commands if not in LED_OVERRIDE mode
return;
}
}
void RGBLed::get_colour_ws2812(void)
{
// initialising pattern
if (AP_Notify::flags.initialising) {
// return sequence_initialising;
_red_ws = _led_medium;
_blue_ws = _led_off;
_green_ws = _led_medium;
set_rgb_mode(1);
return;
}
// save trim and esc calibration pattern
if (AP_Notify::flags.save_trim || AP_Notify::flags.esc_calibration) {
// return sequence_trim_or_esc;
_red_ws = _led_medium;
_blue_ws = _led_medium;
_green_ws = _led_medium;
set_rgb_mode(1); // flow
return;
}
// radio and battery failsafe patter: flash yellow
// gps failsafe pattern : flashing yellow and blue
// ekf_bad pattern : flashing yellow and red
if (AP_Notify::flags.failsafe_radio ||
AP_Notify::flags.failsafe_battery ||
AP_Notify::flags.ekf_bad ||
AP_Notify::flags.gps_glitching ||
AP_Notify::flags.leak_detected) {
if (AP_Notify::flags.leak_detected) {
// purple if leak detected
// return sequence_failsafe_leak;
} else if (AP_Notify::flags.ekf_bad) {
// red on if ekf bad
// return sequence_failsafe_ekf;
} else if (AP_Notify::flags.gps_glitching) {
// blue on gps glitch
// return sequence_failsafe_gps_glitching;
}
// all off for radio or battery failsafe
// return sequence_failsafe_radio_or_battery;
_red_ws = _led_medium;
_blue_ws = _led_medium;
_green_ws = _led_off;
set_rgb_mode(1);
return;
}
static uint16_t arm_delay_cnt;
// solid green or blue if armed
if (AP_Notify::flags.armed) {
// solid green if armed with GPS 3d lock
if (AP_Notify::flags.gps_status >= AP_GPS::GPS_OK_FIX_3D) {
// return sequence_armed;
_red_ws = _led_off;
_blue_ws = _led_off;
_green_ws = _led_medium;
}
// solid blue if armed with no GPS lock
// return sequence_armed_nogps;
else{ _red_ws = _led_off;
_blue_ws = _led_medium;
_green_ws = _led_medium;
set_rgb_mode(0);}
if(arm_delay_cnt>500){
_red_ws = _led_off;
_blue_ws = _led_off;
_green_ws = _led_off;
set_rgb_mode(0);
}else{
arm_delay_cnt+=1;
}
return;
}else{
arm_delay_cnt = 0;
}
// double flash yellow if failing pre-arm checks
if (!AP_Notify::flags.pre_arm_check) {
// return sequence_prearm_failing;
_red_ws = _led_medium;
_blue_ws = _led_off;
_green_ws = _led_medium;
set_rgb_mode(1);
return;
}
if (AP_Notify::flags.gps_status >= AP_GPS::GPS_OK_FIX_3D_DGPS && AP_Notify::flags.pre_arm_gps_check) {
// return sequence_disarmed_good_dgps;
_red_ws = _led_off;
_blue_ws = _led_off;
_green_ws = _led_medium;
set_rgb_mode(2); // green breath
}else if (AP_Notify::flags.gps_status >= AP_GPS::GPS_OK_FIX_3D && AP_Notify::flags.pre_arm_gps_check) {
// return sequence_disarmed_good_gps;
_red_ws = _led_off;
_blue_ws = _led_off;
_green_ws = _led_medium;
set_rgb_mode(2); // blue green breath
}else{
_red_ws = _led_off;
_blue_ws = _led_medium;
_green_ws = _led_medium;
set_rgb_mode(2); // blue breath
}
// return sequence_disarmed_bad_gps;
}

6
libraries/AP_Notify/RGBLed.h

@ -39,6 +39,8 @@ public: @@ -39,6 +39,8 @@ public:
// give RGB and flash rate, used with scripting
virtual void rgb_control(uint8_t r, uint8_t g, uint8_t b, uint8_t rate_hz) override;
virtual void set_rgb_mode(uint8_t mode) override; // @Brown
protected:
// methods implemented in hardware specific classes
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) = 0;
@ -60,6 +62,8 @@ protected: @@ -60,6 +62,8 @@ protected:
uint8_t rate_hz;
uint32_t start_ms;
} _led_override;
uint8_t _red_ws, _green_ws, _blue_ws; // color requested by timed update, @Brown
private:
void update_colours();
@ -68,6 +72,7 @@ private: @@ -68,6 +72,7 @@ private:
uint32_t get_colour_sequence_traffic_light() const;
uint8_t get_brightness(void) const;
void get_colour_ws2812();
#define DEFINE_COLOUR_SEQUENCE(S0, S1, S2, S3, S4, S5, S6, S7, S8, S9) \
((S0) << (0*3) | (S1) << (1*3) | (S2) << (2*3) | (S3) << (3*3) | (S4) << (4*3) | (S5) << (5*3) | (S6) << (6*3) | (S7) << (7*3) | (S8) << (8*3) | (S9) << (9*3))
@ -108,6 +113,7 @@ private: @@ -108,6 +113,7 @@ private:
mavlink = 1,
obc = 2,
traffic_light = 3,
use_ws2812 = 4
};
rgb_source_t rgb_source() const;

9
libraries/AP_Notify/ToneAlarm.cpp

@ -47,9 +47,11 @@ const AP_ToneAlarm::Tone AP_ToneAlarm::_tones[] { @@ -47,9 +47,11 @@ const AP_ToneAlarm::Tone AP_ToneAlarm::_tones[] {
#define AP_NOTIFY_TONE_LOUD_POS_FEEDBACK 5
{ "MFT100L4>A#B#", false },
#define AP_NOTIFY_TONE_LOUD_READY_OR_FINISHED 6
{ "MFT100L4>G#6A#6B#4", false },
// { "MFT100L4>G#6A#6B#4", false },
{ "MFT200L4<G#6A#6B#6O4C#6D#4O3G#6A#6B#6O4C#6D#1", false }, // modify by @Brown
#define AP_NOTIFY_TONE_QUIET_READY_OR_FINISHED 7
{ "MFT200L4<G#6A#6B#4", false },
// { "MFT200L4<G#6A#6B#4", false },
{ "MFT200L4<G#6A#6B#6O4C#6D#4O3G#6A#6B#6O4C#6D#1", false },
#define AP_NOTIFY_TONE_LOUD_ATTENTION_NEEDED 8
{ "MFT100L4>A#A#A#A#", false },
#define AP_NOTIFY_TONE_QUIET_ARMING_WARNING 9
@ -93,7 +95,8 @@ const AP_ToneAlarm::Tone AP_ToneAlarm::_tones[] { @@ -93,7 +95,8 @@ const AP_ToneAlarm::Tone AP_ToneAlarm::_tones[] {
#define AP_NOTIFY_TONE_QUIET_NOT_READY_OR_NOT_FINISHED 28
{ "MFT200L4<B#4A#6G#6", false },
#define AP_NOTIFY_TONE_STARTUP 29
{ "MFT240L8O4aO5dcO4aO5dcO4aO5dcL16dcdcdcdc", false },
// { "MFT240L8O4aO5dcO4aO5dcO4aO5dcL16dcdcdcdc", false },
{ "MFT240L8 O4L4geL2b", false }, // modify by @Brown
#define AP_NOTIFY_TONE_NO_SDCARD 30
{ "MNBGG", false },
#define AP_NOTIFY_TONE_EKF_ALERT 31

5
libraries/AP_Notify/ToshibaLED_I2C.cpp

@ -95,3 +95,8 @@ void ToshibaLED_I2C::_timer(void) @@ -95,3 +95,8 @@ void ToshibaLED_I2C::_timer(void)
_dev->transfer(val, sizeof(val), nullptr, 0);
}
void ToshibaLED_I2C::set_rgb_mode(uint8_t mode)
{
return;
}

1
libraries/AP_Notify/ToshibaLED_I2C.h

@ -26,6 +26,7 @@ public: @@ -26,6 +26,7 @@ public:
bool init(void) override;
protected:
bool hw_set_rgb(uint8_t r, uint8_t g, uint8_t b) override;
void set_rgb_mode(uint8_t mode) override;
private:
AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;

26
libraries/AP_Notify/UAVCAN_RGB_LED.cpp

@ -19,9 +19,7 @@ @@ -19,9 +19,7 @@
#if HAL_CANMANAGER_ENABLED
#include "UAVCAN_RGB_LED.h"
#include <AP_UAVCAN/AP_UAVCAN.h>
#include <AP_CANManager/AP_CANManager.h>
#define LED_OFF 0
@ -62,12 +60,34 @@ bool UAVCAN_RGB_LED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) @@ -62,12 +60,34 @@ bool UAVCAN_RGB_LED::hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue)
bool success = false;
uint8_t can_num_drivers = AP::can().get_num_drivers();
static uint8_t cnt;
static uint8_t l_mode,l_red,l_green,l_blue;
rgb = {red, green, blue};
cnt++;
if(l_mode != rgb_mode || l_red != rgb.r || l_green != rgb.g || l_blue != rgb.b || cnt > 50)
{
cnt =0;
_need_update = true;
l_mode = rgb_mode ;
l_red = rgb.r ;
l_green = rgb.g ;
l_blue = rgb.b;
}else{
return success;
}
for (uint8_t i = 0; i < can_num_drivers; i++) {
AP_UAVCAN *uavcan = AP_UAVCAN::get_uavcan(i);
if (uavcan != nullptr) {
success = uavcan->led_write(_led_index, red, green, blue) || success;
// success = uavcan->led_write(_led_index, red, green, blue) || success;
success = uavcan->set_zr_rgb_led(rgb_mode,red, green, blue) || success;//(_led_index, red, green, blue) || success
}
}
return success;
}
void UAVCAN_RGB_LED::set_rgb_mode(uint8_t mode)
{
rgb_mode = mode;
}
#endif

7
libraries/AP_Notify/UAVCAN_RGB_LED.h

@ -11,8 +11,13 @@ public: @@ -11,8 +11,13 @@ public:
protected:
virtual bool hw_set_rgb(uint8_t red, uint8_t green, uint8_t blue) override;
void set_rgb_mode(uint8_t mode) override;
private:
uint8_t _led_index;
uint8_t rgb_mode;
bool _need_update;
struct {
uint8_t r, g, b;
} rgb;
};

8
libraries/AP_Proximity/AP_Proximity.cpp

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
#include "AP_Proximity_SITL.h"
#include "AP_Proximity_AirSimSITL.h"
#include "AP_Proximity_Cygbot_D1.h"
#include "AP_Proximity_UAVCAN.h"
#include <AP_Logger/AP_Logger.h>
@ -345,6 +346,13 @@ void AP_Proximity::detect_instance(uint8_t instance) @@ -345,6 +346,13 @@ void AP_Proximity::detect_instance(uint8_t instance)
return;
}
break;
case Type::UAVCAN:
#if HAL_CANMANAGER_ENABLED
state[instance].instance = instance;
drivers[instance] = AP_Proximity_UAVCAN::probe(*this, state[instance]);
return;
#endif
break;
case Type::CYGBOT_D1:
#if AP_PROXIMITY_CYGBOT_ENABLED

1
libraries/AP_Proximity/AP_Proximity.h

@ -51,6 +51,7 @@ public: @@ -51,6 +51,7 @@ public:
TRTOWEREVO = 6,
SF40C = 7,
SF45B = 8,
UAVCAN = 9,
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL
SITL = 10,
AirSimSITL = 12,

250
libraries/AP_Proximity/AP_Proximity_UAVCAN.cpp

@ -0,0 +1,250 @@ @@ -0,0 +1,250 @@
#include <AP_HAL/AP_HAL.h>
#if HAL_CANMANAGER_ENABLED
#include <GCS_MAVLink/GCS.h>
#include "AP_Proximity_UAVCAN.h"
#include <AP_CANManager/AP_CANManager.h>
#include <AP_UAVCAN/AP_UAVCAN.h>
#include <zrzk/equipment/range_sensor/Proximity.hpp>
#define PRX_DEBUG 0
#if PRX_DEBUG
#include <GCS_MAVLink/GCS.h>
# define Prx_Debug(fmt, args ...) gcs().send_text(MAV_SEVERITY_INFO, "prx-%d: " fmt "", __LINE__, ## args)
#else
# define Prx_Debug(fmt, args ...)
#endif
extern const AP_HAL::HAL &hal;
#define debug_proximity_uavcan(level_debug, can_driver, fmt, args...) \
do \
{ \
if ((level_debug) <= AP::can().get_debug_level_driver(can_driver)) \
{ \
hal.console->printf(fmt, ##args); \
} \
} while (0)
HAL_Semaphore AP_Proximity_UAVCAN::_sem_registry;
UC_REGISTRY_BINDER(ProximityCb, zrzk::equipment::range_sensor::Proximity);
uint8_t AP_Proximity_UAVCAN::_node_id = 0;
AP_Proximity_UAVCAN* AP_Proximity_UAVCAN::_driver = nullptr;
AP_UAVCAN* AP_Proximity_UAVCAN::_ap_uavcan = nullptr;
AP_Proximity_UAVCAN::DetectedModules AP_Proximity_UAVCAN::_detected_modules[] = {0};
AP_Proximity_UAVCAN::AP_Proximity_UAVCAN(AP_Proximity &_frontend,
AP_Proximity::Proximity_State &_state) :
AP_Proximity_Backend(_frontend, _state)
{
_driver = this;
}
void AP_Proximity_UAVCAN::subscribe_msgs(AP_UAVCAN *ap_uavcan)
{
if (ap_uavcan == nullptr)
{
Prx_Debug("ap_uavcan:nullptr" );
return;
}
Prx_Debug("ap_uavcan:subscribe_msgs");
auto *node = ap_uavcan->get_node();
uavcan::Subscriber<zrzk::equipment::range_sensor::Proximity, ProximityCb> *proximity_listener;
proximity_listener = new uavcan::Subscriber<zrzk::equipment::range_sensor::Proximity, ProximityCb>(*node);
// Register method to handle incoming RangeFinder measurement
const int proximity_listener_res = proximity_listener->start(ProximityCb(ap_uavcan, &handle_proximity_data_trampoline));
if (proximity_listener_res < 0)
{
AP_HAL::panic("UAVCAN RangeFinder subscriber start problem\n\r");
return;
}
}
AP_Proximity_Backend *AP_Proximity_UAVCAN::probe(AP_Proximity &_frontend,
AP_Proximity::Proximity_State &_state)
{
WITH_SEMAPHORE(_sem_registry);
AP_Proximity_UAVCAN *backend = nullptr;
Prx_Debug("---------- AP_Proximity_UAVCAN ----------");
backend = new AP_Proximity_UAVCAN(_frontend, _state);
if (backend != nullptr)
{
Prx_Debug("backend:%d",(int)backend);
}else{
Prx_Debug("faild,backend");
}
Prx_Debug("---------- AP_Proximity_UAVCAN ----------\n");
return backend;
}
AP_Proximity_UAVCAN *AP_Proximity_UAVCAN::get_uavcan_backend(AP_UAVCAN *ap_uavcan,uint8_t node_id)
{
if (ap_uavcan == nullptr)
{
return nullptr;
}
Prx_Debug("get_uavcan:%d",node_id);
for (uint8_t i = 0; i < PROXIMITY_MAX_INSTANCES; i++)
{
if (_detected_modules[i].driver != nullptr &&
_detected_modules[i].ap_uavcan == ap_uavcan&&
_detected_modules[i].node_id == node_id)
{
return _detected_modules[i].driver;
}
}
bool detected = false;
for (uint8_t i = 0; i < PROXIMITY_MAX_INSTANCES; i++)
{
if (_detected_modules[i].ap_uavcan == ap_uavcan &&
_detected_modules[i].node_id == node_id)
{
// detected
detected = true;
break;
}
}
if (!detected)
{
for (uint8_t i = 0; i < PROXIMITY_MAX_INSTANCES; i++)
{
if (_detected_modules[i].ap_uavcan == nullptr)
{
_detected_modules[i].ap_uavcan = ap_uavcan;
_detected_modules[i].node_id = node_id;
break;
}
}
}
return nullptr;
}
float AP_Proximity_UAVCAN::distance_max() const
{
return 40.0f;
}
float AP_Proximity_UAVCAN::distance_min() const
{
return 0.20f;
}
void AP_Proximity_UAVCAN::update(void)
{
WITH_SEMAPHORE(_sem_proximity);
// update_sector_data(0, _interim_data.d1_cm); // d1
// update_sector_data(45, _interim_data.d2_cm); // d8
// update_sector_data(90, _interim_data.d3_cm); // d7
// update_sector_data(135, _interim_data.d4_cm); // d6
// update_sector_data(180, _interim_data.d5_cm); // d5
// update_sector_data(225, _interim_data.d6_cm); // d4
// update_sector_data(270, _interim_data.d7_cm); // d3
// update_sector_data(315, _interim_data.d8_cm); // d2
update_sector_data(0, _interim_data.d1_cm); // d1
update_sector_data(45, _interim_data.d2_cm); // d8
update_sector_data(315, _interim_data.d3_cm); // d7
if ((_last_distance_received_ms == 0) || (AP_HAL::millis() - _last_distance_received_ms > PROXIMITY_UAVCAN_TIMEOUT_MS))
{
set_status(AP_Proximity::Status::NoData);
// gcs().send_text(MAV_SEVERITY_INFO, "NoData\r\n");
}
else
{
set_status(AP_Proximity::Status::Good);
}
}
void AP_Proximity_UAVCAN::handle_proximity_data_trampoline(AP_UAVCAN *ap_uavcan, uint8_t node_id, const ProximityCb &cb)
{
if (_driver == nullptr) {
Prx_Debug("----nullptr : ap:%d,id:%d ----",(int)_ap_uavcan,_node_id);
return;
}
if (_ap_uavcan == nullptr) {
_ap_uavcan = ap_uavcan;
_node_id = node_id;
Prx_Debug("---- uavcan: ap:%d,id:%d ----",(int)_ap_uavcan,_node_id);
}
Prx_Debug("handle_proximity: ap:%d,id:%d ,%d,addr:%d",(int)_ap_uavcan,_node_id,cb.msg->d0,cb.msg->sensor_id);
if (_ap_uavcan == ap_uavcan && _node_id == node_id) {
WITH_SEMAPHORE(_sem_registry);
_driver->_interim_data.d1_cm = cb.msg->d0;
_driver->_interim_data.d2_cm = cb.msg->d45;
_driver->_interim_data.d3_cm = cb.msg->d90;
_driver->_interim_data.d4_cm = cb.msg->d135;
_driver->_interim_data.d5_cm = cb.msg->d180;
_driver->_interim_data.d6_cm = cb.msg->d225;
_driver->_interim_data.d7_cm = cb.msg->d270;
_driver->_interim_data.d8_cm = cb.msg->d315;
_driver->_last_distance_received_ms = AP_HAL::millis();
}
/*
AP_Proximity_UAVCAN *driver = get_uavcan_backend(ap_uavcan,node_id);
if (driver == nullptr)
{
return;
}
driver->handle_proximity_data(cb);
*/
}
void AP_Proximity_UAVCAN::handle_proximity_data(const ProximityCb &cb)
{
WITH_SEMAPHORE(_sem_proximity);
_interim_data.d1_cm = cb.msg->d0;
_interim_data.d2_cm = cb.msg->d45;
_interim_data.d3_cm = cb.msg->d90;
_interim_data.d4_cm = cb.msg->d135;
_interim_data.d5_cm = cb.msg->d180;
_interim_data.d6_cm = cb.msg->d225;
_interim_data.d7_cm = cb.msg->d270;
_interim_data.d8_cm = cb.msg->d315;
_last_distance_received_ms = AP_HAL::millis();
// _last_sample_time_ms = AP_HAL::millis();
}
void AP_Proximity_UAVCAN::update_sector_data(int16_t angle_deg, uint16_t distance_cm)
{
// Get location on 3-D boundary based on angle to the object
const AP_Proximity_Boundary_3D::Face face = boundary.get_face(angle_deg);
if ((distance_cm != 0xffff) && !ignore_reading(angle_deg, distance_cm * 0.01f, false)) {
boundary.set_face_attributes(face, angle_deg, ((float) distance_cm) / 100);
// update OA database
database_push(angle_deg, ((float) distance_cm) / 100);
} else {
boundary.reset_face(face);
}
_last_distance_received_ms = AP_HAL::millis();
/*
uint8_t sector;
if(convert_angle_to_sector(angle_deg,sector)){
_angle[sector] = angle_deg;
_distance[sector] = ((float)distance_cm) / 100;
_distance_valid[sector] = (_distance[sector] > distance_min() && _distance[sector] < distance_max());
update_boundary_for_sector(sector, true);
}
*/
}
#endif

72
libraries/AP_Proximity/AP_Proximity_UAVCAN.h

@ -0,0 +1,72 @@ @@ -0,0 +1,72 @@
#pragma once
#include "AP_Proximity_Backend.h"
#if HAL_CANMANAGER_ENABLED
#include <AP_UAVCAN/AP_UAVCAN.h>
class ProximityCb;
#define PROXIMITY_UAVCAN_TIMEOUT_MS 300
class AP_Proximity_UAVCAN : public AP_Proximity_Backend
{
public:
AP_Proximity_UAVCAN(AP_Proximity &_frontend, AP_Proximity::Proximity_State &_state);
void update(void) override;
// get maximum and minimum distances (in meters) of sensor
float distance_max() const override;
float distance_min() const override;
static void subscribe_msgs(AP_UAVCAN *ap_uavcan);
static AP_Proximity_Backend *probe(AP_Proximity &_frontend, AP_Proximity::Proximity_State &_state);
static void handle_proximity_data_trampoline(AP_UAVCAN *ap_uavcan, uint8_t node_id, const ProximityCb &cb);
//uint8_t _instance;
//AP_Proximity::Proximity_State _status;
private:
static AP_Proximity_UAVCAN *get_uavcan_backend(AP_UAVCAN *ap_uavcan,uint8_t node_id);
static AP_Proximity_UAVCAN* _driver;
// inline void register_sensor()
// {
// // instance = frontend.register_sensor();
// }
uint32_t _last_distance_received_ms;
void handle_proximity_data(const ProximityCb &cb);
struct Proximity_Data
{
uint16_t d1_cm;
uint16_t d2_cm;
uint16_t d3_cm;
uint16_t d4_cm;
uint16_t d5_cm;
uint16_t d6_cm;
uint16_t d7_cm;
uint16_t d8_cm;
} _interim_data;
void update_sector_data(int16_t angle_deg, uint16_t distance_cm);
uint16_t handle_data_valid(uint16_t data);
static struct DetectedModules
{
AP_UAVCAN *ap_uavcan;
uint8_t node_id;
AP_Proximity_UAVCAN *driver;
} _detected_modules[PROXIMITY_MAX_INSTANCES];
static HAL_Semaphore _sem_registry;
HAL_Semaphore _sem_proximity;
static AP_UAVCAN* _ap_uavcan;
static uint8_t _node_id;
};
#endif //HAL_WITH_UAVCAN

41
libraries/AP_UAVCAN/AP_UAVCAN.cpp

@ -61,6 +61,9 @@ @@ -61,6 +61,9 @@
#include <AP_Notify/AP_Notify.h>
#include "AP_UAVCAN_pool.h"
#include <zrzk/equipment/indication/ZrRGB.hpp>
#include <AP_Proximity/AP_Proximity_UAVCAN.h>
#define LED_DELAY_US 50000
extern const AP_HAL::HAL& hal;
@ -175,6 +178,8 @@ static uavcan::ServiceClient<uavcan::protocol::param::ExecuteOpcode, ParamExecut @@ -175,6 +178,8 @@ static uavcan::ServiceClient<uavcan::protocol::param::ExecuteOpcode, ParamExecut
static uavcan::protocol::param::ExecuteOpcode::Request param_save_req[HAL_MAX_CAN_PROTOCOL_DRIVERS];
static uavcan::Publisher<zrzk::equipment::indication::ZrRGB>* zr_rgb_led[HAL_MAX_CAN_PROTOCOL_DRIVERS];
// subscribers
// handler SafteyButton
@ -354,7 +359,8 @@ void AP_UAVCAN::init(uint8_t driver_index, bool enable_filters) @@ -354,7 +359,8 @@ void AP_UAVCAN::init(uint8_t driver_index, bool enable_filters)
#if HAL_EFI_ENABLED
AP_EFI_DroneCAN::subscribe_msgs(this);
#endif
AP_Proximity_UAVCAN::subscribe_msgs(this);
act_out_array[driver_index] = new uavcan::Publisher<uavcan::equipment::actuator::ArrayCommand>(*_node);
act_out_array[driver_index]->setTxTimeout(uavcan::MonotonicDuration::fromMSec(2));
act_out_array[driver_index]->setPriority(uavcan::TransferPriority::OneLowerThanHighest);
@ -390,6 +396,10 @@ void AP_UAVCAN::init(uint8_t driver_index, bool enable_filters) @@ -390,6 +396,10 @@ void AP_UAVCAN::init(uint8_t driver_index, bool enable_filters)
param_get_set_client[driver_index] = new uavcan::ServiceClient<uavcan::protocol::param::GetSet, ParamGetSetCb>(*_node, ParamGetSetCb(this, &AP_UAVCAN::handle_param_get_set_response));
param_execute_opcode_client[driver_index] = new uavcan::ServiceClient<uavcan::protocol::param::ExecuteOpcode, ParamExecuteOpcodeCb>(*_node, ParamExecuteOpcodeCb(this, &AP_UAVCAN::handle_param_save_response));
zr_rgb_led[driver_index] = new uavcan::Publisher<zrzk::equipment::indication::ZrRGB>(*_node);
zr_rgb_led[driver_index]->setTxTimeout(uavcan::MonotonicDuration::fromMSec(20));
zr_rgb_led[driver_index]->setPriority(uavcan::TransferPriority::OneHigherThanLowest);
safety_button_listener[driver_index] = new uavcan::Subscriber<ardupilot::indication::Button, ButtonCb>(*_node);
if (safety_button_listener[driver_index]) {
@ -490,6 +500,7 @@ void AP_UAVCAN::loop(void) @@ -490,6 +500,7 @@ void AP_UAVCAN::loop(void)
send_parameter_request();
send_parameter_save_request();
_dna_server->verify_nodes();
zr_rgb_led_send();
}
}
@ -1211,4 +1222,32 @@ bool AP_UAVCAN::prearm_check(char* fail_msg, uint8_t fail_msg_len) const @@ -1211,4 +1222,32 @@ bool AP_UAVCAN::prearm_check(char* fail_msg, uint8_t fail_msg_len) const
return _dna_server->prearm_check(fail_msg, fail_msg_len);
}
bool AP_UAVCAN::set_zr_rgb_led(uint8_t mode, uint8_t red, uint8_t green, uint8_t blue)
{
WITH_SEMAPHORE(_zr_rgb_led.sem);
_zr_rgb_led.mode = mode;
_zr_rgb_led.red = red;
_zr_rgb_led.green = green;
_zr_rgb_led.blue = blue;
_zr_rgb_led.need_send = true;
return true;
}
void AP_UAVCAN::zr_rgb_led_send()
{
if(!_zr_rgb_led.need_send)
{
return;
}
zrzk::equipment::indication::ZrRGB msg;
WITH_SEMAPHORE(_zr_rgb_led.sem);
msg.rgb_mode = _zr_rgb_led.mode;
msg.rgb_r =_zr_rgb_led. red;
msg.rgb_g = _zr_rgb_led.green;
msg.rgb_b = _zr_rgb_led.blue;
zr_rgb_led[_driver_index]->broadcast(msg);
_zr_rgb_led.need_send =false;
}
#endif // HAL_NUM_CAN_IFACES

13
libraries/AP_UAVCAN/AP_UAVCAN.h

@ -130,6 +130,8 @@ public: @@ -130,6 +130,8 @@ public:
// send RTCMStream packets
void send_RTCMStream(const uint8_t *data, uint32_t len);
bool set_zr_rgb_led(uint8_t mode, uint8_t red, uint8_t green, uint8_t blue);
// Send Reboot command
// Note: Do not call this from outside UAVCAN thread context,
@ -330,7 +332,15 @@ private: @@ -330,7 +332,15 @@ private:
// notify vehicle state
uint32_t _last_notify_state_ms;
struct
{
HAL_Semaphore sem;
uint8_t mode;
uint8_t red;
uint8_t green;
uint8_t blue;
bool need_send;
} _zr_rgb_led;
// incoming button handling
static void handle_button(AP_UAVCAN* ap_uavcan, uint8_t node_id, const ButtonCb &cb);
static void handle_traffic_report(AP_UAVCAN* ap_uavcan, uint8_t node_id, const TrafficReportCb &cb);
@ -340,6 +350,7 @@ private: @@ -340,6 +350,7 @@ private:
static void handle_debug(AP_UAVCAN* ap_uavcan, uint8_t node_id, const DebugCb &cb);
static void handle_param_get_set_response(AP_UAVCAN* ap_uavcan, uint8_t node_id, const ParamGetSetCb &cb);
static void handle_param_save_response(AP_UAVCAN* ap_uavcan, uint8_t node_id, const ParamExecuteOpcodeCb &cb);
void zr_rgb_led_send();
};
#endif // #if HAL_ENABLE_LIBUAVCAN_DRIVERS

4
libraries/AP_UAVCAN/dsdl/zrzk/equipment/indication/30100.ZrRGB.uavcan

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
uint8 rgb_mode # RGBLED mode
uint8 rgb_r # brightness of red light
uint8 rgb_g # brightness of red green
uint8 rgb_b # brightness of red blue

23
libraries/AP_UAVCAN/dsdl/zrzk/equipment/range_sensor/26110.Proximity.uavcan

@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
uint8 sensor_id
uint5 SENSOR_TYPE_UNDEFINED = 0
uint5 SENSOR_TYPE_SONAR = 1
uint5 SENSOR_TYPE_LIDAR = 2
uint5 SENSOR_TYPE_RADAR = 3
uint5 sensor_type
uint3 READING_TYPE_UNDEFINED = 0 # Range is unknown
uint3 READING_TYPE_VALID_RANGE = 1 # Range field contains valid distance
uint3 READING_TYPE_TOO_CLOSE = 2 # Range field contains min range for the sensor
uint3 READING_TYPE_TOO_FAR = 3 # Range field contains max range for the sensor
uint3 reading_type
uint16 d0 # Meters distance_cm
uint16 d45
uint16 d90
uint16 d135
uint16 d180
uint16 d225
uint16 d270
uint16 d315

2
modules/mavlink

@ -1 +1 @@ @@ -1 +1 @@
Subproject commit a2e2f0bd9ed3fc8dc04149d3292376c1e0451e27
Subproject commit 60c48d29c63875362cd3c4ee2ff7f08271c5a43f

3
periph_copy.sh

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
./waf AP_Periph
cp ./build/f103-GPS/bin/AP_Periph.hex /mnt/e/_00-inbox/periph-1.3.1.hex
cp ./build/f103-GPS/bin/AP_Periph_with_bl.hex /mnt/e/_00-inbox/periph-1.3_with_bl.hex
Loading…
Cancel
Save