Go to the documentation of this file.
2 #include <rokubimini_msgs/Reading.h>
6 #include <diagnostic_msgs/DiagnosticArray.h>
40 if (!
implPtr_->parseCommunicationMsgs())
42 ROS_ERROR(
"[%s] Failed to parse communication messages",
name_.c_str());
46 ROS_WARN(
"[%s] Invalid product name '%s' given, didn't match the actual product name of the device: '%s'",
63 <<
" Hz, based on time step.");
127 return implPtr_->getSerialNumber(serialNumber);
132 return implPtr_->getForceTorqueSamplingRate(samplingRate);
137 return implPtr_->setForceTorqueFilter(filter);
142 return implPtr_->setAccelerationFilter(filter);
147 return implPtr_->setAngularRateFilter(filter);
152 return implPtr_->setAccelerationRange(range);
157 return implPtr_->setAngularRateRange(range);
162 return implPtr_->setForceTorqueOffset(forceTorqueOffset);
167 if (!
implPtr_->setSensorConfiguration(sensorConfiguration))
177 if (!
implPtr_->setSensorCalibration(sensorCalibration))
197 return implPtr_->saveConfigParameter();
212 return implPtr_->setHardwareReset();
226 nh_->getNamespace() +
"/" +
getName() +
"/ft_sensor_readings/reading", 10,
false));
229 nh_->getNamespace() +
"/" +
getName() +
"/ft_sensor_readings/wrench", 10,
false));
232 nh_->getNamespace() +
"/" +
getName() +
"/ft_sensor_readings/temperature", 10,
false));
234 std::make_shared<ros::Publisher>(
nh_->advertise<diagnostic_msgs::DiagnosticArray>(
"/diagnostics", 10,
false));
243 rokubimini_msgs::Reading reading_msg;
244 reading_msg.header.stamp = reading.getWrench().header.stamp;
245 reading_msg.header.frame_id = reading.getWrench().header.frame_id;
246 reading_msg.statusword = reading.getStatusword().getData();
247 reading_msg.wrench = reading.getWrench();
248 reading_msg.isForceTorqueSaturated = reading.isForceTorqueSaturated();
249 reading_msg.temperature = reading.getTemperature();
289 std::this_thread::sleep_for(std::chrono::microseconds(500));
290 kill(getpid(), SIGINT);
294 rokubimini_msgs::FirmwareUpdateSerial::Response& response)
301 shutdown_thread.detach();
307 rokubimini_msgs::ResetWrench::Response& response)
309 ROS_INFO(
"[%s] Reseting sensor measurements...",
name_.c_str());
311 bool success =
false;
312 unsigned int count = 0;
313 Eigen::Matrix<double, 6, 1> new_offset;
315 while (!success and count < 8)
329 ROS_ERROR(
"[%s] Device could not switch to config mode",
name_.c_str());
333 geometry_msgs::Wrench wrench;
334 Eigen::Matrix<double, 6, 1> mean_wrench;
339 wrench.force.x = mean_wrench(0, 0);
340 wrench.force.y = mean_wrench(1, 0);
341 wrench.force.z = mean_wrench(2, 0);
342 wrench.torque.x = mean_wrench(3, 0);
343 wrench.torque.y = mean_wrench(4, 0);
344 wrench.torque.z = mean_wrench(5, 0);
347 geometry_msgs::Wrench desired_wrench = request.desired_wrench;
350 new_offset(0, 0) = desired_wrench.force.x - wrench.force.x + current_offset(0, 0);
351 new_offset(1, 0) = desired_wrench.force.y - wrench.force.y + current_offset(1, 0);
352 new_offset(2, 0) = desired_wrench.force.z - wrench.force.z + current_offset(2, 0);
353 new_offset(3, 0) = desired_wrench.torque.x - wrench.torque.x + current_offset(3, 0);
354 new_offset(4, 0) = desired_wrench.torque.y - wrench.torque.y + current_offset(4, 0);
355 new_offset(5, 0) = desired_wrench.torque.z - wrench.torque.z + current_offset(5, 0);
357 <<
"New offset is: " << new_offset);
360 ROS_ERROR(
"[%s] Could not write new offset to device",
name_.c_str());
366 ROS_ERROR(
"[%s] Device could not switch to run mode",
name_.c_str());
388 Eigen::Vector3d forceError;
389 forceError << mean_wrench(0, 0) - desired_wrench.force.x, mean_wrench(1, 0) - desired_wrench.force.y,
390 mean_wrench(2, 0) - desired_wrench.force.z;
391 if (forceError.norm() > 0.2)
397 Eigen::Vector3d torqueError;
398 torqueError << mean_wrench(3, 0) - desired_wrench.torque.x, mean_wrench(4, 0) - desired_wrench.torque.y,
399 mean_wrench(5, 0) - desired_wrench.torque.z;
400 if (torqueError.norm() > 0.01)
409 ROS_INFO(
"[%s] Sensor measurements are reset successfully",
name_.c_str());
421 implPtr_->updateConnectionStatus(stat);
427 unsigned int serial_number;
428 implPtr_->getSerialNumber(serial_number);
451 implPtr_->createDataFlagsDiagnostics(stat);
455 stat.name =
nh_->getNamespace().substr(1) +
": " +
getName() +
": Data Flags";
457 unsigned int serial_number;
459 stat.hardware_id = std::to_string(serial_number);
461 diagnostic_msgs::DiagnosticArray diagnostics_array;
462 diagnostics_array.status.emplace_back(stat);
const std::string response
#define ROS_ERROR_THROTTLE(period,...)
bool setForceTorqueFilter(const configuration::ForceTorqueFilter &filter) override
Sets a force torque filter to the device.
void publishConnectionStatusDiagnostics()
Publishes the Connection Status Diagnostics to the "/diagnostics" topic.
bool loadConfig()
Loads the configuration of the device.
std::atomic< bool > statuswordRequested_
RosPublisherPtr dataFlagsDiagnosticsPublisher_
void createRosPublishers() override
Adds ROS publishers related to the device.
bool resetWrenchCallback(rokubimini_msgs::ResetWrench::Request &request, rokubimini_msgs::ResetWrench::Response &response)
The callback for the reset wrench ROS service.
configuration::Configuration & getConfiguration()
void publishRosDiagnostics() override
Publish ROS diagnostics related to the operation of rokubimini.
RokubiminiSerialImplPtr implPtr_
The pointer to implementation.
geometry_msgs::WrenchStamped RokubiminiWrenchRos
bool deviceIsMissing() const override
Checks if the device is missing.
void updateProcessReading() override
Updates the RokubiminiSerial object with new measurements.
bool init()
Initializes communication with a Rokubimini Serial device.
RosPublisherPtr wrenchPublisher_
The sensor_msgs::Wrench publisher.
Eigen::Matrix< double, 6, 6 > & getCalibrationMatrix()
std::string getName() const
bool setAngularRateFilter(const unsigned int filter) override
Sets an angular rate filter to the device.
void createRosDiagnostics() override
Adds ROS diagnostics related to the operation of rokubimini.
std::thread publishingThread_
The thread that publishes the sensor messages to ROS.
TimerPtr dataFlagsDiagnosticsTimer_
Reading getReading() const
rokubimini_msgs::Reading RokubiminiReadingRos
void setSensorConfiguration(const SensorConfiguration &sensorConfiguration)
const Statusword & getStatusword() const
#define ROS_DEBUG_STREAM(args)
bool publishersSet_
Flag to check whether publishers are ready.
Eigen::Matrix< double, 6, Eigen::Dynamic > resetServiceWrenchSamples_
The wrench samples used by the "reset service" callback for calculating the mean wrench offset.
bool setAccelerationRange(const unsigned int range) override
Sets an acceleration range to the device.
bool setSensorCalibration(const calibration::SensorCalibration &sensorCalibration) override
Sets a sensor calibration to the device.
#define ROS_WARN_STREAM(args)
bool setConfigMode()
Sets the device in config mode.
void postSetupConfiguration() override
Post-setup configuration hook.
std::atomic< bool > computeMeanWrenchFlag_
The flag for enabling the computation of the mean of the wrench measurements. Used withing the "reset...
void shutdownWithCommunication() override
Shuts down a Rokubimini Serial device before communication has been closed.
ros::ServiceServer resetWrenchService_
The service for resetting the sensor wrench measurements.
const Eigen::Matrix< double, 6, 1 > & getForceTorqueOffset() const
void signalShutdown()
Signals shutdown for the ROS node. It's used if a firmware update was successful.
void publishRosMessages() override
Publishes ROS messages with data from the rokubimini device.
bool rosDiagnosticsSet_
Flag to check whether ros diagnostics are ready.
bool setRunMode()
Sets the device in run mode.
void setSensorCalibration(const calibration::SensorCalibration &sensorCalibration)
bool firmwareUpdateCallback(rokubimini_msgs::FirmwareUpdateSerial::Request &request, rokubimini_msgs::FirmwareUpdateSerial::Response &response)
The callback for the firmware update ROS service.
bool setPublishMode(double timeStep)
Sets the publishing mode (synchronous or async) of the serial device.
void preSetupConfiguration() override
Post-setup configuration hook.
void update()
Updates the internal Reading with new measurements and publishes them to ROS.
bool setForceTorqueOffset(const Eigen::Matrix< double, 6, 1 > &forceTorqueOffset) override
Sets a force torque offset to the device.
bool getSerialNumber(unsigned int &serialNumber) override
Gets the serial number of the device.
DiagnosticsUpdaterPtr connectionStatusUpdater_
RosPublisherPtr temperaturePublisher_
The sensor_msgs::Temperature publisher.
bool saveConfigParameter() override
Saves the current configuration to the device.
bool setAngularRateRange(const unsigned int range) override
Sets an angular rate range to the device.
bool setAccelerationFilter(const unsigned int filter) override
Sets an acceleration filter to the device.
uint64_t noFrameSyncCounter_
The counter for measuring failed frame synchronizations.
void updateConnectionStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
Updates the Connection Status of the device and adds it to the diagnostics status.
void setStatusword(Statusword &statusword)
const calibration::SensorCalibration & getSensorCalibration() const
RosPublisherPtr readingPublisher_
The rokubimini_msgs::Reading publisher.
bool printUserConfig()
Prints all the user configurable parameters.
void createRosServices() override
Adds ROS services related to the device.
sensor_msgs::Temperature RokubiminiTemperatureRos
configuration::Configuration configuration_
std::recursive_mutex readingMutex_
void publishDataFlagsDiagnostics(const ros::TimerEvent &event)
Publishes the Data Flags Diagnostics to the "/diagnostics" topic.
void setForceTorqueOffset(const Eigen::Matrix< double, 6, 1 > &forceTorqueOffset)
void parseCommunicationMsgs()
Parses the incoming communication msgs from the device.
bool getForceTorqueSamplingRate(int &samplingRate) override
Gets the force torque sampling rate of the device.
const static uint32_t TOTAL_NUMBER_OF_WRENCH_MESSAGES
std::recursive_mutex meanWrenchOffsetMutex_
The mutex for accessing the mean of the wrench measurements. Used for the "reset service" callback.
bool setInitMode()
Triggers a software reset of the sensor bringing it to a known state.
bool setSensorConfiguration(const configuration::SensorConfiguration &sensorConfiguration) override
Sets a sensor configuration to the device.
std::atomic< uint32_t > wrenchMessageCount_
The counter that is used for the computation of the mean of the wrench measurements....
bool setHardwareReset()
Triggers a hardware reset of the sensor.
ros::ServiceServer firmwareUpdateService_
The service for firmware updates.