4 static const StorageAccess
wp_storage(StorageManager::StorageMission
);
6 void Tracker::init_ardupilot()
10 AP_Notify::flags
.pre_arm_check
= true;
11 AP_Notify::flags
.pre_arm_gps_check
= true;
16 // init baro before we start the GCS, so that the CLI baro test works
17 barometer
.set_log_baro_bit(MASK_LOG_IMU
);
20 // setup telem slots with serial ports
22 // update_send so that if the first packet we receive happens to
23 // be an arm message we don't trigger an internal error when we
24 // try to initialise stream rates in the main loop.
28 AP::compass().set_log_bit(MASK_LOG_COMPASS
);
32 gps
.set_log_gps_bit(MASK_LOG_GPS
);
36 ahrs
.set_fly_forward(false);
38 ins
.init(scheduler
.get_loop_rate_hz());
41 barometer
.calibrate();
43 #if HAL_LOGGING_ENABLED
44 // initialise AP_Logger library
45 logger
.setVehicle_Startup_Writer(FUNCTOR_BIND(&tracker
, &Tracker::Log_Write_Vehicle_Startup_Messages
, void));
48 // initialise rc channels including setting mode
49 rc().convert_options(RC_Channel::AUX_FUNC::ARMDISARM_UNUSED
, RC_Channel::AUX_FUNC::ARMDISARM
);
55 // use given start positions - useful for indoor testing, and
56 // while waiting for GPS lock
57 // sanity check location
58 if (fabsf(g
.start_latitude
) <= 90.0f
&& fabsf(g
.start_longitude
) <= 180.0f
) {
59 current_loc
.lat
= g
.start_latitude
* 1.0e7f
;
60 current_loc
.lng
= g
.start_longitude
* 1.0e7f
;
62 gcs().send_text(MAV_SEVERITY_NOTICE
, "Ignoring invalid START_LATITUDE or START_LONGITUDE parameter");
65 // see if EEPROM has a default location as well
66 if (current_loc
.lat
== 0 && current_loc
.lng
== 0) {
67 get_home_eeprom(current_loc
);
70 hal
.scheduler
->delay(1000); // Why????
72 Mode
*newmode
= mode_from_mode_num((Mode::Number
)g
.initial_mode
.get());
73 if (newmode
== nullptr) {
74 newmode
= &mode_manual
;
76 set_mode(*newmode
, ModeReason::STARTUP
);
78 if (g
.startup_delay
> 0) {
79 // arm servos with trim value to allow them to start up (required
86 fetch HOME from EEPROM
88 bool Tracker::get_home_eeprom(Location
&loc
) const
90 // Find out proper location in memory by using the start_byte position + the index
91 // --------------------------------------------------------------------------------
92 if (g
.command_total
.get() == 0) {
98 int32_t(wp_storage
.read_uint32(5)),
99 int32_t(wp_storage
.read_uint32(9)),
100 int32_t(wp_storage
.read_uint32(1)),
101 Location::AltFrame::ABSOLUTE
107 bool Tracker::set_home_eeprom(const Location
&temp
)
109 wp_storage
.write_byte(0, 0);
110 wp_storage
.write_uint32(1, temp
.alt
);
111 wp_storage
.write_uint32(5, temp
.lat
);
112 wp_storage
.write_uint32(9, temp
.lng
);
114 // Now have a home location in EEPROM
115 g
.command_total
.set_and_save(1); // At most 1 entry for HOME
119 bool Tracker::set_home_to_current_location(bool lock
)
121 return set_home(AP::gps().location(), lock
);
124 bool Tracker::set_home(const Location
&temp
, bool lock
)
126 // check EKF origin has been set
128 if (ahrs
.get_origin(ekf_origin
)) {
129 if (!ahrs
.set_home(temp
)) {
134 if (!set_home_eeprom(temp
)) {
143 void Tracker::arm_servos()
145 hal
.util
->set_soft_armed(true);
146 #if HAL_LOGGING_ENABLED
147 logger
.set_vehicle_armed(true);
151 void Tracker::disarm_servos()
153 hal
.util
->set_soft_armed(false);
154 #if HAL_LOGGING_ENABLED
155 logger
.set_vehicle_armed(false);
160 setup servos to trim value after initialising
162 void Tracker::prepare_servos()
164 start_time_ms
= AP_HAL::millis();
165 SRV_Channels::set_output_limit(SRV_Channel::k_tracker_yaw
, SRV_Channel::Limit::TRIM
);
166 SRV_Channels::set_output_limit(SRV_Channel::k_tracker_pitch
, SRV_Channel::Limit::TRIM
);
167 SRV_Channels::calc_pwm();
168 SRV_Channels::output_ch_all();
171 void Tracker::set_mode(Mode
&newmode
, const ModeReason reason
)
173 control_mode_reason
= reason
;
175 if (mode
== &newmode
) {
176 // don't switch modes if we are already in the correct mode.
181 if (mode
->requires_armed_servos()) {
187 #if HAL_LOGGING_ENABLED
189 logger
.Write_Mode((uint8_t)mode
->number(), reason
);
191 gcs().send_message(MSG_HEARTBEAT
);
193 nav_status
.bearing
= ahrs
.yaw_sensor
* 0.01f
;
196 bool Tracker::set_mode(const uint8_t new_mode
, const ModeReason reason
)
198 Mode
*fred
= nullptr;
199 switch ((Mode::Number
)new_mode
) {
200 case Mode::Number::INITIALISING
:
202 case Mode::Number::AUTO
:
205 case Mode::Number::MANUAL
:
208 case Mode::Number::SCAN
:
211 case Mode::Number::SERVOTEST
:
212 fred
= &mode_servotest
;
214 case Mode::Number::STOP
:
217 case Mode::Number::GUIDED
:
221 if (fred
== nullptr) {
224 set_mode(*fred
, reason
);
228 #if HAL_LOGGING_ENABLED
230 should we log a message type now?
232 bool Tracker::should_log(uint32_t mask
)
234 if (!logger
.should_log(mask
)) {
241 #include <AP_AdvancedFailsafe/AP_AdvancedFailsafe.h>
242 #include <AP_Avoidance/AP_Avoidance.h>
243 #include <AP_ADSB/AP_ADSB.h>
245 #if AP_ADVANCEDFAILSAFE_ENABLED
246 // dummy method to avoid linking AFS
247 bool AP_AdvancedFailsafe::gcs_terminate(bool should_terminate
, const char *reason
) {return false;}
248 AP_AdvancedFailsafe
*AP::advancedfailsafe() { return nullptr; }
249 #endif // AP_ADVANCEDFAILSAFE_ENABLED
251 // dummy method to avoid linking AP_Avoidance
252 AP_Avoidance
*AP::ap_avoidance() { return nullptr; }