17 #include <sys/types.h> 19 #include <boost/thread.hpp> 53 uint16_t app_took_too_long : 1;
54 uint16_t overrange : 1;
55 uint16_t invalid_measurements : 1;
56 uint16_t raw_measurements : 1;
137 RokubiminiSerialImpl(
const std::string& name,
const std::string& port,
const std::uint32_t& baudRate);
363 bool setForceTorqueOffset(
const Eigen::Matrix<double, 6, 1>& forceTorqueOffset);
409 bool setConfigMode();
428 bool setHardwareReset();
453 const uint32_t& baudRate);
463 bool saveConfigParameter();
481 bool printUserConfig();
490 bool firmwareUpdate(
const std::string& filePath);
511 pollingThreadTimeStep_ = timeStep;
536 bool startPollingThread();
547 bool writeSerial(
const std::string& str);
579 return (static_cast<double>(b.tv_sec - a.tv_sec) + static_cast<double>(b.tv_nsec - a.tv_nsec) / NSEC_PER_SEC);
593 return (static_cast<double>(t.tv_sec) + static_cast<double>(t.tv_nsec) / NSEC_PER_SEC);
609 if (static_cast<uint64_t>(a.tv_nsec + b.tv_nsec) >= NSEC_PER_SEC)
611 result.tv_sec = a.tv_sec + b.tv_sec + 1;
612 result.tv_nsec = a.tv_nsec + b.tv_nsec - NSEC_PER_SEC;
616 result.tv_sec = a.tv_sec + b.tv_sec;
617 result.tv_nsec = a.tv_nsec + b.tv_nsec;
645 bool connect(
const std::string& port);
658 bool readDevice(
RxFrame& frame);
670 bool isConnected()
const;
682 bool isConnecting()
const;
693 bool hasError()
const;
704 bool isInConfigMode()
const;
739 std::string getErrorString()
const;
755 bool initSensorCommunication(
bool keepConnecting);
767 std::uint32_t getBaudRateDefinition(
const uint32_t& baudRate);
781 bool initSerialPort(
const std::string& port);
794 uint16_t calcCrc16X25(uint8_t* data,
int len);
807 uint16_t crcCcittUpdate(uint16_t crc, uint8_t data);
815 void connectionWorker();
824 void pollingWorker();
935 uint8_t frameHeader = 0xAA;
1037 boost::atomic<bool> isRunning_;
1047 unsigned long pollingSyncErrorCounter_;
1097 const static uint64_t NSEC_PER_SEC = 1000000000;
bool setAccelerationRange(const unsigned int range)
Sets an acceleration range to the device.
boost::atomic< bool > frameSync_
Flag that indicates if the frame is synced.
void setPollingTimeStep(double timeStep)
Sets the time step of the polling thread in seconds. timeStep The time step in seconds.
The Rokubimini Serial Implementation class.
void updateWrite()
This method is called by the BusManager. Each device attached to the bus writes its data to the buffe...
std::ifstream usbStreamIn_
Input stream for the USB file descriptor.
void updateRead()
This method is called by the BusManager. Each device attached to this bus reads its data from the buf...
boost::atomic< ModeState > modeState_
Mode state of the sensor.
bool setAngularRateRange(const unsigned int range)
Sets an angular rate range to the device.
double timespecToSec(timespec t)
Converts a timespec to seconds.
void init(const M_string &remappings)
unsigned long frameCrcErrorCounter_
Counter for frames with CRC errors.
unsigned long frameReceivedCounter_
Received frame counter.
bool setAccelerationFilter(const unsigned int filter)
Sets an acceleration filter to the device.
void setState(const uint16_t state)
Sets the state of the device in the bus (unused).
std_msgs::Header * header(M &m)
double pollingThreadTimeStep_
If setup, the sensor polling thread will poll at this rate.
std::string getName() const
Accessor for device name.
std::recursive_mutex readingMutex_
Mutex prohibiting simultaneous access the internal Reading variable.
unsigned long frameSuccessCounter_
Correct frames counter.
Reading serialImplReading_
The internal reading variable. It's used for providing to client code the sensor readings, through the getReading () function.
bool useDeviceTimeStamps_
Flag to indicate whether time-stamps should be generated using sensor or system time.
std::string port_
The serial port to connect to.
bool isRunning()
Returns if the serial driver is running.
bool setAngularRateFilter(const unsigned int filter)
Sets an angular rate filter to the device.
unsigned int frameSyncErrorCounter_
Frame sync errors.
timespec timespecAdd(timespec a, timespec b)
Calculates the sum of two timespecs.
bool getForceTorqueSamplingRate(int &samplingRate)
Gets the force torque sampling rate of the device.
bool sendCalibrationMatrixEntry(const uint8_t subId, const double entry)
Sends a calibration matrix entry to device.
struct __attribute__((__packed__))
The status of the sensor data.
RxFrame frame_
The internal variable for the receiving frame. This variable represents the raw data received from th...
std::ofstream usbStreamOut_
Output stream for the USB file descriptor.
std::shared_ptr< RokubiminiSerialImpl > RokubiminiSerialImplPtr
bool waitForState(const uint16_t state)
Wait for a state to be reached (unused).
bool runInThreadedMode_
Flag to indicate whether the driver should setup worker threads at startup.
The frame transmitted and received via the serial bus.
unsigned int maxFrameSyncErrorCounts_
Maximum acceptable frame sync errors.
bool getSerialNumber(unsigned int &serialNumber)
Accessor for device serial number.
ROSCONSOLE_DECL void shutdown()
boost::atomic< ConnectionState > connectionState_
Internal connection state.
bool hasFrameSync()
Returns if there is frame synchronization with the device.
boost::atomic< ErrorState > errorState_
Internal error state.
std::recursive_mutex serialMutex_
Mutex prohibiting simultaneous access to Serial device.
The main output from the sensors in the device.
double diffSec(timespec a, timespec b)
Calculates the difference (b-a) of two timespecs in seconds.
std::string name_
Name of the sensor.
double timeStampSecs_
Sample time-stamp.
boost::thread connectionThread_
Connection thread handle.
boost::atomic< int > usbFileDescriptor_
The USB file descriptor.
std::uint32_t baudRate_
The baud rate of the serial communication.
boost::thread pollingThread_
Polling thread handle.