|
Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
|
Go to the documentation of this file.
35 #include <netinet/in.h>
36 #include <arpa/inet.h>
38 #include <sys/socket.h>
39 #include <sys/types.h>
49 #include "generated/airframe.h"
50 #include "generated/flight_plan.h"
52 #ifndef NPS_CRRCSIM_HOST_IP
53 #define NPS_CRRCSIM_HOST_IP "127.0.0.1"
56 #ifndef NPS_CRRCSIM_HOST_PORT
57 #define NPS_CRRCSIM_HOST_PORT 9002
60 #ifndef NPS_CRRCSIM_ROLL_NEUTRAL
61 #define NPS_CRRCSIM_ROLL_NEUTRAL 0.
64 #ifndef NPS_CRRCSIM_PITCH_NEUTRAL
65 #define NPS_CRRCSIM_PITCH_NEUTRAL 0.
69 #define UDP_BLOCKING 0
70 #define UDP_NONBLOCKING 1
73 #define word unsigned short
74 #define byte unsigned char
77 #define IMU_PACKET_LENGTH 51
78 #define GPS_PACKET_LENGTH 86
79 #define AHRS_PACKET_LENGTH 93
80 #define FULL_PACKET_SIZE 93
86 #define INPUT_BUFFER_SIZE (3*FULL_PACKET_SIZE)
135 printf(
"Starting to connect to CRRCsim server.\n");
139 printf(
"Connection to CRRCsim failed\n");
142 printf(
"Connection to CRRCsim succed\n");
146 double zero[] = { 0., 0., 0. };
195 printf(
"invalid data packet...!\n");
201 double dir __attribute__((unused)))
206 double wind_east __attribute__((unused)),
207 double wind_down __attribute__((unused)))
212 int turbulence_severity __attribute__((unused)))
269 llh_nav0.
lat = RadOfDeg((
double)NAV_LAT0 / 1e7);
270 llh_nav0.
lon = RadOfDeg((
double)NAV_LON0 / 1e7);
272 llh_nav0.
alt = (NAV_ALT0 + NAV_MSL0) / 1000.;
284 #pragma message "Using magnetic field as defined in airframe file."
309 while (
c->length >= 4 && (
c->buf[
c->start] != (
byte)0x55 ||
c->buf[(
byte)(
c->start + 1)] != (
byte)0x55)) {
321 switch (
c->buf[(
byte)(
c->start + 2)]) {
338 if (packet_len > 0 &&
c->length < packet_len) {
341 if (packet_len > 0) {
343 word rcvchecksum = 0;
346 for (i = 2, ib =
c->start + (
byte)2; i < packet_len - 2; i++, ib++) {
349 rcvchecksum =
c->buf[ib++] << 8;
350 rcvchecksum = rcvchecksum |
c->buf[ib++];
352 if (rcvchecksum != sum) {
354 printf(
"checksum error\n");
358 if (packet_len > 0) {
359 for (i = 0; i < packet_len; i++) {
360 data_buffer[i] =
c->buf[
c->start];
375 #define LongOfBuf(_buf,_idx) (int32_t)(((uint32_t)_buf[_idx+3]<<24)|((uint32_t)_buf[_idx+2]<<16)|((uint32_t)_buf[_idx+1]<<8)|((uint32_t)_buf[_idx]))
377 #define UShortOfBuf(_buf,_idx) (uint16_t)(((uint16_t)_buf[_idx+1]<<8)|((uint16_t)_buf[_idx]))
379 #define ShortOfBuf(_buf,_idx) (int16_t)(((uint16_t)_buf[_idx]<<8)|((uint16_t)_buf[_idx+1]))
388 vel.
x = (double)
LongOfBuf(buffer, 3) * 1.0e-2;
389 vel.
y = (double)
LongOfBuf(buffer, 7) * 1.0e-2;
390 vel.
z = (double)
LongOfBuf(buffer, 11) * 1.0e-2;
425 #if NPS_CRRCSIM_DEBUG
426 printf(
"decode gps | pos %f %f %f | vel %f %f %f | time %f\n",
448 #if NPS_CRRCSIM_DEBUG
449 printf(
"decode ahrs %f %f %f\n",
491 #if NPS_CRRCSIM_DEBUG
492 printf(
"decode imu | accel %f %f %f | gyro %f %f %f\n",
504 #define MSG_NOSIGNAL SO_NOSIGPIPE
514 byte data[24] = {0,};
518 word roll = (
word)((65535 / 4) *
commands[NPS_CRRCSIM_COMMAND_ROLL] + (65536 / 2));
519 word pitch = (
word)((65535 / 4) *
commands[NPS_CRRCSIM_COMMAND_PITCH] + (65536 / 2));
523 cnt_cmd[2] = (
word)(65535 *
commands[NPS_CRRCSIM_COMMAND_THROTTLE]);
525 #if NPS_CRRCSIM_DEBUG
526 printf(
"send servo %f %f %f | %d %d %d | %d %d\n",
543 data[4] = (
byte)(cnt_cmd[0] >> 8);
544 data[5] = (
byte)cnt_cmd[0];
546 data[6] = (
byte)(cnt_cmd[1] >> 8);
547 data[7] = (
byte)cnt_cmd[1];
549 data[8] = (
byte)(cnt_cmd[2] >> 8);
550 data[9] = (
byte)cnt_cmd[2];
554 for (i = 4; i < 22; i++) { sum += data[i]; }
556 data[22] = (
byte)(sum >> 8);
557 data[23] = (
byte)sum;
561 send(io->
socket, (
char *)data, 24, MSG_NOSIGNAL);
VIC slots used for the LPC2148 define name e g gps UART1_VIC_SLOT e g modem SPI1_VIC_SLOT SPI1 in mcu_periph spi_arch c or spi_slave_hs_arch c(and some others not using the SPI peripheral yet..) I2C0_VIC_SLOT 8 mcu_periph/i2c_arch.c I2C1_VIC_SLOT 9 mcu_periph/i2c_arch.c USB_VIC_SLOT 10 usb
#define AHRS_PACKET_LENGTH
void ltp_def_from_ecef_d(struct LtpDef_d *def, struct EcefCoor_d *ecef)
byte data_buffer[FULL_PACKET_SIZE]
#define NPS_CRRCSIM_PITCH_NEUTRAL
double airspeed
equivalent airspeed in m/s
Paparazzi generic macros for geodetic calculations.
struct DoubleVect3 body_ecef_accel
acceleration in body frame, wrt ECEF frame
vector in Latitude, Longitude and Altitude
void double_quat_of_eulers(struct DoubleQuat *q, struct DoubleEulers *e)
void nps_fdm_set_wind(double speed, double dir)
void ecef_of_lla_d(struct EcefCoor_d *ecef, struct LlaCoor_d *lla)
double alt
in meters above WGS84 reference ellipsoid
struct NedCoor_d ltpprz_ecef_vel
velocity in ltppprz frame, wrt ECEF frame
static double double_vect3_norm(struct DoubleVect3 *v)
static void inputbuf_init(struct inputbuf *c)
struct DoubleVect3 body_accel
acceleration in body frame as measured by an accelerometer (incl.
byte buf[INPUT_BUFFER_SIZE]
static struct LtpDef_d ltpdef
struct LlaCoor_d lla_pos_pprz
Paparazzi floating point algebra.
static void open_udp(char *host, int port, int blocking)
struct DoubleQuat ltp_to_body_quat
struct NedCoor_d ltp_ecef_vel
velocity in LTP frame, wrt ECEF frame
void nps_fdm_set_wind_ned(double wind_north, double wind_east, double wind_down)
void ecef_of_ned_vect_d(struct EcefCoor_d *ecef, struct LtpDef_d *def, struct NedCoor_d *ned)
#define NPS_CRRCSIM_ROLL_NEUTRAL
struct DoubleRates body_ecef_rotvel
struct EcefCoor_d ecef_ecef_vel
velocity in ECEF frame, wrt ECEF frame
Paparazzi floating point math for geodetic calculations.
static int get_msg(struct _crrcsim *io, byte *data_buffer)
#define INPUT_BUFFER_SIZE
#define LongOfBuf(_buf, _idx)
static void decode_ahrspacket(struct NpsFdm *fdm, byte *buffer)
double total_pressure
total atmospheric pressure in Pascal
#define ShortOfBuf(_buf, _idx)
static struct _crrcsim crrcsim
vector in North East Down coordinates Units: meters
void nps_fdm_set_turbulence(double wind_speed, int turbulence_severity)
static const bool blocking[]
static void decode_gpspacket(struct NpsFdm *fdm, byte *buffer)
Paparazzi double-precision floating point math for geodetic calculations.
definition of the local (flat earth) coordinate system
static float pprz_isa_pressure_of_altitude(float altitude)
Get pressure in Pa from absolute altitude (using simplified equation).
static const ShellCommand commands[]
static void send_servo_cmd(struct _crrcsim *io, double *commands)
static void decode_imupacket(struct NpsFdm *fdm, byte *buffer)
struct DoubleEulers ltp_to_body_eulers
struct NedCoor_d ltpprz_pos
#define UShortOfBuf(_buf, _idx)
void ned_of_ecef_point_d(struct NedCoor_d *ned, struct LtpDef_d *def, struct EcefCoor_d *ecef)
vector in EarthCenteredEarthFixed coordinates
struct EcefCoor_d ecef_pos
double temperature
current temperature in degrees Celcius
void nps_fdm_init(double dt)
void ned_of_ecef_vect_d(struct NedCoor_d *ned, struct LtpDef_d *def, struct EcefCoor_d *ecef)
double pressure
current (static) atmospheric pressure in Pascal
static void init_ltp(void)
double dynamic_pressure
dynamic pressure in Pascal
Paparazzi generic algebra macros.
#define GPS_PACKET_LENGTH
static void read_into_buffer(struct _crrcsim *io)
#define NPS_CRRCSIM_HOST_IP
#define IMU_PACKET_LENGTH
void nps_fdm_run_step(bool launch, double *commands, int commands_nb)
struct LlaCoor_d lla
origin of local frame in LLA
#define VECT3_COPY(_a, _b)
struct DoubleRates body_inertial_rotvel
#define PPRZ_ISA_SEA_LEVEL_PRESSURE
ISA sea level standard atmospheric pressure in Pascal.
double pressure_sl
pressure at sea level in Pascal
Paparazzi atmospheric pressure conversion utilities.
#define NPS_CRRCSIM_HOST_PORT