Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
actuators_ostrich.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) Fabien Bonneval
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
27 #include "mcu_periph/uart.h"
28 #include "generated/airframe.h"
29 
30 #define SPEED_NEUTRAL 500
31 #define SPEED_FACTOR 1.0
32 #define TURN_NEUTRAL 500
33 #define TURN_FACTOR 0.5
34 
35 #define SPEED_OF_CMD(_s) ((_s-SPEED_NEUTRAL)*SPEED_FACTOR)
36 #define TURN_OF_CMD(_w) ((_w-TURN_NEUTRAL)*TURN_FACTOR)
37 
39 
40 #define START_BYTE 0x7F
41 
46 } __attribute__((packed)) ;
47 
48 union rawData {
51 } __attribute__((packed)) ;
52 
53 struct SpeedMessage {
57  union rawData raw_data;
58 } __attribute__((packed)) ;
59 
60 union RawMessage {
63 } __attribute__((packed)) ;
64 
65 // uart periph
66 static struct uart_periph *ostrich_dev;
67 
69 {
70  return ((SPEED_OF_CMD(speed_cmd) + 3200.0) * 10.0);
71 }
72 
74 {
75  return ((TURN_OF_CMD(turn_cmd) + 500.0) * 50);
76 }
77 
78 static uint8_t compute_checksum(uint8_t bytes[], int len)
79 {
80  uint8_t checksum = 0;
81  for (int i = 0; i < len; i++) {
82  checksum += bytes[i];
83  }
84  return checksum;
85 }
86 
87 
89 {
90  ostrich_dev = &(ACTUATORS_OSTRICH_DEV);
94 }
95 
97 {
101 
102  union RawMessage raw_message;
103  raw_message.speed_message.start_byte = START_BYTE;
104  raw_message.speed_message.msg_type = 1;
105 
106  raw_message.speed_message.raw_data.data.vx = speed_msg;
107  raw_message.speed_message.raw_data.data.vy = speed_y_msg;
108  raw_message.speed_message.raw_data.data.vtheta = turn_msg;
109 
110  raw_message.speed_message.checksum = compute_checksum(raw_message.speed_message.raw_data.bytes, 6);
111 
112  uart_put_buffer(ostrich_dev, 0, raw_message.bytes, 9);
113 }
114 
115 
#define SPEED_OF_CMD(_s)
struct ActuatorsOstrich actuators_ostrich
struct SpeedMessage speed_message
#define START_BYTE
uint8_t bytes[6]
static uint16_t turn_cmd_to_msg(uint16_t turn_cmd)
void actuators_ostrich_init()
uint8_t bytes[9]
#define TURN_NEUTRAL
void actuators_ostrich_periodic()
#define TURN_OF_CMD(_w)
static uint16_t speed_cmd_to_msg(uint16_t speed_cmd)
struct SpeedMessagePayload data
#define SPEED_NEUTRAL
union rawData raw_data
static struct uart_periph * ostrich_dev
static uint8_t compute_checksum(uint8_t bytes[], int len)
uint16_t cmds[3]
commands
static uint8_t checksum
Definition: airspeed_uADC.c:61
void WEAK uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
Definition: uart.c:266
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
UART peripheral.
Definition: uart.h:72
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98