Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 
28 #include "subsystems/actuators.h"
30 #include "subsystems/electrical.h"
31 #include "actuators.h"
32 #include "led_hw.h"
33 #include "autopilot.h"
34 
35 #if PERIODIC_TELEMETRY
38 
39 static void send_bebop_actuators(struct transport_tx *trans, struct link_device *dev)
40 {
41  pprz_msg_send_BEBOP_ACTUATORS(trans, dev, AC_ID,
42  &stabilization_cmd[COMMAND_THRUST],
43  &stabilization_cmd[COMMAND_ROLL],
44  &stabilization_cmd[COMMAND_PITCH],
45  &stabilization_cmd[COMMAND_YAW],
54 }
55 #endif
56 
59 static uint8_t actuators_bebop_checksum(uint8_t *bytes, uint8_t size);
60 
62 {
63  /* Initialize the I2C connection */
66  actuators_bebop.led = 0;
67 
68 #if PERIODIC_TELEMETRY
70 #endif
71 }
72 
74 {
75  // Receive the status
78 
79  // Update status
81  // The 15th bit contains saturation information, so it needs to be removed to get the rpm
86 
87  // When detected a suicide
89  if (actuators_bebop.i2c_trans.buf[11] == 2 && actuators_bebop.i2c_trans.buf[10] != 1) {
91  }
92 
93  // Start the motors
95  // Reset the error
98 
99  // Start the motors
101 #if BEBOP_VERSION2
102  // For Bebop version 2 some motors are reversed (FIXME: test final version)
103  actuators_bebop.i2c_trans.buf[1] = 0b00001010;
104 #else
105  actuators_bebop.i2c_trans.buf[1] = 0b00000101;
106 #endif
108  }
109  // Stop the motors
110  else if (actuators_bebop.i2c_trans.buf[10] == 4 && !autopilot_motors_on) {
113  } else if (actuators_bebop.i2c_trans.buf[10] == 4 && autopilot_motors_on) {
114  // Send the commands
124  actuators_bebop.i2c_trans.buf[9] = 0x00; //UNK?
125 #pragma GCC diagnostic push
126 #pragma GCC diagnostic ignored "-Wcast-qual"
128 #pragma GCC diagnostic pop
130  }
131 
132  // Update the LEDs
133  if (actuators_bebop.led != (led_hw_values & 0x3)) {
137 
139  }
140 }
141 
143 {
144  uint8_t checksum = 0;
145  for (int i = 0; i < size; i++) {
146  checksum = checksum ^ bytes[i];
147  }
148 
149  return checksum;
150 }
#define ACTUATORS_BEBOP_SET_REF_SPEED
Set reference speed.
Definition: actuators.h:38
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
Periodic telemetry system header (includes downlink utility and generated code).
void autopilot_set_motors_on(bool motors_on)
Definition: autopilot.c:704
void actuators_bebop_commit(void)
Definition: actuators.c:73
#define ACTUATORS_BEBOP_ADDR
Definition: actuators.h:35
bool autopilot_motors_on
Definition: autopilot.c:76
#define ACTUATORS_BEBOP_TOGGLE_GPIO
Toggle GPIO (reset, red led, green led)
Definition: actuators.h:41
uint32_t led_hw_values
Definition: actuators.c:68
#define FALSE
Definition: std.h:5
uint16_t rpm_obs[4]
Observed RPM.
Definition: actuators.h:51
Hardware independent API for actuators (servos, motor controllers).
static uint8_t checksum
Definition: airspeed_uADC.c:60
#define ACTUATORS_BEBOP_CLEAR_ERROR
Clear all current erros.
Definition: actuators.h:43
transaction set to done by user level
Definition: i2c.h:59
Interface for electrical status: supply voltage, current, battery status, etc.
uint8_t led
Current led status.
Definition: actuators.h:52
unsigned long uint32_t
Definition: types.h:18
#define DefaultPeriodic
Set default periodic telemetry.
Definition: telemetry.h:66
static uint8_t actuators_bebop_checksum(uint8_t *bytes, uint8_t size)
Definition: actuators.c:142
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition: i2c.c:278
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:258
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
#define ACTUATORS_BEBOP_GET_OBS_DATA
Get observation data.
Definition: actuators.h:39
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
unsigned char uint8_t
Definition: types.h:14
uint16_t vsupply
supply voltage in decivolts
Definition: electrical.h:48
General stabilization interface for rotorcrafts.
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:28
#define ACTUATORS_BEBOP_STOP_PROP
Stop the propellers.
Definition: actuators.h:42
struct Electrical electrical
Definition: electrical.c:65
struct ActuatorsBebop actuators_bebop
Definition: actuators.c:58
static void send_bebop_actuators(struct transport_tx *trans, struct link_device *dev)
Definition: actuators.c:39
uint16_t rpm_ref[4]
Reference RPM.
Definition: actuators.h:50
Actuator driver for the bebop.
Motor Mixing.
struct i2c_transaction i2c_trans
I2C transaction for communicating with the bebop BLDC driver.
Definition: actuators.h:49
void actuators_bebop_init(void)
Definition: actuators.c:61
#define ACTUATORS_BEBOP_START_PROP
Start the propellers.
Definition: actuators.h:40
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition: telemetry.c:46