Paparazzi UAS  v5.18.0_stable
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 
27 #include "subsystems/actuators.h"
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 
i2c_transaction::buf
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition: i2c.h:122
ACTUATORS_MD25_I2C_ADDR
#define ACTUATORS_MD25_I2C_ADDR
Definition: actuators_md25.c:67
I2CTransFailed
@ I2CTransFailed
transaction failed
Definition: i2c.h:58
ACTUATORS_MD25_ACCEL_RATE
#define ACTUATORS_MD25_ACCEL_RATE
Definition: actuators_md25.c:62
actuators_md25_init
void actuators_md25_init(void)
Definition: actuators_md25.c:75
ActuatorsMD25::trans_cmd
struct i2c_transaction trans_cmd
i2c struct for command
Definition: actuators_md25.h:42
I2CTransSuccess
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition: i2c.h:57
ActuatorsMD25::initialized
bool initialized
init flag
Definition: actuators_md25.h:41
ActuatorsMD25::current
uint8_t current[2]
current in motors (in deciamp)
Definition: actuators_md25.h:38
i2c_transmit
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
actuators_md25.h
ActuatorsMD25::encoders
int32_t encoders[2]
encoder values
Definition: actuators_md25.h:36
actuators_md25
struct ActuatorsMD25 actuators_md25
Definition: actuators_md25.c:73
i2c_transceive
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
ActuatorsMD25
Definition: actuators_md25.h:34
i2c_transaction::status
enum I2CTransactionStatus status
Transaction status.
Definition: i2c.h:126
ActuatorsMD25::bat
uint8_t bat
batterie voltage (in decivolt)
Definition: actuators_md25.h:37
actuators_md25_periodic
void actuators_md25_periodic(void)
Definition: actuators_md25.c:90
Int32FromBuf
#define Int32FromBuf(_buf, _idx)
Definition: actuators_md25.c:118
actuators_md25_set
void actuators_md25_set(void)
Definition: actuators_md25.c:108
ActuatorsMD25::trans_sensors
struct i2c_transaction trans_sensors
i2c struct for sensors
Definition: actuators_md25.h:43
MD25_REG_SPEED1
#define MD25_REG_SPEED1
Definition: actuators_md25.c:31
MD25_REG_ENCODER1
#define MD25_REG_ENCODER1
Definition: actuators_md25.c:33
actuators_md25_event
void actuators_md25_event(void)
Definition: actuators_md25.c:120
ActuatorsMD25::mode
uint8_t mode
control mode
Definition: actuators_md25.h:39
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
ACTUATORS_MD25_MODE
#define ACTUATORS_MD25_MODE
Definition: actuators_md25.c:57
ActuatorsMD25::accel_rate
uint8_t accel_rate
accel rate (from 1 to 10)
Definition: actuators_md25.h:40
MD25_REG_ACCEL_RATE
#define MD25_REG_ACCEL_RATE
Definition: actuators_md25.c:39
ActuatorsMD25::cmds
uint8_t cmds[2]
commands
Definition: actuators_md25.h:35
actuators.h