Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::VNCommonSerial Class Reference

#include <VNCommonSerial.h>

Inheritance diagram for Boardcore::VNCommonSerial:
Collaboration diagram for Boardcore::VNCommonSerial:

Public Types

enum class  CRCOptions : uint8_t { CRC_NO = 0x00 , CRC_ENABLE_8 = 0x08 , CRC_ENABLE_16 = 0x10 }
 

Public Member Functions

 VNCommonSerial (USART &usart, int baudrate, const char *sensorName, CRCOptions crc, const std::chrono::milliseconds timeout)
 Constructor.
 
 ~VNCommonSerial ()
 
bool closeAndReset ()
 Method to reset the sensor to default values and to close the connection. Used if you need to close and re initialize the sensor.
 
bool startHSIEstimator (uint8_t convergeRate)
 Start the real-time hard/soft iron calibration. The algorithm will continue until stopHSIEstimator() is called.
 
bool stopHSIEstimator ()
 Real-time hard/soft iron calibration algorithm is turned off.
 
std::string getHSIEstimatorValues ()
 
bool setMagnetometerCompensation (const Eigen::Matrix3f &c, const Eigen::Vector3f &b)
 Set custom compensation parameters for the magnetometer.
 
bool setAccelerometerCompensation (const Eigen::Matrix3f &c, const Eigen::Vector3f &b)
 Set custom compensation parameters for the accelerometer.
 
bool setGyroscopeCompensation (const Eigen::Matrix3f &c, const Eigen::Vector3f &b)
 Set custom compensation parameters for the gyroscope.
 
bool saveConfiguration ()
 Write the current register settings into non-volatile memory. Once the settings are stored in non-volatile (Flash) memory, the VN module can be power cycled or reset, and the register will be reloaded from non-volatile memory.
 
bool restoreFactorySettings ()
 Restore the VN module’s factory default settings and reset the module.
 

Protected Member Functions

uint8_t calculateChecksum8 (const uint8_t *message, int length)
 Calculate the 8bit checksum on the given array.
 
uint16_t calculateChecksum16 (const uint8_t *message, int length)
 Calculate the 16bit array on the given array.
 
bool verifyChecksum (char *command, int maxLength)
 Method to verify the crc validity of a command.
 
bool disableAsyncMessages (bool waitResponse)
 Disables the async messages that the sensor is default configured to send at 40Hz on startup.
 
bool setCrc (bool waitResponse=true)
 Sets the user selected crc method.
 
void configDefaultSerialPort ()
 Configures the default serial communication.
 
bool configUserSerialPort ()
 Configures the user defined serial communication.
 
bool verifyModelNumber (const char *expectedModelNumber)
 Verify the model number of the sensor.
 
template<typename T >
bool getBinaryOutput (T &binaryData, const char *const sampleCommand)
 Utility function used to retrieve the binary output from the sensor.
 
uint8_t checkErrorVN (const char *message)
 Check if the message received from the sensor contains an error.
 
bool sendStringCommand (std::string command)
 Sends the command to the sensor with the correct checksum added so '*' symbol is not needed at the end of the string as well as the '$' at the beginning of the command. This function takes into account the time needed for the command to reach the sensor. DO NOT USE THIS FUNCTION IF LOW EXECUTION TIME IS NEEDED (for example when sending the sample command).
 
bool recvStringCommand (char *command, int maxLength)
 Receives a command from the sensor but swaps the first
with a \0 to close the message.
 
bool writeRegister (const std::string &command)
 Utility function used to set a register on the sensor. This function relies on sendStringCommand: DO NOT USE THIS FUNCTION IF LOW EXECUTION TIME IS NEEDED.
 

Protected Attributes

USARTusart
 Serial interface that is needed to communicate with the sensor via ASCII codes.
 
int baudRate
 
CRCOptions crc
 
PrintLogger logger
 
std::array< char, recvStringMaxDimensionrecvString
 Buffer used to store the string received from the sensor.
 
