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_asctec_v2.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2013 The Paparazzi Team
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 #define ACTUATORS_ASCTEC_V2_SLAVE_ADDR 0x02
33 
34 PRINT_CONFIG_VAR(ACTUATORS_ASCTEC_V2_I2C_DEV)
35 
37 
39  actuators_asctec_v2.cmd = NONE;
40  actuators_asctec_v2.cur_addr = FRONT;
41  actuators_asctec_v2.new_addr = FRONT;
42  actuators_asctec_v2.i2c_trans.status = I2CTransSuccess;
43  actuators_asctec_v2.i2c_trans.type = I2CTransTx;
45  actuators_asctec_v2.i2c_trans.len_w = 5;
46  actuators_asctec_v2.nb_err = 0;
47 }
48 
49 
51 #if defined ACTUATORS_START_DELAY && ! defined SITL
52  if (!actuators_delay_done) {
53  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) {
54 #ifdef USE_I2C_ACTUATORS_REBOOT_HACK
55  //Lisa-L with Asctech v2 motors only start after reflashing when a bus error was sensed on stm32-i2c.
56  //multiple re-init solves the problem.
57  i2c1_init();
58 #endif
59  return;
60  }
61  else actuators_delay_done = TRUE;
62  }
63 #endif
64 
66  case I2CTransFailed:
69  break;
70  case I2CTransSuccess:
71  case I2CTransDone:
73  break;
74  default:
76  return;
77  }
78 
79 #ifdef KILL_MOTORS
85 #else
86  switch (actuators_asctec_v2.cmd) {
87  case TEST:
93  break;
94  case REVERSE:
100  break;
101  case SET_ADDR:
109  break;
110  case NONE:
120  break;
121  default:
122  break;
123  }
125 #endif
126 
127  actuators_asctec_v2.i2c_trans.type = I2CTransTx; // Can be reset I2C driver
128  i2c_submit(&ACTUATORS_ASCTEC_V2_I2C_DEV, &actuators_asctec_v2.i2c_trans);
129 
130 }
131 
struct i2c_transaction i2c_trans
bool_t i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Definition: i2c_arch.c:333
Actuators driver for Asctec v2 motor controllers.
enum actuators_asctec_v2_addr new_addr
void actuators_asctec_v2_init(void)
uint8_t slave_addr
Definition: i2c.h:79
enum actuators_asctec_v2_addr cur_addr
volatile uint32_t nb_err
Architecture independent timing functions.
#define SysTimeTimer(_t)
Definition: sys_time_arch.h:65
Hardware independent API for actuators (servos, motor controllers).
enum I2CTransactionStatus status
Definition: i2c.h:83
#define ACTUATORS_ASCTEC_V2_SLAVE_ADDR
#define USEC_OF_SEC(sec)
Definition: sys_time.h:190
void actuators_asctec_v2_set(void)
#define TRUE
Definition: imu_chimu.h:144
volatile uint8_t buf[I2C_BUF_LEN]
Definition: i2c.h:82
uint8_t len_w
Definition: i2c.h:81
Definition: i2c.h:45
enum I2CTransactionType type
Definition: i2c.h:78
enum actuators_asctec_v2_cmd cmd
struct ActuatorsAsctecV2 actuators_asctec_v2
Architecture independent I2C (Inter-Integrated Circuit Bus) API.