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.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 #define ASCTEC_MIN_CMD -100
33 #define ASCTEC_MAX_CMD 100
34 
35 #define ASCTEC_MIN_THROTTLE 0
36 #define ASCTEC_MAX_THROTTLE 200
37 
38 #define ACTUATORS_ASCTEC_SLAVE_ADDR 0x02
39 
40 PRINT_CONFIG_VAR(ACTUATORS_ASCTEC_I2C_DEV)
41 
43 
45 {
46  actuators_asctec.cmd = NONE;
47  actuators_asctec.cur_addr = FRONT;
48  actuators_asctec.new_addr = FRONT;
49  actuators_asctec.i2c_trans.status = I2CTransSuccess;
50  actuators_asctec.i2c_trans.type = I2CTransTx;
52  actuators_asctec.i2c_trans.len_w = 4;
53  actuators_asctec.nb_err = 0;
54 }
55 
56 void actuators_asctec_set(bool motors_on)
57 {
58 #if defined ACTUATORS_START_DELAY && ! defined SITL
59  if (!actuators_delay_done) {
60  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) { return; }
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
84 #else /* ! KILL_MOTORS */
88  if (motors_on) {
90  } else {
92  }
93 #endif /* KILL_MOTORS */
94 
95  switch (actuators_asctec.cmd) {
96  case TEST:
101  break;
102  case REVERSE:
103  actuators_asctec.i2c_trans.buf[0] = 254;
107  break;
108  case SET_ADDR:
109  actuators_asctec.i2c_trans.buf[0] = 250;
115  break;
116  case NONE:
121  break;
122  default:
123  break;
124  }
126 
127  i2c_transmit(&ACTUATORS_ASCTEC_I2C_DEV, &actuators_asctec.i2c_trans,
129 
130 }
#define ACTUATORS_ASCTEC_SLAVE_ADDR
enum actuators_asctec_addr cur_addr
struct i2c_transaction i2c_trans
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_addr new_addr
#define ASCTEC_MIN_THROTTLE
volatile uint32_t nb_err
uint8_t len_w
Number of bytes to write/transmit.
Definition: i2c.h:116
Hardware independent API for actuators (servos, motor controllers).
void actuators_asctec_set(bool motors_on)
struct ActuatorsAsctec actuators_asctec
transaction set to done by user level
Definition: i2c.h:59
Architecture independent timing functions.
int32_t cmds[CMD_NB]
#define ASCTEC_MAX_THROTTLE
Definition: gvf.h:55
transaction failed
Definition: i2c.h:58
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
#define USEC_OF_SEC(sec)
Definition: sys_time.h:210
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition: i2c.c:258
#define SysTimeTimer(_t)
Definition: sys_time.h:219
uint8_t slave_addr
Slave address.
Definition: i2c.h:104
Actuators driver for Asctec motor controllers.
transmit only transaction
Definition: i2c.h:47
void actuators_asctec_init(void)
enum I2CTransactionType type
Transaction type.
Definition: i2c.h:98
#define ASCTEC_MAX_CMD
#define ASCTEC_MIN_CMD
enum actuators_asctec_cmd cmd
Architecture independent I2C (Inter-Integrated Circuit Bus) API.