功能介绍
完成了步态感知系统初步功能的实现,成品能较好地感知人体运动过程中产生的加速度,并将其数值的变化转换为人体移动的步数。在此基础上可以进行跌倒检测、移动距离感知等进一步的开发。
硬件组成
- Arduino 开源平台:提供数据处理功能
- 六轴加速度传感器 6Dof Shield :提供数据采集功能
- Xbee 、蓝牙等无线传输模块:提供终端监控功能(可选)
- 电源模块:供电
相关库文件
FreeSixIMU.cpp
该库文件整合了三轴加速度计 ADXL345 和陀螺仪 ITG3200 所测得的初始数据。常用库函数如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15// 这三个函数可以使 6Dof Shield 按不同的模式初始化
void FreeSixIMU::init()
void FreeSixIMU::init(bool fastmode)
void FreeSixIMU::init(int acc_addr, int gyro_addr, bool fastmode)
void FreeSixIMU::getValues(float * values) {
// 该函数可以在主程序中直接调用以获取加速度的原始值。
int accval[3];
acc.readAccel(&accval[0], &accval[1], &accval[2]);
values[0] = ((float) accval[0]);
values[1] = ((float) accval[1]);
values[2] = ((float) accval[2]);
gyro.readGyro(&values[3]);
}FIMU_ADXL345.cpp
FreeSixIMU.h
的getValues(float * values)
中使用的acc.readAccel()
来自于FIMU_ADXL345.cpp
库文件。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29void ADXL345::readAccel(int *x, int *y, int *z) {
readFrom(ADXL345_DATAX0, TO_READ, _buff); // 从 ADXL345 读取数据
*x = (((int)_buff[1]) << 8) | _buff[0];
*y = (((int)_buff[3]) << 8) | _buff[2];
*z = (((int)_buff[5]) << 8) | _buff[4];
}
void ADXL345::readFrom(byte address, int num, byte _buff[]) {
Wire.beginTransmission(_dev_address); // 开始传送
Wire.write(address); // 传送的是读取数据的地址
Wire.endTransmission(); // 结束传送
Wire.beginTransmission(_dev_address);
Wire.requestFrom(_dev_address, num); // 从设备请求 6 bytes
int i = 0;
while(Wire.available()) {
// 设备可能发送少于请求的 bytes
_buff[i] = Wire.read(); // 接收一个 byte
i++;
}
if(i != num){
status = ADXL345_ERROR;
error_code = ADXL345_READ_ERROR;
}
Wire.endTransmission();
}FIMU_ITG3200.cpp
FreeSixIMU.h
的getValues(float * values)
中使用的gyro.readGyro()
来自于FIMU_ITG3200.cpp
库文件。Wire.cpp
Wire 库就是针对 I2C 串行通信的应用,使用这个库能够很方便地进行 I2C 通信。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25/* 这三个函数作用是初始化I2C通信,如果不带参数,则作为主机加入到总线当中,如果带参数,则以参数为地址,作为从机加入到总线当中。*/
void TwoWire::begin(void)
void TwoWire::begin(uint8_t address)
void TwoWire::begin(int address)
// 开始发送数据给以参数为地址的从机。
void TwoWire::beginTransmission(uint8_t address)
void TwoWire::beginTransmission(int address)
// 发送数据结束。
uint8_t TwoWire::endTransmission(uint8_t sendStop)
uint8_t TwoWire::endTransmission(void)
// 作为主机向从机请求数据,其中参数1为从机地址,参数2为请求的数据大小。
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)
uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)
uint8_t TwoWire::requestFrom(int address, int quantity)
uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)
// 通过I2C发送一个数据或一串数据。
size_t TwoWire::write(uint8_t data)
size_t TwoWire::write(const uint8_t *data, size_t quantity)
int TwoWire::available(void) // 返回接收数据的个数
int TwoWire::read(void) // 接受从机返回的数据
取得原始数据的示例程序
1 | #include <FreeSixIMU.h> |
核心数据处理程序
1 | #include <FreeSixIMU.h> |