Paparazzi UAS  v5.2.2_stable-0-gd6b9f29
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_mkk_v2.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2009 Antoine Drouin <poinix@gmail.com>
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, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
26 #include "subsystems/actuators.h"
28 
29 #include "mcu_periph/i2c.h"
30 #include "mcu_periph/sys_time.h"
31 
32 PRINT_CONFIG_VAR(ACTUATORS_MKK_V2_I2C_DEV)
33 
35 
37 
38  const uint8_t actuators_addr[ACTUATORS_MKK_V2_NB] = ACTUATORS_MKK_V2_ADDR;
39  for (uint8_t i=0; i<ACTUATORS_MKK_V2_NB; i++) {
40  actuators_mkk_v2.trans[i].type = I2CTransTx;
41  actuators_mkk_v2.trans[i].len_w = 2;
42  actuators_mkk_v2.trans[i].slave_addr = actuators_addr[i];
43  actuators_mkk_v2.trans[i].status = I2CTransSuccess;
44 
45  actuators_mkk_v2.data[i].Version = 0;
46  actuators_mkk_v2.data[i].Current = 0;
47  actuators_mkk_v2.data[i].MaxPWM = 0;
48  actuators_mkk_v2.data[i].Temperature = 0;
49  }
50 
51  actuators_mkk_v2.read_number = 0;
52 
53 }
54 
55 static inline void actuators_mkk_v2_read(void) {
57  if (actuators_mkk_v2.read_number >= ACTUATORS_MKK_V2_NB)
59 
62 }
63 
65 #if defined ACTUATORS_START_DELAY && ! defined SITL
66  if (!actuators_delay_done) {
67  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) return;
68  else actuators_delay_done = TRUE;
69  }
70 #endif
71 
72  // Read result
73  for (uint8_t i=0; i<ACTUATORS_MKK_V2_NB; i++)
74  {
76  {
78 
82  }
83  }
84 
85  RunOnceEvery(10, actuators_mkk_v2_read() );
86 
87  for (uint8_t i=0; i<ACTUATORS_MKK_V2_NB; i++) {
88 
89 #ifdef KILL_MOTORS
90  actuators_mkk_v2.trans[i].buf[0] = 0;
91  actuators_mkk_v2.trans[i].buf[1] = 0;
92 #else
95 #endif
96 
97  i2c_submit(&ACTUATORS_MKK_V2_DEVICE, &actuators_mkk_v2.trans[i]);
98  }
99 }
Actuators driver for Mikrokopter motor controllers.
bool_t i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
Definition: i2c_arch.c:335
transaction successfully finished by I2C driver
Definition: i2c.h:57
transmit and receive transaction
Definition: i2c.h:49
struct actuators_mkk_v2_telemetry_struct data[ACTUATORS_MKK_V2_NB]
struct actuators_mkk_v2_struct actuators_mkk_v2
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
uint16_t setpoint[ACTUATORS_MKK_V2_NB]
Architecture independent timing functions.
Hardware independent API for actuators (servos, motor controllers).
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
#define USEC_OF_SEC(sec)
Definition: sys_time.h:190
#define SysTimeTimer(_t)
Definition: sys_time.h:199
#define TRUE
Definition: imu_chimu.h:144
static void actuators_mkk_v2_read(void)
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
uint8_t len_w
Number of bytes to write/transmit.
Definition: i2c.h:116
uint16_t len_r
Number of bytes to read/receive.
Definition: i2c.h:110
struct i2c_transaction trans[ACTUATORS_MKK_V2_NB]
unsigned char uint8_t
Definition: types.h:14
transmit only transaction
Definition: i2c.h:47
enum I2CTransactionType type
Transaction type.
Definition: i2c.h:98
void actuators_mkk_v2_init(void)
void actuators_mkk_v2_set(void)
Architecture independent I2C (Inter-Integrated Circuit Bus) API.