Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
nps_autopilot_rotorcraft.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Antoine Drouin <poinix@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
22 #include "nps_autopilot.h"
23 
25 #include "nps_sensors.h"
26 #include "nps_radio_control.h"
27 #include "nps_electrical.h"
28 #include "nps_fdm.h"
29 
31 #include "subsystems/imu.h"
32 #include "mcu_periph/sys_time.h"
33 #include "state.h"
34 #include "subsystems/ahrs.h"
35 #include "subsystems/ins.h"
36 #include "math/pprz_algebra.h"
37 
39 
40 #include "subsystems/abi.h"
41 
42 #include "pprzlink/messages.h"
44 
45 // for datalink_time hack
47 
51 
52 #ifndef NPS_BYPASS_AHRS
53 #define NPS_BYPASS_AHRS FALSE
54 #endif
55 
56 #ifndef NPS_BYPASS_INS
57 #define NPS_BYPASS_INS FALSE
58 #endif
59 
60 #if NPS_COMMANDS_NB != MOTOR_MIXING_NB_MOTOR
61 #error "NPS_COMMANDS_NB does not match MOTOR_MIXING_NB_MOTOR!"
62 #endif
63 
64 void nps_autopilot_init(enum NpsRadioControlType type_rc, int num_rc_script, char *rc_dev)
65 {
67 
68  nps_radio_control_init(type_rc, num_rc_script, rc_dev);
70 
73 
74  main_init();
75 
76 }
77 
79 {
81 }
82 
83 #include <stdio.h>
84 #include "subsystems/gps.h"
85 
86 void nps_autopilot_run_step(double time)
87 {
88 
90 
91 #if RADIO_CONTROL && !RADIO_CONTROL_TYPE_DATALINK
92  if (nps_radio_control_available(time)) {
93  radio_control_feed();
94  main_event();
95  }
96 #endif
97 
100  main_event();
101  }
102 
104  imu_feed_mag();
105  main_event();
106  }
107 
109  float pressure = (float) sensors.baro.value;
110  AbiSendMsgBARO_ABS(BARO_SIM_SENDER_ID, pressure);
111  main_event();
112  }
113 
115  AbiSendMsgTEMPERATURE(BARO_SIM_SENDER_ID, (float)sensors.temp.value);
116  }
117 
118 #if USE_AIRSPEED
121  }
122 #endif
123 
124 #if USE_SONAR
126  float dist = (float) sensors.sonar.value;
127  AbiSendMsgAGL(AGL_SONAR_NPS_ID, dist);
128 
129  uint16_t foo = 0;
130  DOWNLINK_SEND_SONAR(DefaultChannel, DefaultDevice, &foo, &dist);
131 
132  main_event();
133  }
134 #endif
135 
136 #if USE_GPS
138  gps_feed_value();
139  main_event();
140  }
141 #endif
142 
143  if (nps_bypass_ahrs) {
145  }
146 
147  if (nps_bypass_ins) {
149  }
150 
152 
153  /* scale final motor commands to 0-1 for feeding the fdm */
154  for (uint8_t i = 0; i < NPS_COMMANDS_NB; i++) {
155  autopilot.commands[i] = (double)motor_mixing.commands[i] / MAX_PPRZ;
156  }
157 }
158 
159 
161 {
162 
163  struct FloatQuat quat_f;
164  QUAT_COPY(quat_f, fdm.ltp_to_body_quat);
165  stateSetNedToBodyQuat_f(&quat_f);
166 
167  struct FloatRates rates_f;
168  RATES_COPY(rates_f, fdm.body_ecef_rotvel);
169  stateSetBodyRates_f(&rates_f);
170 
171 }
172 
174 {
175 
176  struct NedCoor_f ltp_pos;
177  VECT3_COPY(ltp_pos, fdm.ltpprz_pos);
178  stateSetPositionNed_f(&ltp_pos);
179 
180  struct NedCoor_f ltp_speed;
181  VECT3_COPY(ltp_speed, fdm.ltpprz_ecef_vel);
182  stateSetSpeedNed_f(&ltp_speed);
183 
184  struct NedCoor_f ltp_accel;
185  VECT3_COPY(ltp_accel, fdm.ltpprz_ecef_accel);
186  stateSetAccelNed_f(&ltp_accel);
187 
188 }
unsigned short uint16_t
Definition: types.h:16
#define NPS_BYPASS_INS
struct NedCoor_d ltpprz_ecef_accel
accel in ltppprz frame, wrt ECEF frame
Definition: nps_fdm.h:81
Dispatcher to register actual AHRS implementations.
struct NpsAutopilot autopilot
bool nps_sensors_gps_available(void)
Definition: nps_sensors.c:67
struct DoubleRates body_ecef_rotvel
Definition: nps_fdm.h:97
#define NPS_BYPASS_AHRS
struct NpsFdm fdm
Holds all necessary NPS FDM state information.
void nps_electrical_run_step(double time)
bool nps_sensors_mag_available(void)
Definition: nps_sensors.c:49
#define NPS_COMMANDS_NB
Number of commands sent to the FDM of NPS.
Definition: nps_autopilot.h:22
#define VECT3_COPY(_a, _b)
Definition: pprz_algebra.h:139
bool nps_sensors_baro_available(void)
Definition: nps_sensors.c:58
Main include for ABI (AirBorneInterface).
void sim_overwrite_ahrs(void)
double value
airspeed reading in meters/second
struct NpsSensorBaro baro
Definition: nps_sensors.h:19
static void stateSetNedToBodyQuat_f(struct FloatQuat *ned_to_body_quat)
Set vehicle body attitude from quaternion (float).
Definition: state.h:1075
bool nps_bypass_ahrs
NpsRadioControlType
Integrated Navigation System interface.
STATIC_INLINE void handle_periodic_tasks(void)
Definition: main.c:243
struct NpsSensorSonar sonar
Definition: nps_sensors.h:21
Rotorcraft main loop.
struct NedCoor_d ltpprz_pos
Definition: nps_fdm.h:54
Roation quaternion.
#define AGL_SONAR_NPS_ID
#define QUAT_COPY(_qo, _qi)
Definition: pprz_algebra.h:532
void nps_autopilot_run_systime_step(void)
static void stateSetSpeedNed_f(struct NedCoor_f *ned_speed)
Set ground speed in local NED coordinates (float).
Definition: state.h:803
#define TRUE
Definition: std.h:4
void imu_feed_mag(void)
Definition: imu_nps.c:53
static void sys_tick_handler(void)
void nps_autopilot_run_step(double time)
double value
temperature in degrees Celcius
vector in North East Down coordinates Units: meters
Architecture independent timing functions.
void sim_overwrite_ins(void)
void nps_electrical_init(void)
static void main_event(void)
Definition: uart_tunnel.c:85
Paparazzi generic algebra macros.
Device independent GPS code (interface)
void nps_radio_control_init(enum NpsRadioControlType type, int num_script, char *js_dev)
uint16_t foo
Definition: main_demo5.c:59
struct NpsSensors sensors
Definition: nps_sensors.c:6
double value
sonar reading in meters
Inertial Measurement Unit interface.
static void stateSetPositionNed_f(struct NedCoor_f *ned_pos)
Set position from local NED coordinates (float).
Definition: state.h:592
void gps_feed_value(void)
Definition: gps_sim_nps.c:31
void imu_feed_gyro_accel(void)
Definition: imu_nps.c:40
bool nps_bypass_ins
bool nps_sensors_temperature_available(void)
Definition: nps_sensors.c:94
#define BARO_SIM_SENDER_ID
unsigned char uint8_t
Definition: types.h:14
API to get/set the generic vehicle states.
bool nps_sensors_airspeed_available(void)
Definition: nps_sensors.c:85
static void main_init(void)
bool nps_radio_control_available(double time)
Electrical status (bat voltage) for NPS.
static void stateSetAirspeed_f(float airspeed)
Set airspeed (float).
Definition: state.h:1291
bool nps_sensors_gyro_available(void)
Definition: nps_sensors.c:40
double value
pressure in Pascal
struct MotorMixing motor_mixing
Definition: motor_mixing.c:94
struct NpsSensorAirspeed airspeed
Definition: nps_sensors.h:22
struct NedCoor_d ltpprz_ecef_vel
velocity in ltppprz frame, wrt ECEF frame
Definition: nps_fdm.h:79
#define RATES_COPY(_a, _b)
Definition: pprz_algebra.h:336
#define MAX_PPRZ
Definition: paparazzi.h:8
int32_t commands[MOTOR_MIXING_NB_MOTOR]
Definition: motor_mixing.h:37
Motor Mixing.
static void stateSetBodyRates_f(struct FloatRates *body_rate)
Set vehicle body angular rate (float).
Definition: state.h:1163
bool nps_sensors_sonar_available(void)
Definition: nps_sensors.c:76
static void stateSetAccelNed_f(struct NedCoor_f *ned_accel)
Set acceleration in NED coordinates (float).
Definition: state.h:984
struct DoubleQuat ltp_to_body_quat
Definition: nps_fdm.h:91
double commands[NPS_COMMANDS_NB]
Definition: nps_autopilot.h:28
angular rates
struct NpsSensorTemperature temp
Definition: nps_sensors.h:23
void nps_autopilot_init(enum NpsRadioControlType type_rc, int num_rc_script, char *rc_dev)