#include <VNCommonSerial.h>
|
| 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.
|
|
|
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.
|
|
Definition at line 32 of file VNCommonSerial.h.
◆ CRCOptions
Enumerator |
---|
CRC_NO | |
CRC_ENABLE_8 | |
CRC_ENABLE_16 | |
Definition at line 35 of file VNCommonSerial.h.
◆ VNCommonSerial()
Boardcore::VNCommonSerial::VNCommonSerial |
( |
USART & | usart, |
|
|
int | baudrate, |
|
|
const char * | sensorName, |
|
|
CRCOptions | crc, |
|
|
const std::chrono::milliseconds | timeout ) |
Constructor.
- Parameters
-
usart | Serial bus used for the sensor. |
BaudRate | Selectd baudrate. |
sensorName | The name of the sensor (VN100/VN300/...). |
crc | Checksum option. |
timeout | The maximum time that will be waited when reading from the sensor. |
Definition at line 31 of file VNCommonSerial.cpp.
◆ ~VNCommonSerial()
Boardcore::VNCommonSerial::~VNCommonSerial |
( |
| ) |
|
◆ calculateChecksum16()
uint16_t Boardcore::VNCommonSerial::calculateChecksum16 |
( |
const uint8_t * | message, |
|
|
int | length ) |
|
protected |
Calculate the 16bit array on the given array.
- Parameters
-
command | Command on which compute the crc. |
length | Array 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
-
command | Command on which compute the crc. |
length | Array 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
-
message | The 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 |
◆ 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
-
waitResponse | If 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
-
binaryData | The variable that will hold the data. |
sampleCommand | The 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
-
command | The char array which will be filled with the command. |
maxLength | Maximum 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
-
- 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
-
c | The accelerometer compensation parameters. See the datasheet for details. |
b | The 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
-
waitResponse | If 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
-
c | The gyroscope compensation parameters. See the datasheet for details. |
b | The 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
-
c | The hard and soft iron compensation parameters. See the datasheet for details. |
b | The 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
-
convergeRate | Controls 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
-
command | The char array which contains the command. |
maxLength | Maximum 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
-
expectedModelNumber | The 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
-
command | Write command to be sent to the sensor. |
- Returns
- True if operation succeeded.
Definition at line 534 of file VNCommonSerial.cpp.
◆ baudRate
int Boardcore::VNCommonSerial::baudRate |
|
protected |
◆ crc
◆ 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 |
◆ logger
◆ recvString
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 |
◆ recvStringMaxDimension
const uint8_t Boardcore::VNCommonSerial::recvStringMaxDimension = 200 |
|
staticprotected |
◆ 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: