8 ROS_ASSERT_MSG(drive_mode !=
DriveMode::LOCKED,
"Don't define a drive parameter source for the LOCKED mode.");
10 this->m_drive_parameters_subscriber =
11 node_handle->subscribe<drive_msgs::drive_param>(topic, 1, &DriveParametersSource::driveParametersCallback,
13 this->m_drive_mode = drive_mode;
15 this->m_updateCallback = update_callback;
16 this->m_timeout = timeout;
17 this->m_last_update = ros::Time();
20 void DriveParametersSource::driveParametersCallback(
const drive_msgs::drive_param::ConstPtr&
message)
22 this->m_last_update = ros::Time::now();
23 this->m_idle = std::abs(message->velocity) <
IDLE_RANGE && std::abs(message->angle) <
IDLE_RANGE;
24 this->m_updateCallback(
this, message);
29 if (this->m_last_update.is_zero())
33 return this->m_last_update + this->m_timeout < ros::Time::now();
43 return this->m_drive_mode;
constexpr float IDLE_RANGE
bool isOutdated()
Returns true if no update was received for a certain time, determined by the timeout variable...
DriveParametersSource(ros::NodeHandle *node_handle, const char *topic, DriveParameterCallbackFunction update_callback, DriveMode drive_mode, ros::Duration timeout)
Construct a new DriveParametersSource object, subscribes to the topic and stores the parameters into ...
bool isIdle()
Returns true if the last update contained values close to 0 for both steering and throttle...
std::function< void(DriveParametersSource *, const drive_msgs::drive_param::ConstPtr &)> DriveParameterCallbackFunction