Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
actuators_md25.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
29 
30 // Registers
31 #define MD25_REG_SPEED1 0x00
32 #define MD25_REG_SPEED2 0x01
33 #define MD25_REG_ENCODER1 0x02
34 #define MD25_REG_ENCODER2 0x06
35 #define MD25_REG_BAT 0x0A
36 #define MD25_REG_CURRENT1 0x0B
37 #define MD25_REG_CURRENT2 0x0C
38 #define MD25_REG_SOFT_REV 0x0D
39 #define MD25_REG_ACCEL_RATE 0x0E
40 #define MD25_REG_MODE 0x0F
41 #define MD25_REG_COMMAND 0x10
42 // Commands
43 #define MD25_CMD_RESET_ENCODERS 0x20
44 #define MD25_CMD_NO_SPEED_REGUL 0x30
45 #define MD25_CMD_SPEED_REGUL 0x31
46 #define MD25_CMD_NO_MOTOR_TIMEOUT 0x32
47 #define MD25_CMD_MOTOR_TIMEOUT 0x33
48 
49 // Modes
50 #define MD25_MODE0 0 // motor1 speed, motor2 speed [0, 255] (default)
51 #define MD25_MODE1 1 // motor1 speed, motor2 speed [-128, 127]
52 #define MD25_MODE2 2 // speed, turn [0, 255]
53 #define MD25_MODE3 3 // speed, turn [-128, 127]
54 
55 // default control mode
56 #ifndef ACTUATORS_MD25_MODE
57 #define ACTUATORS_MD25_MODE MD25_MODE0
58 #endif
59 
60 // default accel rate
61 #ifndef ACTUATORS_MD25_ACCEL_RATE
62 #define ACTUATORS_MD25_ACCEL_RATE 5
63 #endif
64 
65 // 7 bits I2C address
66 #ifndef ACTUATORS_MD25_I2C_ADDR
67 #define ACTUATORS_MD25_I2C_ADDR 0xB0
68 //#define ACTUATORS_MD25_I2C_ADDR 0x58
69 #endif
70 
71 PRINT_CONFIG_VAR(ACTUATORS_MD25_DEV)
72 
74 
76 {
78  actuators_md25.bat = 0;
79  actuators_md25.cmds[0] = 0;
80  actuators_md25.cmds[1] = 0;
81  actuators_md25.encoders[0] = 0;
82  actuators_md25.encoders[1] = 0;
88 }
89 
91 {
94  // send accel rate and mode configuration
99  }
100  else {
101  // read sensors: enc1, enc1, bat, cur1, cur2
103  i2c_transceive(&(ACTUATORS_MD25_DEV), &actuators_md25.trans_sensors, ACTUATORS_MD25_I2C_ADDR, 1, 11);
104  }
105  }
106 }
107 
109 {
114  i2c_transmit(&(ACTUATORS_MD25_DEV), &actuators_md25.trans_cmd, ACTUATORS_MD25_I2C_ADDR, 3);
115  }
116 }
117 
118 #define Int32FromBuf(_buf,_idx) ((int32_t)(((uint32_t)_buf[_idx]<<24) | ((uint32_t)_buf[_idx+1]<<16) | ((uint32_t)_buf[_idx+2]<<8) | _buf[_idx+3]))
119 
121 {
122  // commands
125  }
127  // TODO handle or report error
129  }
130 
131  // sensors
140  }
141  else {
144  }
145  }
147  // TODO handle or report error
149  }
150 }
151 
#define MD25_REG_ACCEL_RATE
void actuators_md25_init(void)
#define ACTUATORS_MD25_ACCEL_RATE
#define ACTUATORS_MD25_MODE
#define MD25_REG_ENCODER1
#define ACTUATORS_MD25_I2C_ADDR
#define Int32FromBuf(_buf, _idx)
void actuators_md25_periodic(void)
void actuators_md25_set(void)
#define MD25_REG_SPEED1
struct ActuatorsMD25 actuators_md25
void actuators_md25_event(void)
uint8_t bat
batterie voltage (in decivolt)
struct i2c_transaction trans_sensors
i2c struct for sensors
uint8_t current[2]
current in motors (in deciamp)
uint8_t mode
control mode
bool initialized
init flag
uint8_t accel_rate
accel rate (from 1 to 10)
struct i2c_transaction trans_cmd
i2c struct for command
uint8_t cmds[2]
commands
int32_t encoders[2]
encoder values
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
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:324
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition: i2c.c:344
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
@ I2CTransFailed
transaction failed
Definition: i2c.h:58
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
Hardware independent API for actuators (servos, motor controllers).