uint8_t recvStringLength = 0
 Actual strlen() of the recvString.
 
bool isInit = false
 

Static Protected Attributes

static const int DEFAULT_BAUDRATE = 115200
 Default baudrate value for the usart communication.
 
static const uint8_t recvStringMaxDimension = 200
 Maximum size of the receiving string.
 

Detailed Description

Definition at line 32 of file VNCommonSerial.h.

Member Enumeration Documentation

◆ CRCOptions

enum class Boardcore::VNCommonSerial::CRCOptions : uint8_t
strong
Enumerator
CRC_NO 
CRC_ENABLE_8 
CRC_ENABLE_16 

Definition at line 35 of file VNCommonSerial.h.

Constructor & Destructor Documentation

◆ VNCommonSerial()

Boardcore::VNCommonSerial::VNCommonSerial ( USART & usart,
int baudrate,
const char * sensorName,
CRCOptions crc,
const std::chrono::milliseconds timeout )

Constructor.

Parameters
usartSerial bus used for the sensor.
BaudRateSelectd baudrate.
sensorNameThe name of the sensor (VN100/VN300/...).
crcChecksum option.
timeoutThe maximum time that will be waited when reading from the sensor.

Definition at line 31 of file VNCommonSerial.cpp.

◆ ~VNCommonSerial()

Boardcore::VNCommonSerial::~VNCommonSerial ( )

Definition at line 39 of file VNCommonSerial.cpp.

Member Function Documentation

◆ calculateChecksum16()

uint16_t Boardcore::VNCommonSerial::calculateChecksum16 ( const uint8_t * message,
int length )
protected

Calculate the 16bit array on the given array.

Parameters
commandCommand on which compute the crc.
lengthArray length.
Returns
The 16 bit CRC16-CCITT error check.

Definition at line 56 of file VNCommonSerial.cpp.

◆ calculateChecksum8()

uint8_t Boardcore::VNCommonSerial::calculateChecksum8 ( const uint8_t * message,
int length )
protected

Calculate the 8bit checksum on the given array.

Parameters
commandCommand on which compute the crc.
lengthArray length.
Returns
The 8 bit checksum.

Definition at line 41 of file VNCommonSerial.cpp.

◆ checkErrorVN()

uint8_t Boardcore::VNCommonSerial::checkErrorVN ( const char * message)
protected

Check if the message received from the sensor contains an error.

Parameters
messageThe message to be checked.
Returns
Returns 0 if no error was found, else returns the actual error code.

Definition at line 270 of file VNCommonSerial.cpp.

◆ closeAndReset()

bool Boardcore::VNCommonSerial::closeAndReset ( )

Method to reset the sensor to default values and to close the connection. Used if you need to close and re initialize the sensor.

Returns
True if operation succeeded.

Definition at line 282 of file VNCommonSerial.cpp.

◆ configDefaultSerialPort()

void Boardcore::VNCommonSerial::configDefaultSerialPort ( )
protected

Configures the default serial communication.

Definition at line 209 of file VNCommonSerial.cpp.

◆ configUserSerialPort()

bool Boardcore::VNCommonSerial::configUserSerialPort ( )
protected

Configures the user defined serial communication.

Returns
True if operation succeeded.

Definition at line 215 of file VNCommonSerial.cpp.

◆ disableAsyncMessages()

bool Boardcore::VNCommonSerial::disableAsyncMessages ( bool waitResponse)
protected

Disables the async messages that the sensor is default configured to send at 40Hz on startup.

Parameters
waitResponseIf true wait for a serial response.
Returns
True if operation succeeded.

Definition at line 130 of file VNCommonSerial.cpp.

◆ getBinaryOutput()

template<typename T >
bool Boardcore::VNCommonSerial::getBinaryOutput ( T & binaryData,
const char *const sampleCommand )
protected

Utility function used to retrieve the binary output from the sensor.

