Paparazzi UAS  v5.15_devel-88-gb3ad7fe
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"
29 #include "subsystems/electrical.h"
30 #include "actuators.h"
31 #include "led_hw.h"
32 #include "autopilot.h"
33 #include "subsystems/abi.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
80  electrical.vsupply = (float)(actuators_bebop.i2c_trans.buf[9] + (actuators_bebop.i2c_trans.buf[8] << 8)) / 1000.f;
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_get_motors_on()) {
113  } else if (actuators_bebop.i2c_trans.buf[10] == 4 && autopilot_get_motors_on()) {
114  // Send the commands
124  actuators_bebop.i2c_trans.buf[9] = 0x00; //UNK enable security?
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  // Send ABI message
141  AbiSendMsgRPM(RPM_SENSOR_ID, actuators_bebop.rpm_obs, 4);
142 }
143 
145 {
146  uint8_t checksum = 0;
147  for (int i = 0; i < size; i++) {
148  checksum = checksum ^ bytes[i];
149  }
150 
151  return checksum;
152 }
#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).
bool autopilot_get_motors_on(void)
get motors status
Definition: autopilot.c:212
void actuators_bebop_commit(void)
Definition: actuators.c:73
Main include for ABI (AirBorneInterface).
float vsupply
supply voltage in V
Definition: electrical.h:45
#define ACTUATORS_BEBOP_ADDR
Definition: actuators.h:35
#define RPM_SENSOR_ID
#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
bool i2c_blocking_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 and wait for it to complete.
Definition: i2c.c:385
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:144
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
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
Core autopilot interface common to all firmwares.
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
unsigned char uint8_t
Definition: types.h:14
General stabilization interface for rotorcrafts.
void 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:200
int32_t stabilization_cmd[COMMANDS_NB]
Stabilization commands.
Definition: stabilization.c:32
#define ACTUATORS_BEBOP_STOP_PROP
Stop the propellers.
Definition: actuators.h:42
struct Electrical electrical
Definition: electrical.c:66
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.
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
bool i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction and wait for it to complete.
Definition: i2c.c:343