added exception for invalid function calls from interface

This commit is contained in:
Ruixiang Du
2021-07-19 09:52:26 +08:00
parent 90d34480be
commit c053d73222
2 changed files with 15 additions and 4 deletions

View File

@@ -65,22 +65,34 @@ class RobotCommonInterface {
// functions to be implemented by class AgilexBase // functions to be implemented by class AgilexBase
virtual void SetMotionMode(uint8_t mode){}; virtual void SetMotionMode(uint8_t mode){};
virtual CoreStateMsgGroup GetRobotCoreStateMsgGroup() { virtual CoreStateMsgGroup GetRobotCoreStateMsgGroup() {
throw std::runtime_error(
"Only a derived version of this function with actual implementation "
"is supposed to be used.");
return CoreStateMsgGroup{}; return CoreStateMsgGroup{};
}; };
virtual ActuatorStateMsgGroup GetActuatorStateMsgGroup() { virtual ActuatorStateMsgGroup GetActuatorStateMsgGroup() {
throw std::runtime_error(
"Only a derived version of this function with actual implementation "
"is supposed to be used.");
return ActuatorStateMsgGroup{}; return ActuatorStateMsgGroup{};
}; };
// any specific robot will use a specialized version of the two functions // any specific robot will use a specialized version of the two functions
virtual void SendMotionCommand(double linear_vel, double angular_vel, virtual void SendMotionCommand(double linear_vel, double angular_vel,
double lateral_velocity, double lateral_velocity,
double steering_angle){ double steering_angle) {
// use derived version throw std::runtime_error(
"Only a derived version of this function with actual implementation "
"is supposed to be used.");
}; };
virtual void SendLightCommand(LightMode front_mode, virtual void SendLightCommand(LightMode front_mode,
uint8_t front_custom_value, LightMode rear_mode, uint8_t front_custom_value, LightMode rear_mode,
uint8_t rear_custom_value){}; uint8_t rear_custom_value) {
throw std::runtime_error(
"Only a derived version of this function with actual implementation "
"is supposed to be used.");
};
}; };
} // namespace westonrobot } // namespace westonrobot

View File

@@ -56,7 +56,6 @@ class ScoutMiniOmniRobot : public ScoutRobot, public ScoutOmniInterface {
private: private:
using ScoutRobot::SetMotionCommand; using ScoutRobot::SetMotionCommand;
// void SetMotionCommand(double linear_vel, double angular_vel) = delete;
}; };
} // namespace westonrobot } // namespace westonrobot