7 #ifndef RC_ROBOTINTERFACE_H
8 #define RC_ROBOTINTERFACE_H
11 #include <robotcontrol/model/robotmodel.h>
12 #include <robotcontrol/hw/hardwareinterface.h>
13 #include <robotcontrol/hw/magfilter.h>
14 #include <robotcontrol/FadeTorqueAction.h>
15 #include <rc_utils/attitude_estimator.h>
16 #include <rc_utils/angle_estimator.h>
17 #include <rc_utils/firfilter.h>
18 #include <rc_utils/golay.h>
19 #include <robotcontrol/ServoDiag.h>
20 #include <rc_utils/low_pass_filter.h>
21 #include <rc_utils/spike_filter.h>
22 #include <nimbro_op_interface/Buzzer.h>
23 #include <nimbro_op_interface/LEDCommand.h>
24 #include <nimbro_op_interface/ReadOffset.h>
25 #include <nimbro_op_interface/AttEstCalib.h>
26 #include <nimbro_op_interface/CalibGyroStop.h>
27 #include <nimbro_op_interface/CalibGyroStart.h>
28 #include <nimbro_op_interface/CalibGyroReturn.h>
29 #include <nimbro_op_interface/CalibGyroAccNow.h>
30 #include <nimbro_op_interface/CalibGyroAccStop.h>
31 #include <actionlib/client/simple_action_client.h>
32 #include <rrlogger/LoggerHeartbeat.h>
33 #include <config_server/parameter.h>
34 #include <plot_msgs/plot_manager.h>
35 #include <ros/service_server.h>
36 #include <std_srvs/Empty.h>
37 #include <cm730/CM730.h>
38 #include <ros/timer.h>
41 namespace urdf {
class Joint; }
42 namespace robotcontrol
45 class DynamicCommandGenerator;
46 typedef boost::shared_ptr<DynamicCommandGenerator> CommandGeneratorPtr;
50 namespace nimbro_op_interface
82 virtual bool init(robotcontrol::RobotModel* model);
84 virtual boost::shared_ptr<robotcontrol::Joint>
createJoint(
const std::string& name);
85 virtual bool sendJointTargets();
87 virtual bool setStiffness(
float torque);
92 virtual bool initCM730();
93 virtual int readFeedbackData(
bool onlyTryCM730);
94 virtual bool syncWriteJointTargets(
size_t numDevices,
const uint8_t* data);
95 virtual bool syncWriteTorqueEnable(
size_t numDevices,
const uint8_t* data);
96 virtual bool syncWriteTorqueLimit(
size_t numDevices,
const uint8_t* data);
97 virtual bool useModel()
const {
return m_useModel(); }
100 static const double TICKS_PER_RAD = 2048.0 / M_PI;
101 static const double FULL_TORQUE = 1023.0;
102 static const double FULL_EFFORT = 32.0;
103 static const double INT_TO_VOLTS = 0.1;
104 static const double GYRO_SCALE = (M_PI / 180) * (2 * 250) / 65536;
105 static const double ACC_SCALE = (2 * (4 * 9.81)) / 65536;
106 static const double MAG_SCALE = 1 / 820.0;
130 struct CM730LedWriteData
135 } __attribute__((packed));
140 struct CM730BuzzerWriteData
144 } __attribute__((packed));
151 struct JointCmdSyncWriteData
156 uint16_t goal_position;
157 } __attribute__((packed));
164 struct TorqueEnableSyncWriteData
167 uint8_t torque_enable;
168 } __attribute__((packed));
174 struct TorqueLimitSyncWriteData
177 uint16_t torque_limit;
178 } __attribute__((packed));
183 struct StatisticsReadData
187 } __attribute__((packed));
191 const std::string CONFIG_PARAM_PATH;
199 struct DXLJoint :
public robotcontrol::Joint
201 DXLJoint(
const std::string& name);
204 robotcontrol::CommandGeneratorPtr commandGenerator;
207 const std::string CONFIG_PARAM_PATH;
211 config_server::Parameter<std::string> type;
212 config_server::Parameter<int> id;
213 config_server::Parameter<int> tickOffset;
214 config_server::Parameter<bool> invert;
215 config_server::Parameter<bool> readFeedback;
231 robotcontrol::ServoDiag diag;
235 void updateJointSettings(DXLJoint* joint);
236 void setJointFeedbackTime(
const ros::Time stamp);
239 robotcontrol::CommandGeneratorPtr commandGenerator(
const std::string& type);
242 void handleStatistics(
const ros::TimerEvent&);
243 void handleLEDCommand(
const LEDCommandConstPtr& cmd);
246 void handleButton(
int number,
bool longPress);
247 config_server::Parameter<bool> m_buttonPress0;
248 config_server::Parameter<bool> m_buttonPress1;
249 config_server::Parameter<bool> m_buttonPress2;
256 inline DXLJoint* dxlJoint(
size_t idx) {
return (DXLJoint*)
m_model->joint(idx).get(); }
258 void sendCM730LedCommand();
260 void waitForRelaxedServos();
262 DXLJoint* dxlJointForID(
int id);
265 boost::shared_ptr<cm730::CM730> m_board;
268 std::map<std::string, robotcontrol::CommandGeneratorPtr> m_generators;
274 ros::Timer m_statisticsTimer;
280 double m_statVoltage;
283 ros::ServiceServer m_srv_readOffsets;
284 ros::ServiceServer m_srv_readOffset;
285 bool handleReadOffsets(std_srvs::EmptyRequest& req, std_srvs::EmptyResponse& resp);
286 bool handleReadOffset(ReadOffsetRequest& req, ReadOffsetResponse& resp);
289 enum GyroAccOffsetMeasType
298 struct GyroAccOffsetMeas
300 GyroAccOffsetMeasType type;
303 config_server::Parameter<bool> m_resetGyroAccOffset;
304 config_server::Parameter<bool> m_resetMagOffset;
305 config_server::Parameter<float> m_gyroAccFusedYaw;
306 config_server::Parameter<float> m_gyroAccTiltAngle;
307 config_server::Parameter<float> m_gyroAccTiltAxisAngle;
308 config_server::Parameter<bool> m_magFlip;
309 config_server::Parameter<float> m_magFusedYaw;
310 config_server::Parameter<float> m_magTiltAngle;
311 config_server::Parameter<float> m_magTiltAxisAngle;
312 config_server::Parameter<float> m_gyroAccMaxRelAccScale;
313 config_server::Parameter<float> m_gyroAccMinYawAgreement;
314 ros::ServiceServer m_srv_imuOffsetsCalibGyroAccStart;
315 ros::ServiceServer m_srv_imuOffsetsCalibGyroAccNow;
316 ros::ServiceServer m_srv_imuOffsetsCalibGyroAccStop;
317 void handleResetGyroAccOffset();
318 void handleResetMagOffset();
319 bool handleCalibGyroAccStart(std_srvs::EmptyRequest& req, std_srvs::EmptyResponse& resp);
320 bool handleCalibGyroAccNow(CalibGyroAccNowRequest& req, CalibGyroAccNowResponse& resp);
321 bool handleCalibGyroAccStop(CalibGyroAccStopRequest& req, CalibGyroAccStopResponse& resp);
322 bool m_imuOffsetsGACalib;
323 std::vector<GyroAccOffsetMeas> m_imuOffsetsGAData;
326 stateestimation::AttitudeEstimator m_attitudeEstimator;
327 stateestimation::AttitudeEstimator m_attEstNoMag;
328 stateestimation::AttitudeEstimator m_attEstYaw;
329 config_server::Parameter<bool> m_attEstUseFusedMethod;
330 void updateAttEstMethod();
331 config_server::Parameter<float> m_attEstKp;
332 config_server::Parameter<float> m_attEstTi;
333 config_server::Parameter<float> m_attEstKpQuick;
334 config_server::Parameter<float> m_attEstTiQuick;
335 config_server::Parameter<float> m_attEstKpYaw;
336 config_server::Parameter<float> m_attEstKpYawQuick;
337 void updateAttEstPIGains();
338 config_server::Parameter<float> m_attEstMagCalibX;
339 config_server::Parameter<float> m_attEstMagCalibY;
340 config_server::Parameter<float> m_attEstMagCalibZ;
341 void updateAttEstMagCalib();
342 config_server::Parameter<float> m_attEstGyroBiasX;
343 config_server::Parameter<float> m_attEstGyroBiasY;
344 config_server::Parameter<float> m_attEstGyroBiasZ;
345 config_server::Parameter<bool> m_attEstGyroBiasUpdate;
346 config_server::Parameter<bool> m_attEstGyroBiasSetFM;
347 config_server::Parameter<bool> m_attEstGyroBiasSetFSM;
348 Eigen::Vector3f m_attEstGyroBiasLast;
349 void updateAttEstGyroCalib();
350 void setAttEstGyroCalib(
const Eigen::Vector3f& bias);
351 void setAttEstGyroBiasFromMean();
352 void setAttEstGyroBiasFromSmoothMean();
355 ros::ServiceServer m_srv_attEstCalibrate;
356 bool handleAttEstCalibrate(nimbro_op_interface::AttEstCalibRequest& req, nimbro_op_interface::AttEstCalibResponse& resp);
359 stateestimation::AngleEstimator m_angleEstimator;
362 config_server::Parameter<float> m_temperatureLowPassTs;
363 rc_utils::LowPassFilter m_temperatureLowPass;
364 double m_temperature;
365 void updateTempLowPassTs();
368 config_server::Parameter<float> m_voltageLowPassTs;
369 rc_utils::LowPassFilter m_voltageLowPass;
370 bool m_initedVoltage;
372 void updateVoltageLowPassTs();
375 config_server::Parameter<float> m_accLowPassMeanTs;
376 rc_utils::LowPassFilterT<Eigen::Vector3d> m_accLowPassMean;
377 Eigen::Vector3d m_accMean;
378 void updateAccLowPassMeanTs();
381 rc_utils::FIRFilter<9> m_fir_accX;
382 rc_utils::FIRFilter<9> m_fir_accY;
383 rc_utils::FIRFilter<11> m_fir_accZ;
386 config_server::Parameter<bool> m_gyroEnableAutoCalib;
387 config_server::Parameter<float> m_gyroScaleFactorHT;
388 config_server::Parameter<float> m_gyroScaleFactorLT;
389 config_server::Parameter<float> m_gyroTemperatureHigh;
390 config_server::Parameter<float> m_gyroTemperatureLow;
391 config_server::Parameter<float> m_gyroLowPassMeanTs;
392 config_server::Parameter<float> m_gyroLowPassMeanTsHigh;
393 config_server::Parameter<float> m_gyroStabilityBound;
394 config_server::Parameter<float> m_gyroCalibFadeTimeStart;
395 config_server::Parameter<float> m_gyroCalibFadeTimeDur;
396 config_server::Parameter<float> m_gyroCalibTsSlow;
397 config_server::Parameter<float> m_gyroCalibTsFast;
398 rc_utils::LowPassFilterT<Eigen::Vector3d> m_gyroLowPassMean;
399 rc_utils::LowPassFilterT<Eigen::Vector3d> m_gyroVeryLowPassMean;
400 Eigen::Vector3d m_gyroMean;
401 Eigen::Vector3d m_gyroMeanSmooth;
402 unsigned int m_gyroStableCount;
403 bool m_gyroBiasAdjusting;
404 void updateGyroLowPassMeanTs();
405 void updateGyroVeryLowPassMeanTs();
408 bool handleCalibrateGyroStart(nimbro_op_interface::CalibGyroStartRequest& req, nimbro_op_interface::CalibGyroStartResponse& resp);
409 bool handleCalibrateGyroReturn(nimbro_op_interface::CalibGyroReturnRequest& req, nimbro_op_interface::CalibGyroReturnResponse& resp);
410 bool handleCalibrateGyroStop(nimbro_op_interface::CalibGyroStopRequest& req, nimbro_op_interface::CalibGyroStopResponse& resp);
411 bool handleCalibrateGyroAbort(std_srvs::EmptyRequest& req, std_srvs::EmptyResponse& resp);
412 ros::ServiceServer m_srv_calibrateGyroStart;
413 ros::ServiceServer m_srv_calibrateGyroReturn;
414 ros::ServiceServer m_srv_calibrateGyroStop;
415 ros::ServiceServer m_srv_calibrateGyroAbort;
416 int m_gyroCalibrating;
418 int m_gyroCalibNumTurns;
419 int m_gyroCalibLoopCount;
420 int m_gyroCalibLoopCountFirst;
421 int m_gyroCalibUpdateCount;
422 int m_gyroCalibUpdateCountFirst;
423 double m_gyroCalibScaleFactor;
424 double m_gyroCalibInitYaw;
425 double m_gyroCalibInitTemp;
426 double m_gyroCalibMiddleYaw;
427 double m_gyroCalibMiddleTemp;
428 double m_gyroCalibCurYaw;
431 config_server::Parameter<bool> m_useMagnetometer;
432 config_server::Parameter<float> m_magSpikeMaxDelta;
433 rc_utils::SpikeFilter m_magSpikeFilterX;
434 rc_utils::SpikeFilter m_magSpikeFilterY;
435 rc_utils::SpikeFilter m_magSpikeFilterZ;
436 rc_utils::FIRFilter<9> m_magFirFilterX;
437 rc_utils::FIRFilter<9> m_magFirFilterY;
438 rc_utils::FIRFilter<9> m_magFirFilterZ;
439 stateestimation::MagFilter m_magHardIronFilter;
440 void updateMagSpikeMaxDelta();
443 config_server::Parameter<bool> m_useModel;
446 config_server::Parameter<float> m_effortSlopeLimit;
449 config_server::Parameter<float> m_rawStateSlopeLimit;
452 config_server::Parameter<bool> m_useServos;
457 PM_ANGEST_PPITCH = 0,
466 PM_ATTEST_NOMAG_FYAW,
467 PM_ATTEST_NOMAG_FPITCH,
468 PM_ATTEST_NOMAG_FROLL,
469 PM_ATTEST_NOMAG_FHEMI,
470 PM_ATTEST_NOMAG_BIAS_X,
471 PM_ATTEST_NOMAG_BIAS_Y,
472 PM_ATTEST_NOMAG_BIAS_Z,
474 PM_ATTEST_YAW_FPITCH,
477 PM_ATTEST_YAW_BIAS_X,
478 PM_ATTEST_YAW_BIAS_Y,
479 PM_ATTEST_YAW_BIAS_Z,
488 PM_GYROMEAN_SMOOTH_X,
489 PM_GYROMEAN_SMOOTH_Y,
490 PM_GYROMEAN_SMOOTH_Z,
491 PM_GYROMEAN_SMOOTH_N,
496 PM_GYRO_SCALE_FACTOR,
527 plot_msgs::PlotManagerFS m_PM;
528 config_server::Parameter<bool> m_plotRobotInterfaceData;
529 void configurePlotManager();
532 ros::Publisher m_pub_buttons;
535 ros::Publisher m_pub_led_state;
538 actionlib::SimpleActionClient<robotcontrol::FadeTorqueAction> m_act_fadeTorque;
541 enum ButtonPressState
550 uint8_t m_lastButtons;
551 ros::Time m_buttonTime0;
552 ros::Time m_buttonTime1;
553 ros::Time m_buttonLastRec0;
554 ButtonPressState m_buttonState0;
555 ButtonPressState m_buttonState1;
556 config_server::Parameter<bool> m_showButtonPresses;
559 std::vector<int> m_cm730_queryset;
563 int m_totalFailCount;
564 int m_consecFailCount;
565 int m_commsSuspCount;
567 int m_lastFailCountSev;
568 int m_lastCommsSuspCount;
569 bool m_enableCommsSusp;
570 ros::Time m_timeLastFailCount;
571 ros::Time m_timeLastFailCountSev;
572 ros::Time m_timeLastCommsSusp;
573 ros::Time m_timeLastSuspCheck;
574 config_server::Parameter<bool> m_showServoFailures;
579 ros::Time m_lastSensorTime;
580 ros::Time m_lastCM730Time;
583 LEDCommand m_ledCommand;
586 ros::Subscriber m_sub_led;
587 config_server::Parameter<bool> m_robPause;
590 ros::Subscriber m_sub_buzzer;
591 bool m_haveBuzzerData;
592 CM730BuzzerWriteData m_buzzerData;
593 void handleBuzzerCommand(
const BuzzerConstPtr& cmd);
596 robotcontrol::RobotModel::State m_state_relaxed;
597 robotcontrol::RobotModel::State m_state_setting_pose;
598 actionlib::SimpleActionClient<robotcontrol::FadeTorqueAction> m_fadeTorqueClient;
599 bool m_fadingIsTriggered;
600 void sendFadeTorqueGoal(
float torque);
601 void resetFadingTriggered();
604 void sendLoggerHeartbeat();
605 void sendLoggerHeartbeat(
bool log);
606 ros::Publisher m_pub_logger;
607 rrlogger::LoggerHeartbeat m_loggerMsg;
608 ros::Time m_loggerStamp;
robotcontrol::RobotModel * m_model
The robot model.
Definition: robotinterface.h:109
virtual void getDiagnostics(robotcontrol::DiagnosticsPtr ptr)
Definition: robotinterface.cpp:1888
virtual bool init(robotcontrol::RobotModel *model)
Definition: robotinterface.cpp:435
RobotInterface()
Definition: robotinterface.cpp:109
std::string m_robotTypeStr
Robot type.
Definition: robotinterface.h:121
virtual void deinit()
Definition: robotinterface.cpp:344
virtual boost::shared_ptr< robotcontrol::Joint > createJoint(const std::string &name)
Definition: robotinterface.cpp:356
virtual bool readJointStates()
Definition: robotinterface.cpp:759
virtual ~RobotInterface()
Definition: robotinterface.cpp:337
cm730::BRBoard m_boardData
Bulk read buffer for CM730 feedback (e.g. IMU)
Definition: robotinterface.h:115
std::string m_robotNameStr
Robot name.
Definition: robotinterface.h:118
std::vector< cm730::BRData > m_servoData
Bulk read buffer for servo feedback.
Definition: robotinterface.h:112
Real robot interface.
Definition: robotinterface.h:74