mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-11 10:28:29 -04:00
Fixed issues with RcChannel EEPROM var ownership.
git-svn-id: https://arducopter.googlecode.com/svn/trunk@1369 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
parent
c45249622c
commit
9f11c97463
@ -52,8 +52,8 @@ class AP_Var : public AP_VarI
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// The default constrcutor
|
/// The default constrcutor
|
||||||
AP_Var(const type & data, const char * name = "", const bool & sync=false) :
|
AP_Var(const type & data, const char * name = "", const char * parentName = "", const bool & sync=false) :
|
||||||
_data(data), _name(name), _sync(sync)
|
_data(data), _name(name), _parentName(parentName), _sync(sync)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,6 +118,9 @@ public:
|
|||||||
/// Get the name. This is useful for ground stations.
|
/// Get the name. This is useful for ground stations.
|
||||||
virtual const char * getName() { return _name; }
|
virtual const char * getName() { return _name; }
|
||||||
|
|
||||||
|
/// Get the parent name. This is also useful for ground stations.
|
||||||
|
virtual const char * getParentName() { return _parentName; }
|
||||||
|
|
||||||
/// If sync is true the a load will always occure before a get and a save will always
|
/// If sync is true the a load will always occure before a get and a save will always
|
||||||
/// occure before a set.
|
/// occure before a set.
|
||||||
virtual const bool & getSync() { return _sync; }
|
virtual const bool & getSync() { return _sync; }
|
||||||
@ -126,6 +129,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
type _data; /// The data that is stored on the heap */
|
type _data; /// The data that is stored on the heap */
|
||||||
const char * _name; /// The variable name, useful for gcs and terminal output
|
const char * _name; /// The variable name, useful for gcs and terminal output
|
||||||
|
const char * _parentName; /// The variable parent name, useful for gcs and terminal output
|
||||||
bool _sync; /// Whether or not to call save/load on get/set
|
bool _sync; /// Whether or not to call save/load on get/set
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
void * operator new(size_t size)
|
void * operator new(size_t size)
|
||||||
{
|
{
|
||||||
|
#ifdef AP_DISPLAYMEM
|
||||||
|
displayMemory();
|
||||||
|
#endif
|
||||||
return(calloc(size, 1));
|
return(calloc(size, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,6 +35,9 @@ extern "C" void __cxa_pure_virtual()
|
|||||||
|
|
||||||
void * operator new[](size_t size)
|
void * operator new[](size_t size)
|
||||||
{
|
{
|
||||||
|
#ifdef AP_DISPLAYMEM
|
||||||
|
displayMemory();
|
||||||
|
#endif
|
||||||
return(calloc(size, 1));
|
return(calloc(size, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AP_EEProm.h>
|
#include <AP_EEProm.h>
|
||||||
|
void AP_EEPromRegistry::print(BetterStream & stream)
|
||||||
|
{
|
||||||
|
stream.printf("\nEEPROM Registry\n");
|
||||||
|
for (int i=0;i<getSize();i++)
|
||||||
|
{
|
||||||
|
stream.printf("%s\t%s\tid:\t%d\taddr:\t%d\tval:\t%f\t\n",
|
||||||
|
(*this)[i]->getEntryParentName(),
|
||||||
|
(*this)[i]->getEntryName(),
|
||||||
|
(*this)[i]->getEntryId(),
|
||||||
|
(*this)[i]->getEntryAddress(),
|
||||||
|
(*this)[i]->getEntry());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AP_EEPromRegistry::add(AP_EEPromEntryI * entry, uint16_t & id, uint16_t & address, size_t size)
|
void AP_EEPromRegistry::add(AP_EEPromEntryI * entry, uint16_t & id, uint16_t & address, size_t size)
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <AP_Vector.h>
|
#include <AP_Vector.h>
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
#include <BetterStream.h>
|
||||||
|
|
||||||
/// The interface for data entries in the eeprom registry
|
/// The interface for data entries in the eeprom registry
|
||||||
class AP_EEPromEntryI
|
class AP_EEPromEntryI
|
||||||
@ -41,6 +42,9 @@ public:
|
|||||||
/// Pure virtual function for getting entry name.
|
/// Pure virtual function for getting entry name.
|
||||||
virtual const char * getEntryName() = 0;
|
virtual const char * getEntryName() = 0;
|
||||||
|
|
||||||
|
/// Pure virtual function for getting entry parent name.
|
||||||
|
virtual const char * getEntryParentName() = 0;
|
||||||
|
|
||||||
/// Get the id of the variable.
|
/// Get the id of the variable.
|
||||||
virtual uint16_t getEntryId() = 0;
|
virtual uint16_t getEntryId() = 0;
|
||||||
|
|
||||||
@ -62,6 +66,9 @@ public:
|
|||||||
/// Add an entry to the registry
|
/// Add an entry to the registry
|
||||||
void add(AP_EEPromEntryI * entry, uint16_t & id, uint16_t & address, size_t size);
|
void add(AP_EEPromEntryI * entry, uint16_t & id, uint16_t & address, size_t size);
|
||||||
|
|
||||||
|
/// Print on desired serial port
|
||||||
|
void print(BetterStream & stream);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t _newAddress; /// the address for the next new variable
|
uint16_t _newAddress; /// the address for the next new variable
|
||||||
uint16_t _newId; /// the id of the next new variable
|
uint16_t _newId; /// the id of the next new variable
|
||||||
@ -79,8 +86,8 @@ class AP_EEPromVar : public AP_EEPromEntryI, public AP_Var<type>
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/// The default constrcutor
|
/// The default constrcutor
|
||||||
AP_EEPromVar(type data = 0, const char * name = "", bool sync=false) :
|
AP_EEPromVar(type data = 0, const char * name = "", const char * parentName = "", bool sync=false) :
|
||||||
AP_Var<type>(data,name,sync)
|
AP_Var<type>(data,name,parentName,sync)
|
||||||
{
|
{
|
||||||
eepromRegistry.add(this,_id,_address,sizeof(type));
|
eepromRegistry.add(this,_id,_address,sizeof(type));
|
||||||
}
|
}
|
||||||
@ -88,6 +95,7 @@ public:
|
|||||||
virtual void setEntry(float val) { this->setF(val); }
|
virtual void setEntry(float val) { this->setF(val); }
|
||||||
virtual float getEntry() { return this->getF(); }
|
virtual float getEntry() { return this->getF(); }
|
||||||
virtual const char * getEntryName() { return this->getName(); }
|
virtual const char * getEntryName() { return this->getName(); }
|
||||||
|
virtual const char * getEntryParentName() { return this->getParentName(); }
|
||||||
|
|
||||||
/// Get the id of the variable.
|
/// Get the id of the variable.
|
||||||
virtual uint16_t getEntryId() { return _id; }
|
virtual uint16_t getEntryId() { return _id; }
|
||||||
|
@ -14,6 +14,28 @@
|
|||||||
#include "AP_RcChannel.h"
|
#include "AP_RcChannel.h"
|
||||||
#include <AP_Common.h>
|
#include <AP_Common.h>
|
||||||
|
|
||||||
|
AP_RcChannel::AP_RcChannel(const char * name, const APM_RC_Class & rc, const uint8_t & ch,
|
||||||
|
const float & scale, const float & center,
|
||||||
|
const uint16_t & pwmMin,
|
||||||
|
const uint16_t & pwmNeutral, const uint16_t & pwmMax,
|
||||||
|
const uint16_t & pwmDeadZone,
|
||||||
|
const bool & filter, const bool & reverse) :
|
||||||
|
_name(name),
|
||||||
|
_rc(rc),
|
||||||
|
_ch(new AP_EEPROM_Uint8(ch,"CH",name)),
|
||||||
|
_scale(new AP_EEPROM_Float(scale,"SCALE",name)),
|
||||||
|
_center(new AP_EEPROM_Float(center,"CNTR",name)),
|
||||||
|
_pwmMin(new AP_EEPROM_Uint16(pwmMin,"PMIN",name)),
|
||||||
|
_pwmMax(new AP_EEPROM_Uint16(pwmMax,"PMAX",name)),
|
||||||
|
_pwmNeutral(new AP_EEPROM_Uint16(pwmNeutral,"PNTRL",name)),
|
||||||
|
_pwmDeadZone(new AP_EEPROM_Uint16(pwmDeadZone,"PDEAD",name)),
|
||||||
|
_pwm(0),
|
||||||
|
_filter(new AP_EEPROM_Bool(filter,"FLTR",name)),
|
||||||
|
_reverse(new AP_EEPROM_Bool(reverse,"REV",name))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void AP_RcChannel::readRadio() {
|
void AP_RcChannel::readRadio() {
|
||||||
// apply reverse
|
// apply reverse
|
||||||
uint16_t pwmRadio = APM_RC.InputCh(getCh());
|
uint16_t pwmRadio = APM_RC.InputCh(getCh());
|
||||||
@ -23,8 +45,9 @@ void AP_RcChannel::readRadio() {
|
|||||||
void
|
void
|
||||||
AP_RcChannel::setPwm(uint16_t pwm)
|
AP_RcChannel::setPwm(uint16_t pwm)
|
||||||
{
|
{
|
||||||
|
//Serial.printf("pwm in setPwm: %d\n", pwm);
|
||||||
//Serial.printf("reverse: %s\n", (getReverse())?"true":"false");
|
//Serial.printf("reverse: %s\n", (getReverse())?"true":"false");
|
||||||
|
|
||||||
// apply reverse
|
// apply reverse
|
||||||
if(getReverse()) pwm = int16_t(getPwmNeutral()-pwm) + getPwmNeutral();
|
if(getReverse()) pwm = int16_t(getPwmNeutral()-pwm) + getPwmNeutral();
|
||||||
|
|
||||||
@ -69,8 +92,8 @@ uint16_t
|
|||||||
AP_RcChannel::_positionToPwm(const float & position)
|
AP_RcChannel::_positionToPwm(const float & position)
|
||||||
{
|
{
|
||||||
uint16_t pwm;
|
uint16_t pwm;
|
||||||
float p = position - getCenter();
|
|
||||||
//Serial.printf("position: %f\n", position);
|
//Serial.printf("position: %f\n", position);
|
||||||
|
float p = position - getCenter();
|
||||||
if(p < 0)
|
if(p < 0)
|
||||||
pwm = p * int16_t(getPwmNeutral() - getPwmMin()) /
|
pwm = p * int16_t(getPwmNeutral() - getPwmMin()) /
|
||||||
getScale() + getPwmNeutral();
|
getScale() + getPwmNeutral();
|
||||||
|
@ -24,27 +24,14 @@ public:
|
|||||||
const float & scale=45.0, const float & center=0.0,
|
const float & scale=45.0, const float & center=0.0,
|
||||||
const uint16_t & pwmMin=1200,
|
const uint16_t & pwmMin=1200,
|
||||||
const uint16_t & pwmNeutral=1500, const uint16_t & pwmMax=1800,
|
const uint16_t & pwmNeutral=1500, const uint16_t & pwmMax=1800,
|
||||||
const uint16_t & pwmDeadZone=100,
|
const uint16_t & pwmDeadZone=10,
|
||||||
const bool & filter=false, const bool & reverse=false) :
|
const bool & filter=false, const bool & reverse=false);
|
||||||
_name(name),
|
|
||||||
_rc(rc),
|
|
||||||
_ch(new AP_EEPROM_Uint8(ch,createName("CH"))),
|
|
||||||
_scale(new AP_EEPROM_Float(scale,createName("SCALE"))),
|
|
||||||
_center(new AP_EEPROM_Float(center,createName("CNTR"))),
|
|
||||||
_pwmMin(new AP_EEPROM_Uint16(pwmMin,createName("PMIN"))),
|
|
||||||
_pwmMax(new AP_EEPROM_Uint16(pwmMax,createName("PMAX"))),
|
|
||||||
_pwmNeutral(new AP_EEPROM_Uint16(pwmNeutral,createName("PNTRL"))),
|
|
||||||
_pwmDeadZone(new AP_EEPROM_Uint16(pwmDeadZone,createName("PDEAD"))),
|
|
||||||
_pwm(0),
|
|
||||||
_filter(new AP_EEPROM_Bool(filter,createName("FLTR"))),
|
|
||||||
_reverse(new AP_EEPROM_Bool(reverse,createName("RVRS")))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// set
|
// set
|
||||||
void readRadio();
|
void readRadio();
|
||||||
void setPwm(uint16_t pwm);
|
void setPwm(uint16_t pwm);
|
||||||
void setPosition(float position);
|
void setPosition(float position);
|
||||||
|
void setNormalized(float normPosition) { setPosition(normPosition*getScale()); }
|
||||||
void mixRadio(uint16_t infStart);
|
void mixRadio(uint16_t infStart);
|
||||||
void setCh(const uint8_t & ch) { _ch->set(ch); }
|
void setCh(const uint8_t & ch) { _ch->set(ch); }
|
||||||
void setScale(const float & scale) { _scale->set(scale); }
|
void setScale(const float & scale) { _scale->set(scale); }
|
||||||
@ -75,16 +62,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// createName
|
|
||||||
const char * createName(char * str)
|
|
||||||
{
|
|
||||||
char * newName;
|
|
||||||
strcpy(newName,_name);
|
|
||||||
strcat(newName,"_");
|
|
||||||
strcat(newName,str);
|
|
||||||
return (const char * )newName;
|
|
||||||
}
|
|
||||||
|
|
||||||
// configuration
|
// configuration
|
||||||
const char * _name;
|
const char * _name;
|
||||||
const APM_RC_Class & _rc;
|
const APM_RC_Class & _rc;
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define AP_DISPLAYMEM
|
||||||
#include <FastSerial.h>
|
#include <FastSerial.h>
|
||||||
#include <AP_Common.h>
|
#include <AP_Common.h>
|
||||||
#include <AP_RcChannel.h> // ArduPilot Mega RC Library
|
#include <AP_RcChannel.h> // ArduPilot Mega RC Library
|
||||||
@ -14,22 +15,21 @@
|
|||||||
FastSerialPort0(Serial); // make sure this procees variable declarations
|
FastSerialPort0(Serial); // make sure this procees variable declarations
|
||||||
|
|
||||||
// test settings
|
// test settings
|
||||||
uint8_t nChannels = 1;
|
uint8_t nChannels = 8;
|
||||||
|
|
||||||
// channel configuration
|
// channel configuration
|
||||||
AP_RcChannel rc[] =
|
AP_RcChannel rcCh[] =
|
||||||
{
|
{
|
||||||
AP_RcChannel("ROLL",APM_RC,0,100.0),
|
AP_RcChannel("ROLL",APM_RC,0,100.0),
|
||||||
/*
|
|
||||||
AP_RcChannel("PITCH",APM_RC,1,45),
|
AP_RcChannel("PITCH",APM_RC,1,45),
|
||||||
AP_RcChannel("THR",APM_RC,2,100),
|
AP_RcChannel("THR",APM_RC,2,100),
|
||||||
AP_RcChannel("YAW",APM_RC,3,45),
|
AP_RcChannel("YAW",APM_RC,3,45),
|
||||||
AP_RcChannel("CH5",APM_RC,4,1),
|
AP_RcChannel("CH5",APM_RC,4,1),
|
||||||
AP_RcChannel("CH6",APM_RC,5,1),
|
AP_RcChannel("CH6",APM_RC,5,1),
|
||||||
AP_RcChannel("CH7",APM_tC,6,1),
|
AP_RcChannel("CH7",APM_RC,6,1),
|
||||||
AP_RcChannel("CH8",APM_RC,7,1)
|
AP_RcChannel("CH8",APM_RC,7,1)
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// test position
|
// test position
|
||||||
float testPosition = 0;
|
float testPosition = 0;
|
||||||
int8_t testSign = 1;
|
int8_t testSign = 1;
|
||||||
@ -38,39 +38,43 @@ void setup()
|
|||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("ArduPilot RC Channel test");
|
Serial.println("ArduPilot RC Channel test");
|
||||||
|
|
||||||
|
eepromRegistry.print(Serial); // show eeprom map
|
||||||
APM_RC.Init(); // APM Radio initialization
|
APM_RC.Init(); // APM Radio initialization
|
||||||
|
|
||||||
|
for (int i=0;i<nChannels;i++)
|
||||||
|
{
|
||||||
|
Serial.printf("ch:\t%d\tscale:\t%f\tcenter:\t%f\tpwmMin:\t%d\tpwmNeutral:\t%d\tpwmMax:\t%d\t",
|
||||||
|
rcCh[i].getCh(),rcCh[i].getScale(),rcCh[i].getCenter(),
|
||||||
|
rcCh[i].getPwmMin(),rcCh[i].getPwmNeutral(),rcCh[i].getPwmMax());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// set channel positions
|
// set channel positions
|
||||||
Serial.println("In Loop");
|
for (int i=0;i<nChannels;i++) rcCh[i].setNormalized(testPosition);
|
||||||
|
Serial.printf("\ntestPosition (%f)\n\t\t",testPosition);
|
||||||
for (int i=0;i<nChannels;i++) rc[i].setPosition(testPosition);
|
for (int i=0;i<nChannels;i++) Serial.printf("%7s\t",rcCh[i].getName());
|
||||||
Serial.printf("\ntestPosition (%f)\n",testPosition);
|
|
||||||
for (int i=0;i<nChannels;i++) Serial.printf("%7s\t",rc[i].getName());
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.printf("pwm :\t");
|
Serial.printf("pwm :\t");
|
||||||
for (int i=0;i<nChannels;i++) Serial.printf("%7d\t",rc[i].getPwm());
|
for (int i=0;i<nChannels;i++) Serial.printf("%7d\t",rcCh[i].getPwm());
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.printf("position :\t");
|
Serial.printf("position :\t");
|
||||||
for (int i=0;i<nChannels;i++) Serial.printf("%7.2f\t",rc[i].getPosition());
|
for (int i=0;i<nChannels;i++) Serial.printf("%7.2f\t",rcCh[i].getPosition());
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
// update test value
|
// update test value
|
||||||
for (int i=0;i<nChannels;i++)
|
testPosition += testSign*.05;
|
||||||
|
if (testPosition > 1)
|
||||||
{
|
{
|
||||||
testPosition += testSign*.05;
|
testPosition = 1;
|
||||||
if (testPosition > 1)
|
testSign = -1;
|
||||||
{
|
}
|
||||||
testPosition = 1;
|
else if (testPosition < -1)
|
||||||
testSign = -1;
|
{
|
||||||
}
|
testPosition = -1;
|
||||||
else if (testPosition < -1)
|
testSign = 1;
|
||||||
{
|
|
||||||
testPosition = -1;
|
|
||||||
testSign = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(500);
|
delay(500);
|
||||||
|
Loading…
Reference in New Issue
Block a user