Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
mag_pitot_uart.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) C. De Wagter
3  * Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
4  *
5  * This file is part of paparazzi
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
28 
29 #include "pprzlink/pprz_transport.h"
30 #include "pprzlink/intermcu_msg.h"
31 #include "mcu_periph/uart.h"
32 #include "modules/core/abi.h"
33 #include "modules/imu/imu.h"
34 #include "state.h"
35 
36 /* Main magneto structure */
37 static struct mag_pitot_t mag_pitot = {
38  .device = (&((MAG_PITOT_PORT).device)),
39  .msg_available = false
40 };
41 static uint8_t mp_msg_buf[128] __attribute__((aligned));
42 
43 /* Initialize the magneto and pitot */
45  // Initialize transport protocol
46  pprz_transport_init(&mag_pitot.transport);
47 
48  // Set the Imu to Magneto rotation
49  struct FloatEulers imu_to_mag_eulers =
51  orientationSetEulers_f(&mag_pitot.imu_to_mag, &imu_to_mag_eulers);
52 }
53 
54 /* Parse the InterMCU message */
55 static inline void mag_pitot_parse_msg(void)
56 {
57  uint32_t now_ts = get_sys_time_usec();
58 
59  /* Parse the mag-pitot message */
60  uint8_t msg_id = pprzlink_get_msg_id(mp_msg_buf);
61 
62 #if PPRZLINK_DEFAULT_VER == 2
63  // Check that the message is really a intermcu message
64  if (pprzlink_get_msg_class_id(mp_msg_buf) == DL_intermcu_CLASS_ID) {
65 #endif
66  switch (msg_id) {
67  /* Got a magneto message */
68  case DL_IMCU_REMOTE_MAG: {
69  struct Int32Vect3 raw_mag, mag;
70 
71  // Read the raw magneto information
72  raw_mag.x = DL_IMCU_REMOTE_MAG_mag_x(mp_msg_buf);
73  raw_mag.y = DL_IMCU_REMOTE_MAG_mag_y(mp_msg_buf);
74  raw_mag.z = DL_IMCU_REMOTE_MAG_mag_z(mp_msg_buf);
75 
76  // Rotate the magneto
77  struct Int32RMat *imu_to_mag_rmat = orientationGetRMat_i(&mag_pitot.imu_to_mag);
78  int32_rmat_vmult(&mag, imu_to_mag_rmat, &raw_mag);
79 
80  // Send and set the magneto IMU data
81  AbiSendMsgIMU_MAG_RAW(IMU_MAG_PITOT_ID, now_ts, &mag);
82  break;
83  }
84 
85  /* Got a barometer message */
86  case DL_IMCU_REMOTE_BARO: {
87  float pitot_stat = DL_IMCU_REMOTE_BARO_pitot_stat(mp_msg_buf);
88  float pitot_temp = DL_IMCU_REMOTE_BARO_pitot_temp(mp_msg_buf);
89 
90  AbiSendMsgBARO_ABS(IMU_MAG_PITOT_ID, now_ts, pitot_stat);
91  AbiSendMsgTEMPERATURE(IMU_MAG_PITOT_ID, pitot_temp);
92  break;
93  }
94 
95  /* Got an airspeed message */
96  case DL_IMCU_REMOTE_AIRSPEED: {
97  // Should be updated to differential pressure
98  float pitot_ias = DL_IMCU_REMOTE_AIRSPEED_pitot_IAS(mp_msg_buf);
99  AbiSendMsgAIRSPEED(IMU_MAG_PITOT_ID, pitot_ias);
100  break;
101  }
102 
103  default:
104  break;
105  }
106 #if PPRZLINK_DEFAULT_VER == 2
107  }
108 #endif
109 }
110 
111 /* We need to wait for incomming messages */
113  // Check if we got some message from the Magneto or Pitot
115 
116  // If we have a message we should parse it
117  if (mag_pitot.msg_available) {
119  mag_pitot.msg_available = false;
120  }
121 }
122 
123 
Main include for ABI (AirBorneInterface).
#define IMU_MAG_PITOT_ID
uint32_t get_sys_time_usec(void)
Get the time in microseconds since startup.
Definition: sys_time_arch.c:71
euler angles
void int32_rmat_vmult(struct Int32Vect3 *vb, struct Int32RMat *m_a2b, struct Int32Vect3 *va)
rotate 3D vector by rotation matrix.
rotation matrix
static struct Int32RMat * orientationGetRMat_i(struct OrientationReps *orientation)
Get vehicle body attitude rotation matrix (int).
static void orientationSetEulers_f(struct OrientationReps *orientation, struct FloatEulers *eulers)
Set vehicle body attitude from euler angles (float).
Inertial Measurement Unit interface.
void mag_pitot_init()
static void mag_pitot_parse_msg(void)
static uint8_t mp_msg_buf[128]
The message buffer for the Magneto and pitot.
static struct mag_pitot_t mag_pitot
void mag_pitot_event()
bool msg_available
If we received a message.
struct link_device * device
The device which is uses for communication.
struct pprz_transport transport
The transport layer (PPRZ)
struct OrientationReps imu_to_mag
IMU to magneto translation.
#define IMU_TO_MAG_THETA
#define IMU_TO_MAG_PSI
#define IMU_TO_MAG_PHI
API to get/set the generic vehicle states.
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
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