Parameters
binaryDataThe variable that will hold the data.
sampleCommandThe command to be sent to sample data.
Returns
True if operation successful, false otherwise.

Definition at line 313 of file VNCommonSerial.h.

◆ getHSIEstimatorValues()

std::string Boardcore::VNCommonSerial::getHSIEstimatorValues ( )
Returns
The raw string containing the estimated hard and soft iron compensation parameters.

Definition at line 334 of file VNCommonSerial.cpp.

◆ recvStringCommand()

bool Boardcore::VNCommonSerial::recvStringCommand ( char * command,
int maxLength )
protected

Receives a command from the sensor but swaps the first
with a \0 to close the message.

Parameters
commandThe char array which will be filled with the command.
maxLengthMaximum length for the command array.
Returns
True if operation succeeded.

Definition at line 514 of file VNCommonSerial.cpp.

◆ restoreFactorySettings()

bool Boardcore::VNCommonSerial::restoreFactorySettings ( )

Restore the VN module’s factory default settings and reset the module.

Definition at line 428 of file VNCommonSerial.cpp.

◆ saveConfiguration()

bool Boardcore::VNCommonSerial::saveConfiguration ( )

Write the current register settings into non-volatile memory. Once the settings are stored in non-volatile (Flash) memory, the VN module can be power cycled or reset, and the register will be reloaded from non-volatile memory.

Definition at line 398 of file VNCommonSerial.cpp.

◆ sendStringCommand()

bool Boardcore::VNCommonSerial::sendStringCommand ( std::string command)
protected

Sends the command to the sensor with the correct checksum added so '*' symbol is not needed at the end of the string as well as the '$' at the beginning of the command. This function takes into account the time needed for the command to reach the sensor. DO NOT USE THIS FUNCTION IF LOW EXECUTION TIME IS NEEDED (for example when sending the sample command).

Parameters
commandCommand to send.
Returns
True if operation succeeded.

Wait enough to let the message reach the sensor. The wait time is expressed in milliseconds. The baudrate is expressed in bps. As a safety measure 10ms are added to the wait time.

Thus the command size is multiplied by 1000 to obtain milliseconds and by 8 because the baudrate is expressed in bit per second.

Definition at line 463 of file VNCommonSerial.cpp.

◆ setAccelerometerCompensation()

bool Boardcore::VNCommonSerial::setAccelerometerCompensation ( const Eigen::Matrix3f & c,
const Eigen::Vector3f & b )

Set custom compensation parameters for the accelerometer.

Parameters
cThe accelerometer compensation parameters. See the datasheet for details.
bThe accelerometer compensation parameters. See the datasheet for details. Unit of measurement [m/s^2]
Returns
True if operation succeeded.

Definition at line 376 of file VNCommonSerial.cpp.

◆ setCrc()

bool Boardcore::VNCommonSerial::setCrc ( bool waitResponse = true)
protected

Sets the user selected crc method.

Parameters
waitResponseIf true wait for a serial response.
Returns
True if operation succeeded.

Definition at line 153 of file VNCommonSerial.cpp.

◆ setGyroscopeCompensation()

bool Boardcore::VNCommonSerial::setGyroscopeCompensation ( const Eigen::Matrix3f & c,
const Eigen::Vector3f & b )

Set custom compensation parameters for the gyroscope.

Parameters
cThe gyroscope compensation parameters. See the datasheet for details.
bThe gyroscope compensation parameters. See the datasheet for details. Unit of measurement [rad/s]
Returns
True if operation succeeded.

Definition at line 387 of file VNCommonSerial.cpp.

◆ setMagnetometerCompensation()

bool Boardcore::VNCommonSerial::setMagnetometerCompensation ( const Eigen::Matrix3f & c,
const Eigen::Vector3f & b )

Set custom compensation parameters for the magnetometer.

