ezosd current sensor integration

This commit is contained in:
Gerard Toonstra
2012-10-05 18:36:09 -03:00
committed by Felix Ruess
parent 1ad3759e48
commit 30d0ea0b1a
5 changed files with 154 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
<!DOCTYPE module SYSTEM "module.dtd">
<!--
EzOSD current sensor module (I2C)
-->
<module name="ezcurrent" dir="sensors">
<doc>
<description>EzOSD Current sensor (I2C)</description>
<define name="EZCURRENT_I2C_DEV" value="i2cX" description="change default i2c peripheral"/>
</doc>
<header>
<file name="ezcurrent.h"/>
</header>
<init fun="ezcurrent_init()"/>
<periodic fun="ezcurrent_read_periodic()" freq="1."/>
<event fun="ezcurrent_read_event()"/>
<makefile>
<file name="ezcurrent.c"/>
<define name="DISABLE_ELECTRICAL" description="Disable default electrical handling"/>
</makefile>
</module>
@@ -64,7 +64,9 @@ void init_fbw( void ) {
mcu_init();
#ifndef DISABLE_ELECTRICAL
electrical_init();
#endif
#ifdef ACTUATORS
actuators_init();
@@ -213,7 +215,9 @@ void handle_periodic_tasks_fbw(void) {
if (sys_time_check_and_ack_timer(fbw_periodic_tid))
periodic_task_fbw();
#ifndef DISABLE_ELECTRICAL
if (sys_time_check_and_ack_timer(electrical_tid))
electrical_periodic();
#endif
}
+77
View File
@@ -0,0 +1,77 @@
/*
* Driver for the EzOSD Current sensor.
*
* Notes:
* Connect directly to I2C1 port.
*
* Copyright (C) 2012 Gerard Toonstra
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "sensors/ezcurrent.h"
#include "estimator.h"
#include "mcu_periph/i2c.h"
#include "mcu_periph/uart.h"
#include "messages.h"
#include "subsystems/datalink/downlink.h"
#include "subsystems/electrical.h"
#include <math.h>
#define EZCURRENT_ADDR 0xEF
#ifndef ezcurrent_I2C_DEV
#define ezcurrent_I2C_DEV i2c1
#endif
#ifndef DOWNLINK_DEVICE
#define DOWNLINK_DEVICE DOWNLINK_AP_DEVICE
#endif
struct i2c_transaction ezcurrent_i2c_trans;
void ezcurrent_init( void ) {
electrical.vsupply = 0;
electrical.current = 0;
ezcurrent_i2c_trans.status = I2CTransDone;
ezcurrent_i2c_trans.slave_addr = EZCURRENT_ADDR;
}
void ezcurrent_read_periodic( void ) {
#ifndef SITL
if (ezcurrent_i2c_trans.status == I2CTransDone) {
I2CReceive(ezcurrent_I2C_DEV, ezcurrent_i2c_trans, ezcurrent_i2c_trans.slave_addr, 10);
}
#endif //SITL
}
void ezcurrent_read_event( void ) {
if (ezcurrent_i2c_trans.status == I2CTransSuccess) {
// Get electrical information from buffer
electrical.vsupply = ((uint8_t)( (((ezcurrent_i2c_trans.buf[3]) << 8) + (ezcurrent_i2c_trans.buf[2])) * 0.01f) );
electrical.current = ((int32_t)(ezcurrent_i2c_trans.buf[9]) << 8) + (int32_t)(ezcurrent_i2c_trans.buf[8]);
electrical.consumed = ((int32_t)(ezcurrent_i2c_trans.buf[7]) << 8) + (int32_t)(ezcurrent_i2c_trans.buf[6]);
// Transaction has been read
ezcurrent_i2c_trans.status = I2CTransDone;
} else if ( ezcurrent_i2c_trans.status == I2CTransFailed ) {
ezcurrent_i2c_trans.status = I2CTransDone;
// ezcurrent_i2c_trans.slave_addr++;
}
}
+46
View File
@@ -0,0 +1,46 @@
/*
* Driver for the EzOSD Current sensor.
*
* Notes:
* Connect directly to I2C1 port.
*
* Sensor module wire assignments:
* Red wire: 5V
* Black wire: Ground
* DAT: SDA
* CLK: SCL
*
* Copyright (C) 2012 Gerard Toonstra
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef EZCURRENT_H
#define EZCURRENT_H
#include "std.h"
#include "mcu_periph/i2c.h"
extern struct i2c_transaction ezcurrent_i2c_trans;
extern void ezcurrent_init( void );
extern void ezcurrent_read_periodic( void );
extern void ezcurrent_read_event( void );
#endif // EZCURRENT_H
+1
View File
@@ -7,6 +7,7 @@ struct Electrical {
uint8_t vsupply; /* supply in decivolts */
int32_t current; /* current in milliamps */
int32_t consumed; /* consumption in mAh */
};