Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 {
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 
struct SpeedMessage speed_message
#define TURN_OF_CMD(_w)
unsigned short uint16_t
Definition: types.h:16
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
static struct uart_periph * ostrich_dev
#define SPEED_NEUTRAL
static uint16_t turn_cmd_to_msg(uint16_t turn_cmd)
void uart_put_buffer(struct uart_periph *p, long fd, const uint8_t *data, uint16_t len)
Uart transmit buffer implementation.
Definition: uart_arch.c:1021
uint8_t bytes[6]
static uint8_t checksum
Definition: airspeed_uADC.c:60
static uint8_t compute_checksum(uint8_t bytes[], int len)
void actuators_ostrich_periodic()
#define TURN_NEUTRAL
UART peripheral.
Definition: uart.h:70
unsigned char uint8_t
Definition: types.h:14
#define SPEED_OF_CMD(_s)
union rawData raw_data
static uint16_t speed_cmd_to_msg(uint16_t speed_cmd)
uint8_t bytes[9]
void actuators_ostrich_init()
struct SpeedMessagePayload data
uint16_t cmds[3]
commands
struct ActuatorsOstrich actuators_ostrich
#define START_BYTE