Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
actuators.c
Go to the documentation of this file.
1/*
2 *
3 * Copyright (C) 2014-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, write to
19 * the Free Software Foundation, 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
30#include "actuators.h"
31#include "led_hw.h"
32#include "autopilot.h"
33#include "modules/core/abi.h"
34
35#if PERIODIC_TELEMETRY
38
39#ifdef STABILIZATION_INDI_COMMANDS
41#endif
42
67#endif
68
69#define ACTUATORS_BEBOP_I2C_TIMEOUT 1.f
70
74
86
91
93{
94 // Receive the status
97
98 // Update status
100 // The 15th bit contains saturation information, so it needs to be removed to get the rpm
105
106 // When detected a suicide
108 if (actuators_bebop.i2c_trans.buf[11] == 2 && actuators_bebop.i2c_trans.buf[10] != 1) {
110 }
111
112 // Start the motors
114 // Reset the error
117
118 // Start the motors
120#if BEBOP_VERSION2
121 // For Bebop version 2 some motors are reversed (FIXME: test final version)
122 actuators_bebop.i2c_trans.buf[1] = 0b00001010;
123#else
124 actuators_bebop.i2c_trans.buf[1] = 0b00000101;
125#endif
127 }
128 // Stop the motors
129 else if (actuators_bebop.i2c_trans.buf[10] == 4 && !autopilot_get_motors_on()) {
132 } else if (actuators_bebop.i2c_trans.buf[10] == 4 && autopilot_get_motors_on()) {
133 // Send the commands
143 actuators_bebop.i2c_trans.buf[9] = 0x00; //UNK enable security?
144#pragma GCC diagnostic push
145#pragma GCC diagnostic ignored "-Wcast-qual"
147#pragma GCC diagnostic pop
149 }
150
151 // Update the LEDs
152 if (actuators_bebop.led != (led_hw_values & 0x3)) {
156
158 }
159
160 // Send ABI message
161 struct act_feedback_t feedback[4];
162 for (int i=0;i<4;i++) {
163 feedback[i].idx = get_servo_idx(i);
164 feedback[i].rpm = actuators_bebop.rpm_obs[i];
165 feedback[i].set.rpm = true;
166 }
168}
169
171{
172 uint8_t checksum = 0;
173 for (int i = 0; i < size; i++) {
174 checksum = checksum ^ bytes[i];
175 }
176
177 return checksum;
178}
Main include for ABI (AirBorneInterface).
#define ACT_FEEDBACK_BOARD_ID
static uint8_t checksum
bool autopilot_set_motors_on(bool motors_on)
turn motors on/off, eventually depending of the current mode set kill_throttle accordingly FIXME is i...
Definition autopilot.c:250
bool autopilot_get_motors_on(void)
get motors status
Definition autopilot.c:295
Core autopilot interface common to all firmwares.
uint32_t led_hw_values
Definition actuators.c:68
static void send_bebop_actuators(struct transport_tx *trans, struct link_device *dev)
Definition actuators.c:43
void actuators_bebop_init(void)
Definition actuators.c:75
#define ACTUATORS_BEBOP_I2C_TIMEOUT
Definition actuators.c:69
static uint8_t actuators_bebop_checksum(uint8_t *bytes, uint8_t size)
Definition actuators.c:170
void actuators_bebop_commit(void)
Definition actuators.c:92
struct ActuatorsBebop actuators_bebop
Definition actuators.c:72
void actuators_bebop_set(uint8_t idx, int16_t value)
Definition actuators.c:87
uint8_t led
Current led status.
Definition actuators.h:52
#define ACTUATORS_BEBOP_TOGGLE_GPIO
Toggle GPIO (reset, red led, green led)
Definition actuators.h:41
struct i2c_transaction i2c_trans
I2C transaction for communicating with the bebop BLDC driver.
Definition actuators.h:49
uint16_t rpm_ref[4]
Reference RPM.
Definition actuators.h:50
#define ACTUATORS_BEBOP_STOP_PROP
Stop the propellers.
Definition actuators.h:42
#define ACTUATORS_BEBOP_ADDR
Definition actuators.h:35
uint16_t rpm_obs[4]
Observed RPM.
Definition actuators.h:51
#define ACTUATORS_BEBOP_START_PROP
Start the propellers.
Definition actuators.h:40
#define ACTUATORS_BEBOP_SET_REF_SPEED
Set reference speed.
Definition actuators.h:38
#define ACTUATORS_BEBOP_CLEAR_ERROR
Clear all current erros.
Definition actuators.h:43
#define ACTUATORS_BEBOP_GET_OBS_DATA
Get observation data.
Definition actuators.h:39
static struct uart_periph * dev
struct Electrical electrical
Definition electrical.c:92
Interface for electrical status: supply voltage, current, battery status, etc.
float vsupply
supply voltage in V
Definition electrical.h:45
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:123
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:127
uint8_t slave_addr
Slave address.
Definition i2c.h:105
enum I2CTransactionStatus i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len, float timeout)
Submit a write only transaction and wait for it to complete.
Definition i2c.c:245
enum I2CTransactionStatus i2c_blocking_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r, float timeout)
Submit a write/read transaction and wait for it to complete.
Definition i2c.c:265
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:60
uint16_t foo
Definition main_demo5.c:58
Hardware independent API for actuators (servos, motor controllers).
int32_t rpm
RPM.
Definition actuators.h:51
struct act_feedback_t::act_feedback_set_t set
Bitset registering what is set as feedback.
uint8_t idx
General index of the actuators (generated in airframe.h)
Definition actuators.h:45
static uint32_t idx
static const ShellCommand commands[]
Definition shell_arch.c:78
struct Stabilization stabilization
General stabilization interface for rotorcrafts.
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
int int32_t
Typedef defining 32 bit int type.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.