Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
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
25
28
29#include "mcu_periph/i2c.h"
30#include "mcu_periph/sys_time.h"
31
32#define ACTUATORS_ASCTEC_V2_SLAVE_ADDR 0x02
33
34PRINT_CONFIG_VAR(ACTUATORS_ASCTEC_V2_I2C_DEV)
35
37
39{
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
66 switch (actuators_asctec_v2.i2c_trans.status) {
67 case I2CTransFailed:
68 actuators_asctec_v2.nb_err++;
69 actuators_asctec_v2.i2c_trans.status = I2CTransDone;
70 break;
71 case I2CTransSuccess:
72 case I2CTransDone:
73 actuators_asctec_v2.i2c_trans.status = I2CTransDone;
74 break;
75 default:
76 actuators_asctec_v2.nb_err++;
77 return;
78 }
79
80#ifdef KILL_MOTORS
81 actuators_asctec_v2.i2c_trans.buf[0] = 0;
82 actuators_asctec_v2.i2c_trans.buf[1] = 0;
83 actuators_asctec_v2.i2c_trans.buf[2] = 0;
84 actuators_asctec_v2.i2c_trans.buf[3] = 0;
85 actuators_asctec_v2.i2c_trans.buf[4] = 0xAA;
86#else
87 switch (actuators_asctec_v2.cmd) {
88 case TEST:
89 actuators_asctec_v2.i2c_trans.buf[0] = 251;
90 actuators_asctec_v2.i2c_trans.buf[1] = actuators_asctec_v2.cur_addr;
91 actuators_asctec_v2.i2c_trans.buf[2] = 0;
92 actuators_asctec_v2.i2c_trans.buf[3] = 231 + actuators_asctec_v2.cur_addr;
93 actuators_asctec_v2.i2c_trans.len_w = 4;
94 break;
95 case REVERSE:
96 actuators_asctec_v2.i2c_trans.buf[0] = 254;
97 actuators_asctec_v2.i2c_trans.buf[1] = actuators_asctec_v2.cur_addr;
98 actuators_asctec_v2.i2c_trans.buf[2] = 0;
99 actuators_asctec_v2.i2c_trans.buf[3] = 234 + actuators_asctec_v2.cur_addr;
100 actuators_asctec_v2.i2c_trans.len_w = 4;
101 break;
102 case SET_ADDR:
103 actuators_asctec_v2.i2c_trans.buf[0] = 250;
104 actuators_asctec_v2.i2c_trans.buf[1] = actuators_asctec_v2.cur_addr;
105 actuators_asctec_v2.i2c_trans.buf[2] = actuators_asctec_v2.new_addr;
106 actuators_asctec_v2.i2c_trans.buf[3] = 230 + actuators_asctec_v2.cur_addr +
107 actuators_asctec_v2.new_addr;
108 actuators_asctec_v2.cur_addr = actuators_asctec_v2.new_addr;
109 actuators_asctec_v2.i2c_trans.len_w = 4;
110 break;
111 case NONE:
112 actuators_asctec_v2.i2c_trans.buf[0] = actuators_asctec_v2.cmds[SERVO_FRONT_IDX];
113 actuators_asctec_v2.i2c_trans.buf[1] = actuators_asctec_v2.cmds[SERVO_BACK_IDX];
114 actuators_asctec_v2.i2c_trans.buf[2] = actuators_asctec_v2.cmds[SERVO_LEFT_IDX];
115 actuators_asctec_v2.i2c_trans.buf[3] = actuators_asctec_v2.cmds[SERVO_RIGHT_IDX];
116 actuators_asctec_v2.i2c_trans.buf[4] = 0xAA + actuators_asctec_v2.i2c_trans.buf[0] +
117 actuators_asctec_v2.i2c_trans.buf[1] +
118 actuators_asctec_v2.i2c_trans.buf[2] +
119 actuators_asctec_v2.i2c_trans.buf[3];
120 actuators_asctec_v2.i2c_trans.len_w = 5;
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
134{
135 actuators_asctec_v2.cmds[idx] = value;
136}
137
void actuators_asctec_v2_commit(void)
void actuators_asctec_v2_set(uint8_t idx, int16_t value)
void actuators_asctec_v2_init(void)
struct ActuatorsAsctecV2 actuators_asctec_v2
#define ACTUATORS_ASCTEC_V2_SLAVE_ADDR
Actuators driver for Asctec v2 motor controllers.
static bool i2c_submit(struct i2c_periph *p, struct i2c_transaction *t)
Submit a I2C transaction.
Definition i2c.h:271
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:58
@ I2CTransFailed
transaction failed
Definition i2c.h:59
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:60
@ I2CTransTx
transmit only transaction
Definition i2c.h:48
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
Hardware independent API for actuators (servos, motor controllers).
static uint32_t idx
PRINT_CONFIG_VAR(ONELOOP_ANDI_FILT_CUTOFF)
Architecture independent timing functions.
#define USEC_OF_SEC(sec)
Definition sys_time.h:322
#define SysTimeTimer(_t)
Definition sys_time.h:330
short int16_t
Typedef defining 16 bit short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.