Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 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 
141  // Send ABI message
142  struct act_feedback_t feedback[4];
143  for (int i=0;i<4;i++) {
144  feedback[i].idx = get_servo_idx(i);
145  feedback[i].rpm = actuators_bebop.rpm_obs[i];
146  feedback[i].set.rpm = true;
147  }
148  AbiSendMsgACT_FEEDBACK(ACT_FEEDBACK_BOARD_ID, feedback, 4);
149 }
150 
152 {
153  uint8_t checksum = 0;
154  for (int i = 0; i < size; i++) {
155  checksum = checksum ^ bytes[i];
156  }
157 
158  return checksum;
159 }
Main include for ABI (AirBorneInterface).
#define ACT_FEEDBACK_BOARD_ID
static uint8_t checksum
Definition: airspeed_uADC.c:61
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:39
void actuators_bebop_init(void)
Definition: actuators.c:61
static uint8_t actuators_bebop_checksum(uint8_t *bytes, uint8_t size)
Definition: actuators.c:151
void actuators_bebop_commit(void)
Definition: actuators.c:73
struct ActuatorsBebop actuators_bebop
Definition: actuators.c:58
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
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:122
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
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:403
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:359
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
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
struct Stabilization stabilization
Definition: stabilization.c:41
General stabilization interface for rotorcrafts.
int32_t cmd[COMMANDS_NB]
output command vector, range from [-MAX_PPRZ:MAX_PPRZ] (store for messages)
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_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
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98