Parameters
cThe hard and soft iron compensation parameters. See the datasheet for details.
bThe hard and soft iron compensation parameters. See the datasheet for details. Unit of measurement [Gauss]
Returns
True if operation succeeded.

Definition at line 365 of file VNCommonSerial.cpp.

◆ startHSIEstimator()

bool Boardcore::VNCommonSerial::startHSIEstimator ( uint8_t convergeRate)

Start the real-time hard/soft iron calibration. The algorithm will continue until stopHSIEstimator() is called.

Parameters
convergeRateControls how quickly the hard/soft iron solution is allowed to converge onto a new solution. Only values between 1 and 5 are allowed. 1 = Solution converges slowly over approximately 60-90 seconds. 5 = Solution converges rapidly over approximately 15-20 seconds.
Returns
True if the algorithm started successfully.

Definition at line 296 of file VNCommonSerial.cpp.

◆ stopHSIEstimator()

bool Boardcore::VNCommonSerial::stopHSIEstimator ( )

Real-time hard/soft iron calibration algorithm is turned off.

Returns
True if the command is accepted by the sensor.

Definition at line 315 of file VNCommonSerial.cpp.

◆ verifyChecksum()

bool Boardcore::VNCommonSerial::verifyChecksum ( char * command,
int maxLength )
protected

Method to verify the crc validity of a command.

Parameters
commandThe char array which contains the command.
maxLengthMaximum length for the command array.
Returns
True if operation succeeded.

Definition at line 74 of file VNCommonSerial.cpp.

◆ verifyModelNumber()

bool Boardcore::VNCommonSerial::verifyModelNumber ( const char * expectedModelNumber)
protected

Verify the model number of the sensor.

Parameters
expectedModelNumberThe expected model number.
Returns
True if the model number received from the sensor corresponds with the expected one.

Definition at line 231 of file VNCommonSerial.cpp.

◆ writeRegister()

bool Boardcore::VNCommonSerial::writeRegister ( const std::string & command)
protected

Utility function used to set a register on the sensor. This function relies on sendStringCommand: DO NOT USE THIS FUNCTION IF LOW EXECUTION TIME IS NEEDED.

Parameters
commandWrite command to be sent to the sensor.
Returns
True if operation succeeded.

Definition at line 534 of file VNCommonSerial.cpp.

Member Data Documentation

◆ baudRate

int Boardcore::VNCommonSerial::baudRate
protected

Definition at line 276 of file VNCommonSerial.h.

◆ crc

CRCOptions Boardcore::VNCommonSerial::crc
protected

Definition at line 278 of file VNCommonSerial.h.

◆ DEFAULT_BAUDRATE

const int Boardcore::VNCommonSerial::DEFAULT_BAUDRATE = 115200
staticprotected

Default baudrate value for the usart communication.

Definition at line 285 of file VNCommonSerial.h.

◆ isInit

bool Boardcore::VNCommonSerial::isInit = false
protected

Definition at line 302 of file VNCommonSerial.h.

◆ logger

PrintLogger Boardcore::VNCommonSerial::logger
protected

Definition at line 280 of file VNCommonSerial.h.

◆ recvString

std::array<char, recvStringMaxDimension> Boardcore::VNCommonSerial::recvString
protected

Buffer used to store the string received from the sensor.

Definition at line 295 of file VNCommonSerial.h.

◆ recvStringLength

uint8_t Boardcore::VNCommonSerial::recvStringLength = 0
protected

Actual strlen() of the recvString.

Definition at line 300 of file VNCommonSerial.h.

◆ recvStringMaxDimension

const uint8_t Boardcore::VNCommonSerial::recvStringMaxDimension = 200
staticprotected

Maximum size of the receiving string.

Definition at line 290 of file VNCommonSerial.h.

◆ usart

USART& Boardcore::VNCommonSerial::usart
protected

Serial interface that is needed to communicate with the sensor via ASCII codes.

Definition at line 275 of file VNCommonSerial.h.


The documentation for this class was generated from the following files: