Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
actuators_mkk.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_I2C_DEV)
33 
35 
36 
37 void actuators_mkk_init(void) {
38  actuators_mkk.submit_err_cnt = 0;
39 }
40 
41 
42 void actuators_mkk_set(void) {
43  const uint8_t actuators_addr[ACTUATORS_MKK_NB] = ACTUATORS_MKK_ADDR;
44  static uint8_t last_idx = ACTUATORS_MKK_NB;
45 
46 #if defined ACTUATORS_START_DELAY && ! defined SITL
47  if (!actuators_delay_done) {
48  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY))
49  return;
50  else
51  actuators_delay_done = TRUE;
52  }
53 #endif
54 
55  uint8_t cur_idx = last_idx;
56  for (uint8_t i=0; i<ACTUATORS_MKK_NB; i++) {
57  if(cur_idx >= ACTUATORS_MKK_NB) {
58  cur_idx = 0;
59  }
60 #ifdef KILL_MOTORS
61  actuators_mkk.trans[cur_idx].buf[0] = 0;
62 #endif
63  if (!i2c_transmit(&ACTUATORS_MKK_I2C_DEV, &actuators_mkk.trans[cur_idx],
64  actuators_addr[cur_idx], 1)) {
66  last_idx = cur_idx;
67  return;
68  }
69  cur_idx++;
70  }
71  /* successfully submitted all transactions */
72  last_idx = ACTUATORS_MKK_NB;
73 }
struct i2c_transaction trans[ACTUATORS_MKK_NB]
Definition: actuators_mkk.h:36
struct ActuatorsMkk actuators_mkk
Definition: actuators_mkk.c:34
Actuators driver for Mikrokopter motor controllers.
Architecture independent timing functions.
void actuators_mkk_init(void)
Definition: actuators_mkk.c:37
bool_t i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Definition: i2c.c:85
#define SysTimeTimer(_t)
Definition: sys_time_arch.h:65
Hardware independent API for actuators (servos, motor controllers).
#define USEC_OF_SEC(sec)
Definition: sys_time.h:190
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
uint16_t submit_err_cnt
Definition: actuators_mkk.h:37
unsigned char uint8_t
Definition: types.h:14
void actuators_mkk_set(void)
Definition: actuators_mkk.c:42
Architecture independent I2C (Inter-Integrated Circuit Bus) API.