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.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  actuators_asctec.cmd = NONE;
46  actuators_asctec.cur_addr = FRONT;
47  actuators_asctec.new_addr = FRONT;
48  actuators_asctec.i2c_trans.status = I2CTransSuccess;
49  actuators_asctec.i2c_trans.type = I2CTransTx;
51  actuators_asctec.i2c_trans.len_w = 4;
52  actuators_asctec.nb_err = 0;
53 }
54 
55 void actuators_asctec_set(bool_t motors_on) {
56 #if defined ACTUATORS_START_DELAY && ! defined SITL
57  if (!actuators_delay_done) {
58  if (SysTimeTimer(actuators_delay_time) < USEC_OF_SEC(ACTUATORS_START_DELAY)) return;
59  else actuators_delay_done = TRUE;
60  }
61 #endif
62 
64  case I2CTransFailed:
67  break;
68  case I2CTransSuccess:
69  case I2CTransDone:
71  break;
72  default:
74  return;
75  }
76 
77 #ifdef KILL_MOTORS
82 #else /* ! KILL_MOTORS */
86  if (motors_on) {
88  }
89  else
91 #endif /* KILL_MOTORS */
92 
93  switch (actuators_asctec.cmd) {
94  case TEST:
99  break;
100  case REVERSE:
101  actuators_asctec.i2c_trans.buf[0] = 254;
105  break;
106  case SET_ADDR:
107  actuators_asctec.i2c_trans.buf[0] = 250;
113  break;
114  case NONE:
119  break;
120  default:
121  break;
122  }
124 
125  i2c_transmit(&ACTUATORS_ASCTEC_I2C_DEV, &actuators_asctec.i2c_trans,
127 
128 }
#define ACTUATORS_ASCTEC_SLAVE_ADDR
int32_t cmds[CMD_NB]
#define ASCTEC_MIN_THROTTLE
uint8_t slave_addr
Definition: i2c.h:79
struct ActuatorsAsctec actuators_asctec
void actuators_asctec_set(bool_t motors_on)
Architecture independent timing functions.
bool_t i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Definition: i2c.c:85
#define ASCTEC_MAX_THROTTLE
#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 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
uint8_t len_w
Definition: i2c.h:81
Actuators driver for Asctec motor controllers.
struct i2c_transaction i2c_trans
enum actuators_asctec_addr new_addr
Definition: i2c.h:45
enum I2CTransactionType type
Definition: i2c.h:78
void actuators_asctec_init(void)
enum actuators_asctec_cmd cmd
#define ASCTEC_MAX_CMD
#define ASCTEC_MIN_CMD
enum actuators_asctec_addr cur_addr
volatile uint32_t nb_err
Architecture independent I2C (Inter-Integrated Circuit Bus) API.