Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
nps_autopilot_rover.c
Go to the documentation of this file.
1 /*
2  *
3  * This file is part of paparazzi.
4  *
5  * paparazzi is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * paparazzi is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with paparazzi; see the file COPYING. If not, write to
17  * the Free Software Foundation, 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #include "nps_autopilot.h"
22 
23 #include "main_ap.h"
24 #include "nps_sensors.h"
25 #include "nps_radio_control.h"
26 #include "nps_electrical.h"
27 #include "nps_fdm.h"
28 
30 #include "modules/imu/imu.h"
31 #include "mcu_periph/sys_time.h"
32 #include "state.h"
33 #include "modules/ahrs/ahrs.h"
34 #include "modules/ins/ins.h"
35 #include "math/pprz_algebra.h"
36 
47 #include "modules/core/abi.h"
48 
49 #include "pprzlink/messages.h"
51 
52 // for datalink_time hack
55 
59 
60 #ifndef NPS_BYPASS_AHRS
61 #define NPS_BYPASS_AHRS FALSE
62 #endif
63 
64 #ifndef NPS_BYPASS_INS
65 #define NPS_BYPASS_INS FALSE
66 #endif
67 
68 #if INDI_RPM_FEEDBACK
69 #error "INDI_RPM_FEEDBACK can not be used in simulation!"
70 #endif
71 
72 void nps_autopilot_init(enum NpsRadioControlType type_rc, int num_rc_script, char *rc_dev)
73 {
75 
76  nps_radio_control_init(type_rc, num_rc_script, rc_dev);
78 
81 
82  modules_mcu_init();
83  main_ap_init();
84 
85 }
86 
88 {
90 }
91 
92 #include <stdio.h>
93 #include "modules/gps/gps.h"
94 
96 {
97 
99 
100 #if RADIO_CONTROL && !RADIO_CONTROL_TYPE_DATALINK
103  main_ap_event();
104  }
105 #endif
106 
109  main_ap_event();
110  }
111 
113  imu_feed_mag();
114  main_ap_event();
115  }
116 
118  uint32_t now_ts = get_sys_time_usec();
119  float pressure = (float) sensors.baro.value;
120  AbiSendMsgBARO_ABS(BARO_SIM_SENDER_ID, now_ts, pressure);
121  main_ap_event();
122  }
123 
125  AbiSendMsgTEMPERATURE(BARO_SIM_SENDER_ID, (float)sensors.temp.value);
126  main_ap_event();
127  }
128 
129 #if USE_AIRSPEED
131  stateSetAirspeed_f((float)sensors.airspeed.value);
132  AbiSendMsgAIRSPEED(AIRSPEED_NPS_ID, (float)sensors.airspeed.value);
133  main_ap_event();
134  }
135 #endif
136 
137 #if USE_SONAR
139  uint32_t now_ts = get_sys_time_usec();
140  float dist = (float) sensors.sonar.value;
141  if (dist >= 0.0) {
142  AbiSendMsgAGL(AGL_SONAR_NPS_ID, now_ts, dist);
143  }
144 
145 #ifdef SENSOR_SYNC_SEND_SONAR
146  uint16_t foo = 0;
147  DOWNLINK_SEND_SONAR(DefaultChannel, DefaultDevice, &foo, &dist);
148 #endif
149 
150  main_ap_event();
151  }
152 #endif
153 
154 #if USE_GPS
156  gps_feed_value();
157  main_ap_event();
158  }
159 #endif
160 
161  if (nps_bypass_ahrs) {
163  }
164 
165  if (nps_bypass_ins) {
167  }
168 
170 
171  /* feeding the fdm with raw low level commands */
172  for (uint8_t i = 0; i < NPS_COMMANDS_NB; i++) {
173  commands[i] = autopilot_get_motors_on() ? commands[i] : 0;
174  nps_autopilot.commands[i] = (double)commands[i] / MAX_PPRZ;
175  }
176 
177  PRINT_CONFIG_MSG("Using throttle, steering commands because rover's fdm don't have explicit actuators.")
178 }
179 
180 
182 {
183 
184  struct FloatQuat quat_f;
185  QUAT_COPY(quat_f, fdm.ltp_to_body_quat);
186  stateSetNedToBodyQuat_f(&quat_f);
187 
188  struct FloatRates rates_f;
189  RATES_COPY(rates_f, fdm.body_ecef_rotvel);
190  stateSetBodyRates_f(&rates_f);
191 
192 }
193 
195 {
196 
197  struct NedCoor_f ltp_pos;
198  VECT3_COPY(ltp_pos, fdm.ltpprz_pos);
199  stateSetPositionNed_f(&ltp_pos);
200 
201  struct NedCoor_f ltp_speed;
202  VECT3_COPY(ltp_speed, fdm.ltpprz_ecef_vel);
203  stateSetSpeedNed_f(&ltp_speed);
204 
205  struct NedCoor_f ltp_accel;
206  VECT3_COPY(ltp_accel, fdm.ltpprz_ecef_accel);
207  stateSetAccelNed_f(&ltp_accel);
208 
209  // Here we make sure that ENU states are recalculated
211 }
Main include for ABI (AirBorneInterface).
#define BARO_SIM_SENDER_ID
#define AGL_SONAR_NPS_ID
#define AIRSPEED_NPS_ID
Dispatcher to register actual AHRS implementations.
bool autopilot_get_motors_on(void)
get motors status
Definition: autopilot.c:295
#define sensors(...)
Definition: cc2500_compat.h:68
static void sys_tick_handler(void)
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
pprz_t commands[COMMANDS_NB]
Definition: commands.c:30
if(GpsFixValid() &&e_identification_started)
Device independent GPS code (interface)
void gps_feed_value(void)
Definition: gps_sim_nps.c:32
Roation quaternion.
angular rates
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:337
#define QUAT_COPY(_qo, _qi)
Definition: pprz_algebra.h:596
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:140
static void stateSetAccelNed_f(struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
Definition: state.h:1002
static void stateSetNedToBodyQuat_f(struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
Definition: state.h:1093
static void stateSetPositionNed_f(struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
Definition: state.h:598
void stateCalcPositionEnu_i(void)
Definition: state.c:199
static void stateSetBodyRates_f(struct FloatRates *body_rate)
Set vehicle body angular rate (float).
Definition: state.h:1181
static void stateSetSpeedNed_f(struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Definition: state.h:809
static void stateSetAirspeed_f(float airspeed)
Set airspeed (float).
Definition: state.h:1309
Inertial Measurement Unit interface.
void imu_feed_mag(void)
Definition: imu_nps.c:76
void imu_feed_gyro_accel(void)
Definition: imu_nps.c:65
Integrated Navigation System interface.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void main_ap_periodic(void)
Definition: main_ap.c:119
void main_ap_event(void)
Definition: main_ap.c:146
void main_ap_init(void)
Definition: main_ap.c:79
Autopilot main loop.
uint16_t foo
Definition: main_demo5.c:58
Hardware independent API for actuators (servos, motor controllers).
double commands[NPS_COMMANDS_NB]
Definition: nps_autopilot.h:49
#define NPS_COMMANDS_NB
Number of commands sent to the FDM of NPS.
Definition: nps_autopilot.h:44
struct NpsAutopilot nps_autopilot
#ifndef NPS_NO_MOTOR_MIXING #include "modules/actuators/motor_mixing.h"
void nps_autopilot_run_step(double time)
#define NPS_BYPASS_INS
void nps_autopilot_init(enum NpsRadioControlType type_rc, int num_rc_script, char *rc_dev)
bool nps_bypass_ahrs
bool nps_bypass_ins
void sim_overwrite_ins(void)
void nps_autopilot_run_systime_step(void)
void sim_overwrite_ahrs(void)
#define NPS_BYPASS_AHRS
void nps_electrical_init(void)
void nps_electrical_run_step(double time)
Electrical status (bat voltage) for NPS.
struct NedCoor_d ltpprz_ecef_vel
velocity in ltppprz frame, wrt ECEF frame
Definition: nps_fdm.h:79
struct NedCoor_d ltpprz_pos
Definition: nps_fdm.h:54
struct NedCoor_d ltpprz_ecef_accel
accel in ltppprz frame, wrt ECEF frame
Definition: nps_fdm.h:81
struct DoubleQuat ltp_to_body_quat
Definition: nps_fdm.h:91
struct DoubleRates body_ecef_rotvel
Definition: nps_fdm.h:97
struct NpsFdm fdm
Holds all necessary NPS FDM state information.
void nps_radio_control_init(enum NpsRadioControlType type, int num_script, char *js_dev)
bool nps_radio_control_available(double time)
NpsRadioControlType
bool nps_sensors_airspeed_available(void)
Definition: nps_sensors.c:85
bool nps_sensors_sonar_available(void)
Definition: nps_sensors.c:76
bool nps_sensors_mag_available(void)
Definition: nps_sensors.c:49
bool nps_sensors_gps_available(void)
Definition: nps_sensors.c:67
bool nps_sensors_baro_available(void)
Definition: nps_sensors.c:58
bool nps_sensors_gyro_available(void)
Definition: nps_sensors.c:40
bool nps_sensors_temperature_available(void)
Definition: nps_sensors.c:94
#define MAX_PPRZ
Definition: paparazzi.h:8
Paparazzi generic algebra macros.
vector in North East Down coordinates Units: meters
Generic interface for radio control modules.
void radio_control_feed(void)
Definition: ppm_arch.c:42
API to get/set the generic vehicle states.
#define TRUE
Definition: std.h:4
Architecture independent timing functions.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98