Paparazzi UAS
v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
Main Page
Related Pages
Modules
Data Structures
Data Structures
Data Structure Index
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
e
f
g
h
i
j
m
n
p
r
s
t
u
v
w
Enumerations
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
z
Enumerator
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
x
y
z
Macros
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
•
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
*/
26
#include "
modules/actuators/actuators_ostrich.h
"
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
38
struct
ActuatorsOstrich
actuators_ostrich
;
39
40
#define START_BYTE 0x7F
41
42
struct
SpeedMessagePayload
{
43
uint16_t
vx
;
44
uint16_t
vy
;
45
uint16_t
vtheta
;
46
} __attribute__((packed)) ;
47
48
union
rawData
{
49
struct
SpeedMessagePayload
data
;
50
uint8_t
bytes
[6];
51
} __attribute__((packed)) ;
52
53
struct
SpeedMessage
{
54
uint8_t
start_byte
;
55
uint8_t
msg_type
;
56
uint8_t
checksum
;
57
union
rawData
raw_data
;
58
} __attribute__((packed)) ;
59
60
union
RawMessage
{
61
struct
SpeedMessage
speed_message
;
62
uint8_t
bytes
[9];
63
} __attribute__((packed)) ;
64
65
// uart periph
66
static
struct
uart_periph
*
ostrich_dev
;
67
68
static
uint16_t
speed_cmd_to_msg
(
uint16_t
speed_cmd)
69
{
70
return
((
SPEED_OF_CMD
(speed_cmd) + 3200.0) * 10.0);
71
}
72
73
static
uint16_t
turn_cmd_to_msg
(
uint16_t
turn_cmd)
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
88
void
actuators_ostrich_init
()
89
{
90
ostrich_dev
= &(ACTUATORS_OSTRICH_DEV);
91
actuators_ostrich
.
cmds
[0] =
SPEED_NEUTRAL
;
92
actuators_ostrich
.
cmds
[1] =
SPEED_NEUTRAL
;
93
actuators_ostrich
.
cmds
[2] =
TURN_NEUTRAL
;
94
}
95
96
void
actuators_ostrich_periodic
()
97
{
98
uint16_t
speed_msg =
speed_cmd_to_msg
(
actuators_ostrich
.
cmds
[0]);
99
uint16_t
speed_y_msg =
speed_cmd_to_msg
(
actuators_ostrich
.
cmds
[1]);
100
uint16_t
turn_msg =
turn_cmd_to_msg
(
actuators_ostrich
.
cmds
[2]);
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
ActuatorsOstrich
Definition:
actuators_ostrich.h:32
actuators_ostrich_periodic
void actuators_ostrich_periodic()
Definition:
actuators_ostrich.c:96
SpeedMessage::start_byte
uint8_t start_byte
Definition:
actuators_ostrich.c:54
SpeedMessagePayload::vtheta
uint16_t vtheta
Definition:
actuators_ostrich.c:45
TURN_NEUTRAL
#define TURN_NEUTRAL
Definition:
actuators_ostrich.c:32
uint16_t
unsigned short uint16_t
Definition:
types.h:16
SpeedMessage
Definition:
actuators_ostrich.c:53
compute_checksum
static uint8_t compute_checksum(uint8_t bytes[], int len)
Definition:
actuators_ostrich.c:78
actuators_ostrich.h
RawMessage::bytes
uint8_t bytes[9]
Definition:
actuators_ostrich.c:62
SPEED_OF_CMD
#define SPEED_OF_CMD(_s)
Definition:
actuators_ostrich.c:35
SpeedMessage::msg_type
uint8_t msg_type
Definition:
actuators_ostrich.c:55
SpeedMessage::raw_data
union rawData raw_data
Definition:
actuators_ostrich.c:57
rawData::data
struct SpeedMessagePayload data
Definition:
actuators_ostrich.c:49
actuators_ostrich_init
void actuators_ostrich_init()
Definition:
actuators_ostrich.c:88
RawMessage::speed_message
struct SpeedMessage speed_message
Definition:
actuators_ostrich.c:61
uart.h
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
ActuatorsOstrich::cmds
uint16_t cmds[3]
commands
Definition:
actuators_ostrich.h:33
START_BYTE
#define START_BYTE
Definition:
actuators_ostrich.c:40
SpeedMessage::checksum
uint8_t checksum
Definition:
actuators_ostrich.c:56
speed_cmd_to_msg
static uint16_t speed_cmd_to_msg(uint16_t speed_cmd)
Definition:
actuators_ostrich.c:68
actuators_ostrich
struct ActuatorsOstrich actuators_ostrich
Definition:
actuators_ostrich.c:38
uint8_t
unsigned char uint8_t
Definition:
types.h:14
turn_cmd_to_msg
static uint16_t turn_cmd_to_msg(uint16_t turn_cmd)
Definition:
actuators_ostrich.c:73
ostrich_dev
static struct uart_periph * ostrich_dev
Definition:
actuators_ostrich.c:66
SPEED_NEUTRAL
#define SPEED_NEUTRAL
Definition:
actuators_ostrich.c:30
SpeedMessagePayload
Definition:
actuators_ostrich.c:42
TURN_OF_CMD
#define TURN_OF_CMD(_w)
Definition:
actuators_ostrich.c:36
RawMessage
Definition:
actuators_ostrich.c:60
SpeedMessagePayload::vy
uint16_t vy
Definition:
actuators_ostrich.c:44
uart_periph
UART peripheral.
Definition:
uart.h:70
uart_put_buffer
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:1122
rawData
Definition:
actuators_ostrich.c:48
checksum
static uint8_t checksum
Definition:
airspeed_uADC.c:61
rawData::bytes
uint8_t bytes[6]
Definition:
actuators_ostrich.c:50
SpeedMessagePayload::vx
uint16_t vx
Definition:
actuators_ostrich.c:43
sw
airborne
modules
actuators
actuators_ostrich.c
Generated on Tue Feb 1 2022 13:51:14 for Paparazzi UAS by
1.8.17