diff --git a/ArduCopter/Copter.h b/ArduCopter/Copter.h
index 62ef997c82..a095253540 100644
--- a/ArduCopter/Copter.h
+++ b/ArduCopter/Copter.h
@@ -1004,6 +1004,7 @@ private:
// mode.cpp
Mode *mode_from_mode_num(const Mode::Number mode);
void exit_mode(Mode *&old_flightmode, Mode *&new_flightmode);
+ bool disable_rc_in;// modify by @Brown
public:
void mavlink_delay_cb(); // GCS_Mavlink.cpp
@@ -1012,6 +1013,10 @@ public:
const char* get_sysid_board_id(void); // modify by @Brown
const char* get_sysid_board_name_and_id(void); // modify by @Binsir
const char* parse_sysid_board_name(void); // modify by @Binsir
+
+ bool get_disable_rc_in() const { // modify by @Brown
+ return disable_rc_in;
+ }
};
extern Copter copter;
diff --git a/ArduCopter/UserCode.cpp b/ArduCopter/UserCode.cpp
index 583ec8f5ec..6e3e6a23d3 100644
--- a/ArduCopter/UserCode.cpp
+++ b/ArduCopter/UserCode.cpp
@@ -83,18 +83,35 @@ void Copter::userhook_SuperSlowLoop()
{
// put your 1Hz code here
static bool before_fly = true;
+ static bool last_disable_ch = false;
+
if(motors->armed()){
before_fly = false;
relay.on(3);
- // if (control_mode == Mode::Number::AUTO || control_mode == Mode::Number::RTL || control_mode == Mode::Number::LAND){
- // rc().set_disable_ch();
- // }else{
- // rc().set_enable_ch();
- // }
+ if (control_mode == Mode::Number::AUTO || control_mode == Mode::Number::RTL || control_mode == Mode::Number::LAND){
+ if(abs(channel_roll->get_control_in())>750 || \
+ abs(channel_pitch->get_control_in())>750 || \
+ abs(channel_yaw->get_control_in())>750 || \
+ channel_throttle->get_control_in()<380 || \
+ channel_throttle->get_control_in()>590 ){
+ // rc().set_disable_ch();
+ disable_rc_in = true;
+ if(last_disable_ch != disable_rc_in){
+ gcs().send_text(MAV_SEVERITY_INFO,"NOTICE: 注意遥控通道是否在中位");
+ }
+ }else{
+ disable_rc_in = false;
+ // rc().set_enable_ch();
+ }
+ }else{
+ // rc().set_enable_ch();
+ disable_rc_in = false;
+ }
}else{
relay.off(3);
// rc().set_enable_ch();
+ disable_rc_in = false;
updownStatus =UpDown_TakeOffStart;
mavlink_zr_flying_status_t zr_flying_status_t;
zr_flying_status_t.updown_status = updownStatus;
@@ -112,6 +129,9 @@ void Copter::userhook_SuperSlowLoop()
}
cacl_volt_pst = 100 - cnt;
battery.reset_remaining(1, cacl_volt_pst);
+ }
+ if(last_disable_ch != disable_rc_in){
+ last_disable_ch = disable_rc_in;
}
}
diff --git a/ArduCopter/mode.cpp b/ArduCopter/mode.cpp
index 32df8b98e4..4c19a76584 100644
--- a/ArduCopter/mode.cpp
+++ b/ArduCopter/mode.cpp
@@ -192,6 +192,15 @@ bool Copter::set_mode(Mode::Number mode, ModeReason reason)
return true;
}
+ if(get_disable_rc_in() && \
+ reason == ModeReason::RC_COMMAND ){
+ if(mode != Mode::Number::RTL){
+ gcs().send_text(MAV_SEVERITY_WARNING,"切换模式失败,遥控器通道错误");
+ AP::logger().Write_Error(LogErrorSubsystem::FLIGHT_MODE, LogErrorCode(mode));
+ return false;
+ }
+ }
+
Mode *new_flightmode = mode_from_mode_num((Mode::Number)mode);
if (new_flightmode == nullptr) {
gcs().send_text(MAV_SEVERITY_WARNING,"没有这个模式");//No such mode
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/README.md b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/README.md
new file mode 100644
index 0000000000..4f5a2eb5d4
--- /dev/null
+++ b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/README.md
@@ -0,0 +1,393 @@
+# Pixhawk4 Flight Controller
+
+The Pixhawk4 flight controller is sold by [Holybro](http://www.holybro.com/product/pixhawk-4)
+
+## Features
+
+ - STM32F765 microcontroller
+ - Two IMUs: ICM20689 and BMI055
+ - MS5611 SPI barometer
+ - builtin I2C IST8310 magnetometer
+ - microSD card slot
+ - 6 UARTs plus USB
+ - 14 PWM outputs
+ - Four I2C and two CAN ports
+ - External Buzzer
+ - external safety Switch
+ - voltage monitoring for servo rail and Vcc
+ - two dedicated power input ports for external power bricks
+
+## Pinout
+
+![Pixhawk4 Board](pixhawk4-pinout.jpg "Pixhawk4")
+
+## UART Mapping
+
+ - SERIAL0 -> USB
+ - SERIAL1 -> UART2 (Telem1)
+ - SERIAL2 -> UART3 (Telem2)
+ - SERIAL3 -> UART1 (GPS)
+ - SERIAL4 -> UART4 (GPS2)
+ - SERIAL5 -> UART6 (spare)
+ - SERIAL6 -> UART7 (spare, debug)
+
+The Telem1 and Telem2 ports have RTS/CTS pins, the other UARTs do not
+have RTS/CTS.
+
+The UART7 connector is labelled debug, but is available as a general
+purpose UART with ArduPilot.
+
+### TELEM1, TELEM2 ports
+
+
+
+
+ Pin |
+ Signal |
+ Volt |
+
+
+ 1 (red) |
+ VCC |
+ +5V |
+
+
+ 2 (blk) |
+ TX (OUT) |
+ +3.3V |
+
+
+ 3 (blk) |
+ RX (IN) |
+ +3.3V |
+
+
+ 4 (blk) |
+ CTS |
+ +3.3V |
+
+
+ 5 (blk) |
+ RTS |
+ +3.3V |
+
+
+ 6 (blk) |
+ GND |
+ GND |
+
+
+
+
+
+### GPS port
+
+
+
+
+ Pin |
+ Signal |
+ Volt |
+
+
+ 1 (red) |
+ VCC |
+ +5V |
+
+
+ 2 (blk) |
+ SERIAL3 TX (OUT) |
+ +3.3V |
+
+
+ 3 (blk) |
+ SERIAL3 RX (IN) |
+ +3.3V |
+
+
+ 4 (blk) |
+ SCL |
+ +3.3 (pullups) |
+
+
+ 5 (blk) |
+ SDA |
+ +3.3 (pullups) |
+
+
+ 6 (blk) |
+ SafetyButton |
+ +3.3V |
+
+
+ 7 (blk) |
+ SafetyLED |
+ +3.3V |
+
+
+ 8 (blk) |
+ VDD 3.3 (OUT) |
+ +3.3V |
+
+
+ 9 (blk) |
+ Buzzer |
+ +3.3V |
+
+
+ 10 (blk) |
+ GND |
+ GND |
+
+
+
+
+## RC Input
+
+RC input is configured on the port marked DSM/SBUS RC. This connector
+supports all RC protocols. Two cables are available for this port. To
+use software binding of Spektrum satellite receivers you need to use
+the Spektrum satellite cable.
+
+## PWM Output
+
+The Pixhawk4 supports up to 16 PWM outputs. First first 8 outputs (labelled
+"MAIN") are controlled by a dedicated STM32F100 IO controller. These 8
+outputs support all PWM output formats, but not DShot.
+
+The remaining 8 outputs (labelled AUX1 to AUX8) are the "auxillary"
+outputs. These are directly attached to the STM32F765 and support all
+PWM protocols. The first 6 of the auxillary PWM outputs support DShot.
+
+The 8 main PWM outputs are in 3 groups:
+
+ - PWM 1 and 2 in group1
+ - PWM 3 and 4 in group2
+ - PWM 5, 6, 7 and 8 in group3
+
+The 8 auxillary PWM outputs are in 2 groups:
+
+ - PWM 1, 2, 3 and 4 in group1
+ - PWM 5 and 6 in group2
+ - PWM 7 and 8 in group3
+
+Channels within the same group need to use the same output rate. If
+any channel in a group uses DShot then all channels in the group need
+to use DShot.
+
+## Battery Monitoring
+
+The board has two dedicated power monitor ports on 6 pin
+connectors. The correct battery setting parameters are dependent on
+the type of power brick which is connected.
+
+## Compass
+
+The Pixhawk4 has a builtin IST8310 compass. Due to potential
+interference the board is usually used with an external I2C compass as
+part of a GPS/Compass combination.
+
+## GPIOs
+
+The 6 PWM ports can be used as GPIOs (relays, buttons, RPM etc). To
+use them you need to limit the number of these pins that is used for
+PWM by setting the BRD_PWM_COUNT to a number less than 6. For example
+if you set BRD_PWM_COUNT to 4 then PWM5 and PWM6 will be available for
+use as GPIOs.
+
+The numbering of the GPIOs for PIN variables in ArduPilot is:
+
+ - AUX1 50
+ - AUX2 51
+ - AUX3 52
+ - AUX4 53
+ - AUX5 54
+ - AUX6 55
+
+## Analog inputs
+
+The Pixhawk4 has 7 analog inputs
+
+ - ADC Pin0 -> Battery Voltage
+ - ADC Pin1 -> Battery Current Sensor
+ - ADC Pin2 -> Battery Voltage 2
+ - ADC Pin3 -> Battery Current Sensor 2
+ - ADC Pin4 -> ADC port pin 2
+ - ADC Pin14 -> ADC port pin 3
+ - ADC Pin10 -> ADC 5V Sense
+ - ADC Pin11 -> ADC 3.3V Sense
+ - ADC Pin103 -> RSSI voltage monitoring
+
+## I2C Buses
+
+ - the internal I2C port is bus 0 in ArduPilot (I2C3 in hardware)
+ - the port labelled I2CA is bus 3 in ArduPilot (I2C4 in hardware)
+ - the port labelled I2CB is bus 2 in ArduPilot (I2c2 in hardware)
+ - the port labelled GPS is bus 1 in ArduPilot (I2c1 in hardware)
+
+### Pinout for I2CA
+
+
+
+
+ Pin |
+ Signal |
+ Volt |
+
+
+ 1 (red) |
+ VCC |
+ +5V |
+
+
+ 2 (blk) |
+ SCL |
+ +3.3 (pullups) |
+
+
+ 3 (blk) |
+ SDA |
+ +3.3 (pullups) |
+
+
+ 4 (blk) |
+ GND |
+ GND |
+
+
+
+
+### Pinout for I2CB+UART
+
+
+
+
+ Pin |
+ Signal |
+ Volt |
+
+
+ 1 (red) |
+ VCC |
+ +5V |
+
+
+ 2 (blk) |
+ SERIAL4 TX (OUT) |
+ +3.3V |
+
+
+ 3 (blk) |
+ SERIAL4 RX (IN) |
+ +3.3V |
+
+
+ 4 (blk) |
+ SCL |
+ +3.3 (pullups) |
+
+
+ 5 (blk) |
+ SDA |
+ +3.3 (pullups) |
+
+
+ 6 (blk) |
+ GND |
+ GND |
+
+
+
+
+## CAN
+
+The Pixhawk4 has two independent CAN buses, with the following pinouts.
+
+### CAN1&2
+
+
+
+
+ Pin |
+ Signal |
+ Volt |
+
+
+ 1 (red) |
+ VCC |
+ +5V |
+
+
+ 2 (blk) |
+ CAN_H |
+ +12V |
+
+
+ 3 (blk) |
+ CAN_L |
+ +12V |
+
+
+ 4 (blk) |
+ GND |
+ GND |
+
+
+
+
+## Debug
+
+The Pixhawk4 supports SWD debugging on the debug port
+
+
+
+
+ Pin |
+ Signal |
+ Volt |
+
+
+ 1 (red) |
+ FMU VDD 3.3 |
+ +3.3V |
+
+
+ 2 (blk) |
+ UART TX Debug (OUT) |
+ +3.3V |
+
+
+ 3 (blk) |
+ UART RX Debug (IN) |
+ +3.3V |
+
+
+ 4 (blk) |
+ SWDIO |
+ +3.3V |
+
+
+ 5 (blk) |
+ SWCLK |
+ +3.3V |
+
+
+ 6 (blk) |
+ GND |
+ GND |
+
+
+
+
+
+## Loading Firmware
+
+The board comes pre-installed with an ArduPilot compatible bootloader,
+allowing the loading of *.apj firmware files with any ArduPilot
+compatible ground station.
+
+## Acknowledgements
+
+Thanks to
+[PX4](https://docs.px4.io/en/flight_controller/pixhawk4.html) for
+images used under the [CC-BY 4.0 license](https://creativecommons.org/licenses/by/4.0/)
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/defaults.parm b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/defaults.parm
new file mode 100644
index 0000000000..ccd4e2f888
--- /dev/null
+++ b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/defaults.parm
@@ -0,0 +1,4 @@
+
+# Pixhawk4 does not have hw flow control on radios
+BRD_SER1_RTSCTS 0
+BRD_SER2_RTSCTS 0
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/hwdef-bl.dat b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/hwdef-bl.dat
new file mode 100644
index 0000000000..8f84484e43
--- /dev/null
+++ b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/hwdef-bl.dat
@@ -0,0 +1,4 @@
+# hw definition file for processing by chibios_hwdef.py
+# for Pixhawk4 bootloader
+
+include ../fmuv5/hwdef-bl.dat
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/hwdef.dat b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/hwdef.dat
new file mode 100644
index 0000000000..910bcac2fe
--- /dev/null
+++ b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/hwdef.dat
@@ -0,0 +1,11 @@
+# hw definition file for processing by chibios_hwdef.py
+# for Holybro Pixhawk4 hardware.
+
+include ../fmuv5/hwdef.dat
+
+# setup for supplied power brick
+undef HAL_BATT_VOLT_SCALE
+define HAL_BATT_VOLT_SCALE 18.182
+undef HAL_BATT_CURR_SCALE
+define HAL_BATT_CURR_SCALE 36.364
+
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/pixhawk4-pinout.jpg b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/pixhawk4-pinout.jpg
new file mode 100644
index 0000000000..bebe219ed2
Binary files /dev/null and b/libraries/AP_HAL_ChibiOS/hwdef/zr-v4/pixhawk4-pinout.jpg differ
diff --git a/libraries/RC_Channel/RC_Channel.h b/libraries/RC_Channel/RC_Channel.h
index b9c63d515b..e6029cd9da 100644
--- a/libraries/RC_Channel/RC_Channel.h
+++ b/libraries/RC_Channel/RC_Channel.h
@@ -347,12 +347,12 @@ public:
return (_enable_ch == (num+1) );
}
- // void set_disable_ch() {
- // _options = uint32_t(Option::IGNORE_CTRLCHAN);
- // }
- // void set_enable_ch() {
- // _options = 0;
- // }
+ void set_disable_ch() {
+ _options = uint32_t(Option::IGNORE_CTRLCHAN);
+ }
+ void set_enable_ch() {
+ _options = 0;
+ }
float override_timeout_ms() const {
return _override_timeout.get() * 1e3f;
diff --git a/zr_version b/version_zr.txt
similarity index 100%
rename from zr_version
rename to version_zr.txt
diff --git a/zr-v4.sh b/zr-v4.sh
new file mode 100755
index 0000000000..d19b47f6cb
--- /dev/null
+++ b/zr-v4.sh
@@ -0,0 +1,2 @@
+./waf configure --board zr-v4
+./waf --targets bin/arducopter --upload