Go to the documentation of this file.
17 #include <sys/types.h>
19 #include <boost/thread.hpp>
25 #include <condition_variable>
57 uint16_t app_took_too_long : 1;
58 uint16_t overrange : 1;
59 uint16_t invalid_measurements : 1;
60 uint16_t raw_measurements : 1;
101 uint16_t crc16_ccitt;
111 { 0, { 9600, B9600 } },
112 { 1, { 57600, B57600 } },
113 { 2, { 115200, B115200 } },
115 { 3, { 230400, B230400 } },
117 { 4, { 460800, B460800 } }
244 return "Config Mode";
250 return "ERROR: Unrecognized mode state";
259 return "Disconnected";
261 return "Is Connecting";
265 return "ERROR: Unrecognized connection state";
481 const uint8_t& baudRate);
771 return (
static_cast<double>(b.tv_sec - a.tv_sec) +
static_cast<double>(b.tv_nsec - a.tv_nsec) /
NSEC_PER_SEC);
785 return (
static_cast<double>(t.tv_sec) +
static_cast<double>(t.tv_nsec) /
NSEC_PER_SEC);
801 if (
static_cast<uint64_t
>(a.tv_nsec + b.tv_nsec) >=
NSEC_PER_SEC)
803 result.tv_sec = a.tv_sec + b.tv_sec + 1;
808 result.tv_sec = a.tv_sec + b.tv_sec;
809 result.tv_nsec = a.tv_nsec + b.tv_nsec;
837 bool connect(
const std::string& port);
const static uint64_t NSEC_PER_SEC
bool printUserConfig()
Prints all the user configurable parameters.
The status of the sensor data.
unsigned int timeoutCounter_
Timeout counter.
BaudRateStruct baudRate_
The baud rate of the serial communication, as a termios bit mask.
bool readDevice(RxFrame &frame)
Reads a raw measurement frame from the serial-port.
bool setAngularRateFilter(const unsigned int filter)
Sets an angular rate filter to the device.
boost::atomic< ConnectionState > connectionState_
Internal connection state.
std::atomic< DataStatus > currentDataFlagsDiagnostics_
The current Data Flags Diagnostics (Data Status) which is updated when a new frame is published and i...
~RokubiminiSerialImpl()=default
std::ofstream usbStreamOut_
Output stream for the USB file descriptor.
void shutdown()
Shuts down the device. It automatically shuts-down threads and disconnects from serial-port.
unsigned int frameSyncErrorCounter_
Frame sync errors.
bool getForceTorqueSamplingRate(int &samplingRate)
Gets the force torque sampling rate of the device.
std::vector< std::string > getErrorStrings() const
Retrieves detailed error indication.
bool parseRegexWaitTimeout(RokubiminiSerialResponseRegex ®, const double &timeout=1.0)
Parses a regex from the serial sensor input stream.
bool setForceTorqueOffset(const Eigen::Matrix< double, 6, 1 > &forceTorqueOffset)
Sets a force torque offset to the device.
std::string getConnectionStateString() const
std::string getName() const
Accessor for device name.
const static uint8_t MAX_BAUD_RATE_OPTION
std::string getProductName() const
Gets the product name of the device.
std::recursive_mutex serialMutex_
Mutex prohibiting simultaneous access to Serial device.
bool sendCommand(const std::string &command)
Sends a command to the serial device.
boost::thread connectionThread_
Connection thread handle.
bool startup()
This method starts up communication with the device.
bool hasFrameSync()
Returns if there is frame synchronization with the device.
struct __attribute__((__packed__))
bool setCommunicationSetup(const configuration::SensorConfiguration &sensorConfiguration, const uint8_t &dataFormat, const uint8_t &baudRate)
Sets communication setup for the device. This includes setting the temperature compensation,...
bool hasError() const
Checks the connection has errors.
unsigned long frameCrcErrorCounter_
Counter for frames with CRC errors.
bool sendCalibrationMatrixEntry(const uint8_t subId, const double entry)
Sends a calibration matrix entry to device.
const static uint8_t DEFAULT_BAUD_RATE_OPTION
bool setAccelerationFilter(const unsigned int filter)
Sets an acceleration filter to the device.
constexpr static double TIMEOUT_MARGIN
double diffSec(timespec a, timespec b)
Calculates the difference (b-a) of two timespecs in seconds.
uint8_t frameHeader
The frame header value.
void pollingWorker()
Worker threads for polling the sensors.
void getReading(rokubimini::Reading &reading)
Gets the internal reading variable.
Reading serialImplReading_
The internal reading variable. It's used for providing to client code the sensor readings,...
The Rokubimini Serial Implementation class.
The frame transmitted and received via the serial bus.
struct __attribute__((__packed__))
bool connect()
Connects to the Serial-over-USB port.
RxFrame frame_
The internal variable for the receiving frame. This variable represents the raw data received from th...
uint16_t calcCrc16X25(uint8_t *data, int len)
void connectionWorker()
Worker threads for managing sensor connections.
unsigned long pollingSyncErrorCounter_
Internal statistics and error counters.
boost::atomic< bool > isRunning_
Internal flags/indicators.
void updateConnectionStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
Fills the Device Connection Status (ROS diagnostics).
unsigned long frameSuccessCounter_
Correct frames counter.
std::string name_
Name of the sensor.
RokubiminiSerialImpl()=delete
Default constructor is deleted.
unsigned int maxCountOpenSerialPort_
Maximum attempts to open serial port.
std::atomic< bool > runsAsync_
The flag that represents whether the driver runs asynchronously or not.
bool setHardwareReset()
Triggers a hardware reset of the sensor.
bool runsAsync()
Returns if the driver runs asynchronously.
bool firmwareUpdate(const std::string &filePath)
Updates the firmware of the device.
void increaseAndCheckTimeoutCounter()
Increases the timeout counter and checks if it has passed the maximum available timeouts.
void createDataFlagsDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &stat)
Creates the Data Flags Diagnostics status.
void getFrameDataStatus(DataStatus &status)
Gets the latest frame's Data Status.
unsigned long frameReceivedCounter_
Received frame counter.
timespec timespecAdd(timespec a, timespec b)
Calculates the sum of two timespecs.
bool writeSerial(const std::string &str)
Writes an Ascii string to the serial device.
bool isConnecting() const
Checks if device is already in the process of connecting.
bool isRunning()
Returns if the serial driver is running.
bool setForceTorqueFilter(const configuration::ForceTorqueFilter &filter)
Sets a force torque filter to the device.
bool readSerialWaitTimeout(const uint32_t &numChars, std::string &str, const double &timeout=1.0)
Reads a string from the serial device waiting a timeout duration. The number of characters of the str...
bool startPollingThread()
This method starts up the polling thread.
ros::Time frameTimestamp_
ConnectionState getConnectionState() const
Gets the current connection status.
ErrorFlags getErrorFlags() const
Gets the current error status.
const static std::map< uint32_t, BaudRateStruct > CODE_TO_BAUD_RATE_MAP
bool openSerialPort(bool keepOpening)
Opens the serial port.
double readTimeout_
The timeout to read from device (in seconds).
unsigned int maxFrameSyncErrorCounts_
Maximum acceptable frame sync errors.
bool initSerialPort(const std::string &port)
Sets up and initializes the serial port for communication.
void updateDataFlags()
Updates the Data Flags variable currentDataFlagsDiagnostics_.
DataStatus frameDataStatus_
The current frame's Data Status.
std::string port_
The serial port to connect to.
bool setSensorCalibration(const calibration::SensorCalibration &sensorCalibration)
Sets a sensor calibration to the device.
ErrorFlags errorFlags_
Flags to indicate errors in serial communication.
std::ifstream usbStreamIn_
Input stream for the USB file descriptor.
bool setAccelerationRange(const unsigned int range)
Sets an acceleration range to the device.
bool parseAcknowledgement(const char &command_code, const double &timeout=2.0)
Parses the acknowledgement from the serial device.
void setRunsAsync(bool runsAsync)
Sets the runsAsync_ variable.
bool readSerialNoWait(const uint32_t &numChars, std::string &str)
Reads a string from the serial device without waiting. The number of characters of the string is not ...
bool saveConfigParameter()
Saves the current configuration to the device.
std::condition_variable newFrameIsAvailable_
The condition variable that is used between the publishing and the polling thread to synchronize on n...
void updateRead()
This method is called by the BusManager. Each device attached to this bus reads its data from the buf...
bool isInConfigMode() const
Checks if the ModeState is Config Mode.
std::mutex readingMutex_
Mutex prohibiting simultaneous access the internal Reading variable.
uint32_t frameOffset_
The frame offset to start reading (in bytes).
uint16_t crcCcittUpdate(uint16_t crc, uint8_t data)
Implementation function of the CRC16 X25 checksum for the input data.
void updateWrite()
This method is called by the BusManager. Each device attached to the bus writes its data to the buffe...
bool setConfigMode()
Sets the device in config mode.
std::shared_ptr< RokubiminiSerialImpl > RokubiminiSerialImplPtr
boost::atomic< bool > frameSync_
Flag that indicates if the frame is synced.
double timespecToSec(timespec t)
Converts a timespec to seconds.
bool parseCommunicationMsgs(const double &timeout=1.0)
Parses the Communication Messages of the serial sensor.
bool isConnected() const
Checks if the device is connected.
bool dataReady_
This flag is on when new data are ready to be published.
constexpr static double MAXIMUM_ACCEPTABLE_TIMEOUT
bool initSensorCommunication(bool keepOpening)
Initializes communication with the sensor.
void resetDataFlags()
Resets the Data Flags variable currentDataFlagsDiagnostics_.
boost::atomic< int > usbFileDescriptor_
The USB file descriptor.
bool runInThreadedMode_
Flag to indicate whether the driver should setup worker threads at startup.
bool getSerialNumber(unsigned int &serialNumber)
Accessor for device serial number.
boost::thread pollingThread_
Polling thread handle.
bool setInitMode()
Triggers a software reset of the sensor bringing it to a known state.
std::string getModeStateString() const
std::string productName_
The product name of the device.
bool setRunMode()
Sets the device in run mode.
struct __attribute__((__packed__))
RxFrame placeholder_
A placeholder to save unfinished frames.
bool setSensorConfiguration(const configuration::SensorConfiguration &sensorConfiguration)
Sets a sensor configuration to the device.
The main output from the sensors in the device.
boost::atomic< ModeState > modeState_
Mode state of the sensor.
bool clearReadBuffer()
Clears the Read Serial buffer by extracting every character available.
bool setAngularRateRange(const unsigned int range)
Sets an angular rate range to the device.
bool init()
This method initializes internal variables and the device for communication. It connects to the seria...
uint32_t serialNumber_
The serial number of the device.
constexpr static double FTDI_DRIVER_LATENCY
bool loadConfig()
Loads the configuration of the device.
void closeSerialPort()
Closes the serial port.