Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces 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 {
40  actuators_asctec_v2.cmd = NONE;
41  actuators_asctec_v2.cur_addr = FRONT;
42  actuators_asctec_v2.new_addr = FRONT;
43  actuators_asctec_v2.i2c_trans.status = I2CTransSuccess;
44  actuators_asctec_v2.i2c_trans.type = I2CTransTx;
46  actuators_asctec_v2.i2c_trans.len_w = 5;
47  actuators_asctec_v2.nb_err = 0;
48 }
49 
50 
52 {
53 #if defined ACTUATORS_START_DELAY && ! defined SITL
54  if (!actuators_delay_done) {
55  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) {
56 #ifdef USE_I2C_ACTUATORS_REBOOT_HACK
57  //Lisa-L with Asctech v2 motors only start after reflashing when a bus error was sensed on stm32-i2c.
58  //multiple re-init solves the problem.
59  i2c1_init();
60 #endif
61  return;
62  } else { actuators_delay_done = true; }
63  }
64 #endif
65 
67  case I2CTransFailed:
70  break;
71  case I2CTransSuccess:
72  case I2CTransDone:
74  break;
75  default:
77  return;
78  }
79 
80 #ifdef KILL_MOTORS
86 #else
87  switch (actuators_asctec_v2.cmd) {
88  case TEST:
94  break;
95  case REVERSE:
101  break;
102  case SET_ADDR:
110  break;
111  case NONE:
121  break;
122  default:
123  break;
124  }
126 #endif
127 
128  actuators_asctec_v2.i2c_trans.type = I2CTransTx; // Can be reset I2C driver
129  i2c_submit(&ACTUATORS_ASCTEC_V2_I2C_DEV, &actuators_asctec_v2.i2c_trans);
130 
131 }
132 
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
transaction successfully finished by I2C driver
Definition: i2c.h:57
enum actuators_asctec_v2_addr cur_addr
Actuators driver for Asctec v2 motor controllers.
enum actuators_asctec_v2_addr new_addr
void actuators_asctec_v2_init(void)
uint8_t len_w
Number of bytes to write/transmit.
Definition: i2c.h:116
Hardware independent API for actuators (servos, motor controllers).
transaction set to done by user level
Definition: i2c.h:59
Architecture independent timing functions.
Definition: gvf.h:55
bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
i2c_submit() function
Definition: i2c_arch.c:375
transaction failed
Definition: i2c.h:58
#define ACTUATORS_ASCTEC_V2_SLAVE_ADDR
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
#define USEC_OF_SEC(sec)
Definition: sys_time.h:210
void actuators_asctec_v2_set(void)
#define SysTimeTimer(_t)
Definition: sys_time.h:219
struct i2c_transaction i2c_trans
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
volatile uint32_t nb_err
transmit only transaction
Definition: i2c.h:47
enum I2CTransactionType type
Transaction type.
Definition: i2c.h:98
enum actuators_asctec_v2_cmd cmd
struct ActuatorsAsctecV2 actuators_asctec_v2
Architecture independent I2C (Inter-Integrated Circuit Bus) API.