2 #include <rokubimini_msgs/Reading.h> 6 #include <diagnostic_msgs/DiagnosticArray.h> 53 return slavePtr_->getSerialNumber(serialNumber);
58 return slavePtr_->getForceTorqueSamplingRate(samplingRate);
63 return slavePtr_->setForceTorqueFilter(filter);
68 return slavePtr_->setAccelerationFilter(filter);
73 return slavePtr_->setAngularRateFilter(filter);
78 return slavePtr_->setAccelerationRange(range);
83 return slavePtr_->setAngularRateRange(range);
88 return slavePtr_->setForceTorqueOffset(forceTorqueOffset);
93 if (!
slavePtr_->setSensorConfiguration(sensorConfiguration))
103 if (!
slavePtr_->setSensorCalibration(sensorCalibration))
133 nh_->getNamespace() +
"/" +
getName() +
"/ft_sensor_readings/reading", 10,
false));
136 nh_->getNamespace() +
"/" +
getName() +
"/ft_sensor_readings/wrench", 10,
false));
142 nh_->getNamespace() +
"/" +
getName() +
"/ft_sensor_readings/temperature", 10,
false));
144 std::make_shared<ros::Publisher>(
nh_->advertise<diagnostic_msgs::DiagnosticArray>(
"/diagnostics", 10,
false));
154 rokubimini_msgs::Reading reading_msg;
155 reading_msg.header.stamp = reading.getWrench().header.stamp;
157 reading_msg.statusword = reading.getStatusword().getData();
158 reading_msg.imu = reading.getImu();
159 reading_msg.wrench = reading.getWrench();
160 reading_msg.externalImu = reading.getExternalImu();
161 reading_msg.isForceTorqueSaturated = reading.isForceTorqueSaturated();
162 reading_msg.temperature = reading.getTemperature();
191 std::this_thread::sleep_for(std::chrono::microseconds(500));
192 kill(getpid(), SIGINT);
203 unsigned int serial_number;
226 slavePtr_->createDataFlagsDiagnostics(stat);
230 stat.name =
nh_->getNamespace().substr(1) +
": " +
getName() +
": Data Flags";
232 unsigned int serial_number;
234 stat.hardware_id = std::to_string(serial_number);
236 diagnostic_msgs::DiagnosticArray diagnostics_array;
237 diagnostics_array.status.emplace_back(stat);
244 rokubimini_msgs::FirmwareUpdateEthercat::Response& response)
246 response.result =
slavePtr_->firmwareUpdate(request.file_path, request.file_name, request.password);
251 shutdown_thread.detach();
257 rokubimini_msgs::ResetWrench::Response& response)
259 ROS_INFO(
"[%s] Reseting sensor measurements...",
name_.c_str());
261 bool success =
false;
262 unsigned int count = 0;
263 Eigen::Matrix<double, 6, 1> new_offset;
265 while (!success and count < 8)
278 ROS_ERROR(
"[%s] Device could not switch to config mode",
name_.c_str());
279 response.success =
false;
282 geometry_msgs::Wrench wrench;
283 Eigen::Matrix<double, 6, 1> mean_wrench;
288 wrench.force.x = mean_wrench(0, 0);
289 wrench.force.y = mean_wrench(1, 0);
290 wrench.force.z = mean_wrench(2, 0);
291 wrench.torque.x = mean_wrench(3, 0);
292 wrench.torque.y = mean_wrench(4, 0);
293 wrench.torque.z = mean_wrench(5, 0);
295 geometry_msgs::Wrench desired_wrench = request.desired_wrench;
298 new_offset(0, 0) = desired_wrench.force.x - wrench.force.x + current_offset(0, 0);
299 new_offset(1, 0) = desired_wrench.force.y - wrench.force.y + current_offset(1, 0);
300 new_offset(2, 0) = desired_wrench.force.z - wrench.force.z + current_offset(2, 0);
301 new_offset(3, 0) = desired_wrench.torque.x - wrench.torque.x + current_offset(3, 0);
302 new_offset(4, 0) = desired_wrench.torque.y - wrench.torque.y + current_offset(4, 0);
303 new_offset(5, 0) = desired_wrench.torque.z - wrench.torque.z + current_offset(5, 0);
305 <<
"New offset is: " << new_offset);
308 ROS_ERROR(
"[%s] Could not write new offset to device",
name_.c_str());
309 response.success =
false;
314 ROS_ERROR(
"[%s] Device could not switch to run mode",
name_.c_str());
315 response.success =
false;
336 Eigen::Vector3d forceError;
337 forceError << mean_wrench(0, 0) - desired_wrench.force.x, mean_wrench(1, 0) - desired_wrench.force.y,
338 mean_wrench(2, 0) - desired_wrench.force.z;
339 if (forceError.norm() > 0.2)
345 Eigen::Vector3d torqueError;
346 torqueError << mean_wrench(3, 0) - desired_wrench.torque.x, mean_wrench(4, 0) - desired_wrench.torque.y,
347 mean_wrench(5, 0) - desired_wrench.torque.z;
348 if (torqueError.norm() > 0.01)
356 response.success = success;
357 ROS_INFO(
"[%s] Sensor measurements are reset successfully",
name_.c_str());
368 const std::string& valueTypeString, std::string& valueString)
370 return slavePtr_->sendSdoReadGeneric(indexString, subindexString, valueTypeString, valueString);
374 const std::string& valueTypeString,
const std::string& valueString)
376 return slavePtr_->sendSdoWriteGeneric(indexString, subindexString, valueTypeString, valueString);
383 return slavePtr_->sendSdoReadInt8(index, subindex, completeAccess, value);
390 return slavePtr_->sendSdoReadInt16(index, subindex, completeAccess, value);
397 return slavePtr_->sendSdoReadInt32(index, subindex, completeAccess, value);
404 return slavePtr_->sendSdoReadInt64(index, subindex, completeAccess, value);
411 return slavePtr_->sendSdoReadUInt8(index, subindex, completeAccess, value);
418 return slavePtr_->sendSdoReadUInt16(index, subindex, completeAccess, value);
425 return slavePtr_->sendSdoReadUInt32(index, subindex, completeAccess, value);
432 return slavePtr_->sendSdoReadUInt64(index, subindex, completeAccess, value);
439 return slavePtr_->sendSdoReadFloat(index, subindex, completeAccess, value);
446 return slavePtr_->sendSdoReadDouble(index, subindex, completeAccess, value);
453 return slavePtr_->sendSdoWriteInt8(index, subindex, completeAccess, value);
460 return slavePtr_->sendSdoWriteInt16(index, subindex, completeAccess, value);
467 return slavePtr_->sendSdoWriteInt32(index, subindex, completeAccess, value);
474 return slavePtr_->sendSdoWriteInt64(index, subindex, completeAccess, value);
481 return slavePtr_->sendSdoWriteUInt8(index, subindex, completeAccess, value);
488 return slavePtr_->sendSdoWriteUInt16(index, subindex, completeAccess, value);
495 return slavePtr_->sendSdoWriteUInt32(index, subindex, completeAccess, value);
502 return slavePtr_->sendSdoWriteUInt64(index, subindex, completeAccess, value);
509 return slavePtr_->sendSdoWriteFloat(index, subindex, completeAccess, value);
516 return slavePtr_->sendSdoWriteDouble(index, subindex, completeAccess, value);
void shutdownWithCommunication() override
Shuts down a Rokubimini Ethercat device before communication has been closed.
void preSetupConfiguration() override
Pre-setup configuration hook.
void postSetupConfiguration() override
Post-setup configuration hook.
void createRosDiagnostics() override
Adds ROS diagnostics related to the operation of rokubimini.
std::atomic< uint32_t > wrenchMessageCount_
The counter that is used for the computation of the mean of the wrench measurements. Used for the "reset service" callback.
void setRunsAsync(bool runsAsync)
void createRosPublishers() override
Adds ROS publishers related to the device.
void updateConnectionStatus(diagnostic_updater::DiagnosticStatusWrapper &stat)
Shows the Device Status of the rokubimini.
RokubiminiEthercatSlavePtr slavePtr_
The pointer to implementation.
bool saveConfigParameter() override
Saves the current configuration to the device.
bool sendSdoReadGeneric(const std::string &indexString, const std::string &subindexString, const std::string &valueTypeString, std::string &valueString)
Sends a generic reading SDO to the Ethercat device.
geometry_msgs::WrenchStamped RokubiminiWrenchRos
void setStatusword(Statusword &statusword)
std::string getName() const
void signalShutdown()
Signals shutdown for the ROS node. It's used if a firmware update was successful. ...
bool setAccelerationRange(const unsigned int range) override
Sets an acceleration range to the device.
bool resetWrenchCallback(rokubimini_msgs::ResetWrench::Request &request, rokubimini_msgs::ResetWrench::Response &response)
The callback for the reset wrench ROS service.
void setSensorConfiguration(const SensorConfiguration &sensorConfiguration)
bool setForceTorqueOffset(const Eigen::Matrix< double, 6, 1 > &forceTorqueOffset) override
Sets a force torque offset to the device.
const Statusword & getStatusword() const
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.
sensor_msgs::Temperature RokubiminiTemperatureRos
bool sendSdoWrite(const uint16_t index, const uint8_t subindex, const bool completeAccess, const Value value)
RosPublisherPtr readingPublisher_
The rokubimini_msgs::Reading publisher.
bool setSensorCalibration(const calibration::SensorCalibration &sensorCalibration) override
Sets a sensor calibration to the device.
bool setSensorConfiguration(const configuration::SensorConfiguration &sensorConfiguration) override
Sets a sensor configuration to the device.
bool firmwareUpdateCallback(rokubimini_msgs::FirmwareUpdateEthercat::Request &request, rokubimini_msgs::FirmwareUpdateEthercat::Response &response)
The callback for the firmware update ROS service.
void updateProcessReading() override
Updates the RokubiminiEthercat object with new measurements.
bool setAngularRateFilter(const unsigned int filter) override
Sets an angular rate filter to the device.
bool setAccelerationFilter(const unsigned int filter) override
Sets an acceleration filter to the device.
RosPublisherPtr imuPublisher_
The sensor_msgs::Imu publisher.
const Eigen::Matrix< double, 6, 1 > & getForceTorqueOffset() const
bool getForceTorqueSamplingRate(int &samplingRate) override
Gets the force torque sampling rate of the device.
rokubimini_msgs::Reading RokubiminiReadingRos
sensor_msgs::Imu RokubiminiImuRos
ros::ServiceServer resetWrenchService_
The service for resetting the sensor wrench measurements.
configuration::Configuration configuration_
unsigned __int64 uint64_t
void publishRosDiagnostics() override
Publish ROS diagnostics related to the operation of rokubimini.
void publishDataFlagsDiagnostics(const ros::TimerEvent &event)
Publishes the Data Flags Diagnostics to the "/diagnostics" topic.
bool sendSdoWriteGeneric(const std::string &indexString, const std::string &subindexString, const std::string &valueTypeString, const std::string &valueString)
Sends a generic write SDO to the Ethercat device.
static const uint32_t TOTAL_NUMBER_OF_WRENCH_MESSAGES
void createRosServices() override
Adds ROS services related to the device.
bool setConfigMode()
Sets the device in config mode.
std::atomic< bool > statuswordRequested_
bool setRunMode()
Sets the device in run mode.
void setSensorCalibration(const calibration::SensorCalibration &sensorCalibration)
std::atomic< bool > computeMeanWrenchFlag_
The flag for enabling the computation of the mean of the wrench measurements. Used withing the "reset...
#define ROS_DEBUG_STREAM(args)
std::recursive_mutex meanWrenchOffsetMutex_
The mutex for accessing the mean of the wrench measurements. Used for the "reset service" callback...
Eigen::Matrix< double, 6, Eigen::Dynamic > resetServiceWrenchSamples_
The wrench samples used by the "reset service" callback for calculating the mean wrench offset...
RosPublisherPtr wrenchPublisher_
The sensor_msgs::Wrench publisher.
ros::ServiceServer firmwareUpdateService_
The service for firmware updates.
Reading getReading() const
bool deviceIsMissing() const override
Checks if the device is missing.
DiagnosticsUpdaterPtr connectionStatusUpdater_
void setForceTorqueOffset(const Eigen::Matrix< double, 6, 1 > &forceTorqueOffset)
TimerPtr dataFlagsDiagnosticsTimer_
RosPublisherPtr dataFlagsDiagnosticsPublisher_
bool getSerialNumber(unsigned int &samplingRate) override
Gets the serial number of the device.
RosPublisherPtr temperaturePublisher_
The sensor_msgs::Temperature publisher.
bool sendSdoRead(const uint16_t index, const uint8_t subindex, const bool completeAccess, Value &value)
configuration::Configuration & getConfiguration()
std::recursive_mutex readingMutex_
void publishRosMessages() override
Publishes ROS messages with data from the rokubimini device.
bool setAngularRateRange(const unsigned int range) override
Sets an angular rate range to the device.