Skip to content

Commit

Permalink
Spaces fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicogene committed Jul 27, 2022
1 parent 0ff458b commit a9f530b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ bool embot::app::application::theIMU::Impl::fill(embot::prot::can::inertial::per

info.canaddress = embot::app::theCANboardInfo::getInstance().cachedCANaddress();


info.x = imuacquisition.data.acc.x;
info.y = imuacquisition.data.acc.y;
info.z = imuacquisition.data.acc.z;
Expand Down Expand Up @@ -528,7 +528,7 @@ bool embot::app::application::theIMU::initialise(Config &config)
embot::hw::bno055::write(pImpl->config.sensor, embot::hw::bno055::Register::AXIS_MAP_SIGN, 0x07, 5*embot::core::time1millisec);
#endif
embot::hw::bno055::set(pImpl->config.sensor, embot::hw::bno055::Mode::NDOF, 5*embot::core::time1millisec);



return true;
Expand Down
124 changes: 62 additions & 62 deletions emBODY/eBcode/arch-arm/embot/hw/embot_hw_bno055.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,28 @@

#include "embot_hw_i2c.h"


namespace embot { namespace hw { namespace bno055 {

struct Config
{ // the addressing of the sensor is given by the bps
uint8_t tbd {0};
uint8_t tbd {0};
constexpr Config() = default;
};
enum class Mode
{
CONFIG = 0,


enum class Mode
{
CONFIG = 0,
ACCONLY = 1, MAGONLY = 2, GYRONLY = 3, ACCMAG = 4, ACCGYRO = 5, MAGGYRO = 6, AMG = 7, // non fusion modes
IMU = 8, COMPASS = 9, M4G = 10, NDOF_FMC_OFF = 11, NDOF = 12, // fusion modes
none = 32, maxnumberof = 13
IMU = 8, COMPASS = 9, M4G = 10, NDOF_FMC_OFF = 11, NDOF = 12, // fusion modes
none = 32, maxnumberof = 13
};
enum class Register
{
CHIP_ID = 0x00, // 7 bytes RO with many info. see embot::hw::bno055::Info


enum class Register
{
CHIP_ID = 0x00, // 7 bytes RO with many info. see embot::hw::bno055::Info
PAGE_ID = 0x07, // 1 byte RW. it changes page. unfortunately there are no registers defined for page 1
DATASET_START = 0x08, // how many as we want: acc + mag + gyr + eul + qua + lia + grv + temp + calibstat + stresult (total = 47 bytes).
ACC_DATA = 0x08, // 6 bytes RO
Expand All @@ -64,44 +64,44 @@ namespace embot { namespace hw { namespace bno055 {
TEMP = 0x34, // 1 byte RO
CALIB_STAT = 0x35, // 1 byte RO in bit pairs: sys|gyr|acc|mag (3 is fully calib, 0 is not calib)
ST_RESULT = 0x36, // 1 byte RO, but only ls nibble: mcu|gyr|mag|acc (1 is ok, 0 is ko)
OPR_MODE = 0x3D,
OPR_MODE = 0x3D,
PWR_MODE = 0x3E,
AXIS_MAP_CONFIG = 0x41,
AXIS_MAP_SIGN = 0x42
};
};

enum class Set
{
A = 6, // acc: 6 bytes (1 Triple<std::uint16_t>)
AMG = 18, // acc+mag+gyr: 18 bytes
AMGE = 24, // acc+mag+gyr+eul: 24 bytes
AMGEQ = 32, // acc+mag+gyr+eul+quat: 32 bytes
AMG = 18, // acc+mag+gyr: 18 bytes
AMGE = 24, // acc+mag+gyr+eul: 24 bytes
AMGEQ = 32, // acc+mag+gyr+eul+quat: 32 bytes
AMGEQL = 38, // acc+mag+gyr+eul+quat+lia: 38 bytes
AMGEQLG = 44, // acc+mag+gyr+eul+quat+lia+grv: 44 bytes
FULL = 47 // acc+mag+gyr+eul+quat+lia+grv+temp+calib+res: 47 bytes
AMGEQLG = 44, // acc+mag+gyr+eul+quat+lia+grv: 44 bytes
FULL = 47 // acc+mag+gyr+eul+quat+lia+grv+temp+calib+res: 47 bytes
};


struct Info
{ // 7 registers from Register::CHIP_ID
std::uint8_t chipID; // RO: 0xA0
std::uint8_t accID; // RO: 0xFB
std::uint8_t magID; // RO: 0x32
std::uint8_t gyrID; // RO: 0x0F
std::uint16_t swREV; // RO:
std::uint8_t blVER; // RO:
std::uint16_t swREV; // RO:
std::uint8_t blVER; // RO:
Info() { clear(); }
void clear() { chipID = 0; accID = 0; magID = 0; gyrID = 0; swREV = 0; blVER = 0; }
void load(void *mem)
{
std::uint8_t *m = reinterpret_cast<std::uint8_t*>(mem);
chipID = m[0]; accID = m[1]; magID = m[2]; gyrID = m[3];
void load(void *mem)
{
std::uint8_t *m = reinterpret_cast<std::uint8_t*>(mem);
chipID = m[0]; accID = m[1]; magID = m[2]; gyrID = m[3];
swREV = m[4] | (static_cast<std::uint16_t>(m[5]) << 8);
blVER = m[6];
}
bool isvalid() { if((0xA0==chipID)&&(0xFB==accID)&&(0x32==magID)&&(0x0F==gyrID)){return true;} return false; }
};

static const float accRES = 0.01f; // = 1/100 [m/(s*s)]
static const float magRES = 0.0625f; // = 1/16 [microTesla]
static const float gyrRES = 0.0625f; // = 1/16 [deg/s]
Expand All @@ -110,10 +110,10 @@ namespace embot { namespace hw { namespace bno055 {
static const float liaRES = 0.01f; // = 1/100 [m/(s*s)]
static const float grvRES = 0.01f; // = 1/100 [m/(s*s)]
static const float tmpRES = 1.0f; // = 1 [Celsius Deg]

struct Data
{ // it holds the Set::FULL lot
embot::core::utils::Triple<std::int16_t> acc; // acc.z = 9.8 means: horizontally placed
embot::core::utils::Triple<std::int16_t> acc; // acc.z = 9.8 means: horizontally placed
embot::core::utils::Triple<std::int16_t> mag;
embot::core::utils::Triple<std::int16_t> gyr;
embot::core::utils::Triple<std::int16_t> eul; // eul.x = 0 means: directed towards NORTH
Expand All @@ -122,9 +122,9 @@ namespace embot { namespace hw { namespace bno055 {
embot::core::utils::Triple<std::int16_t> grv;
std::uint8_t temperature;
std::uint8_t calibstatus;
std::uint8_t systemstatus;
std::uint8_t systemstatus;
Data() { clear(); }
void clear()
void clear()
{
acc.clear();
mag.clear();
Expand All @@ -137,17 +137,17 @@ namespace embot { namespace hw { namespace bno055 {
calibstatus = 0;
systemstatus = 0;
}
void load(void *mem)
void load(void *mem)
{
std::uint8_t *m = reinterpret_cast<std::uint8_t*>(mem);
std::uint8_t *m = reinterpret_cast<std::uint8_t*>(mem);
acc.load(m); mag.load(&m[6]); gyr.load(&m[12]); eul.load(&m[18]);
qua.load(&m[24]);
lia.load(&m[32]); grv.load(&m[38]);
temperature = m[44]; calibstatus = m[45]; systemstatus = m[46];
}
void getACC(embot::core::utils::Triple<float> &a) const { a.x = accRES * acc.x; a.y = accRES * acc.y; a.z = accRES * acc.z; }
void getMAG(embot::core::utils::Triple<float> &a) const { a.x = magRES * mag.x; a.y = magRES * mag.y; a.z = magRES * mag.z; }
void getGYR(embot::core::utils::Triple<float> &a) const { a.x = gyrRES * gyr.x; a.y = gyrRES * gyr.y; a.z = gyrRES * gyr.z; }
void getGYR(embot::core::utils::Triple<float> &a) const { a.x = gyrRES * gyr.x; a.y = gyrRES * gyr.y; a.z = gyrRES * gyr.z; }
void getEUL(embot::core::utils::Triple<float> &a) const { a.x = eulRES * eul.x; a.y = eulRES * eul.y; a.z = eulRES * eul.z; }
void getQUA(embot::core::utils::Quadruple<float> &a) const { a.w = quaRES * qua.w; a.x = quaRES * qua.x; a.y = quaRES * qua.y; a.z = quaRES * qua.z; }
void getLIA(embot::core::utils::Triple<float> &a) const { a.x = liaRES * lia.x; a.y = liaRES * lia.y; a.z = liaRES * lia.z; }
Expand All @@ -157,64 +157,64 @@ namespace embot { namespace hw { namespace bno055 {
std::uint8_t calibrationOfGYR() const { return(embot::core::binary::pair::get(calibstatus, 2)); } // 3 is ok, 1 is not calibrated
std::uint8_t calibrationOfMAG() const { return(embot::core::binary::pair::get(calibstatus, 0)); } // 3 is ok, 1 is not calibrated
//std::uint8_t calibrationOfSYS() const { return(embot::core::binary::pair::get(calibstatus, 4)); } // 3 is ok, 1 is not calibrated BUT ALWAYS ZERO
};
};



bool supported(BNO055 s);

bool initialised(BNO055 s);

// the init() starts the chip, prepares i2c, pings it. if all ok it returns resOK.
// the working mode is however Mode::CONFIG
result_t init(BNO055 s, const Config &config);

// after that init() returns resOK we can check if it is alive. we can specify a timeout
bool isalive(BNO055 s, embot::core::relTime timeout = 3*embot::core::time1millisec);

// we can get info
result_t get(BNO055 s, Info &info, embot::core::relTime timeout = 3*embot::core::time1millisec);

// we can now set a working mode. we can specify a timeout
result_t set(BNO055 s, Mode m, embot::core::relTime timeout = 3*embot::core::time1millisec);

// we must check that nobody is using the sensor, maybe in non-blocking mode some time earlier
bool isacquiring(BNO055 s);

// we check isacquiring() but also if any other device is using i2c bus
bool canacquire(BNO055 s);

// we start acquisition of a set.
// if returns resOK, we know that acquisition is over if it is called oncompletion() or when operationdone() is true;
result_t acquisition(BNO055 s, Set set, const embot::core::Callback &oncompletion = embot::core::Callback(nullptr, nullptr));

result_t acquisition(BNO055 s, Set set, Data &data, const embot::core::Callback &oncompletion = embot::core::Callback(nullptr, nullptr));

// it tells if a previous operation (acquisition, read, write) is over
bool operationdone(BNO055 s);

// ok, now we can read data previously acquired
result_t read(BNO055 s, Data &data);

// and here is acquisition in blocking mode
result_t acquisition(BNO055 s, Set set, Data &data, const embot::core::relTime timeout);
// here are some write() and read() funtions which operate directly on a single register reg

// here are some write() and read() funtions which operate directly on a single register reg


// we write a single byte into a register.
// blocking or non-blocking mode. we check end of oepration either with operationdone() or with the execution of oncompletion().
// blocking or non-blocking mode. we check end of oepration either with operationdone() or with the execution of oncompletion().
result_t write(BNO055 s, embot::hw::bno055::Register reg, std::uint8_t value, const embot::core::relTime timeout);
result_t write(BNO055 s, embot::hw::bno055::Register reg, std::uint8_t value, const embot::core::Callback &oncompletion = embot::core::Callback(nullptr, nullptr));

// we read from register reg, for data.size positions and we place results into data.pointer (which MUST point to at least data.size bytes)
// blocking or non-blocking mode. we check end of oepration either with operationdone() or with the execution of oncompletion().
// blocking or non-blocking mode. we check end of oepration either with operationdone() or with the execution of oncompletion().
result_t read(BNO055 s, embot::hw::bno055::Register reg, embot::core::Data &data, const embot::core::relTime timeout);
result_t read(BNO055 s, embot::hw::bno055::Register reg, embot::core::Data &data, const embot::core::Callback &oncompletion = embot::core::Callback(nullptr, nullptr));


}}} // namespace embot { namespace hw { namespace bno055 {



#endif // include-guard
Expand Down

0 comments on commit a9f530b

Please sign in to comment.