5 this->m_heartbeat_manual_subscriber =
7 &DMSController::heartbeatManualCallback,
this);
8 this->m_heartbeat_autonomous_subscriber =
10 &DMSController::heartbeatAutonomousCallback,
this);
11 this->m_emergencystop_subscriber =
12 this->m_node_handle.subscribe<std_msgs::Time>(
TOPIC_EMERGENCYSTOP, 1, &DMSController::emergencystopCallback,
14 this->m_drive_mode_publisher = this->m_node_handle.advertise<std_msgs::Int32>(
TOPIC_DRIVE_MODE, 1);
15 this->m_command_emergencystop_publisher =
17 this->configureParameters();
18 this->m_last_heartbeat_manual = ros::Time();
19 this->m_last_heartbeat_autonomous = ros::Time();
20 this->m_last_emergencystop = ros::Time();
25 ros::Rate loop(this->m_update_frequency);
28 this->publishDriveMode();
29 this->publishCommandEmergencyStop();
39 return this->m_mode_override;
42 auto current_time = ros::Time::now();
43 if (this->m_last_heartbeat_manual + this->m_expiration_time > current_time &&
44 this->m_last_heartbeat_manual < current_time)
48 if (this->m_last_heartbeat_autonomous + this->m_expiration_time > current_time &&
49 this->m_last_heartbeat_autonomous < current_time)
56 void DMSController::publishDriveMode()
58 std_msgs::Int32 drive_mode_message;
59 drive_mode_message.data = (int)this->getDriveMode();
60 this->m_drive_mode_publisher.publish(drive_mode_message);
63 bool DMSController::getEmergencyStop()
65 auto current_time = ros::Time::now();
66 return (!this->m_last_emergencystop.is_zero() &&
67 this->m_last_emergencystop + this->m_emergencystop_expiration_time > current_time &&
68 this->m_last_emergencystop < current_time);
71 void DMSController::publishCommandEmergencyStop()
73 std_msgs::Bool emergency_stop_message;
74 emergency_stop_message.data = this->getEmergencyStop();
75 this->m_command_emergencystop_publisher.publish(emergency_stop_message);
78 void DMSController::heartbeatManualCallback(
const std_msgs::Time::ConstPtr&
message)
80 this->m_last_heartbeat_manual = message->data;
83 void DMSController::heartbeatAutonomousCallback(
const std_msgs::Time::ConstPtr&
message)
85 this->m_last_heartbeat_autonomous = message->data;
88 void DMSController::emergencystopCallback(
const std_msgs::Time::ConstPtr&
message)
90 this->m_last_emergencystop = message->data;
93 void DMSController::configureParameters()
95 ros::NodeHandle private_node_handle(
"~");
99 if (this->m_update_frequency <= 0 || this->m_update_frequency > 1000)
101 ROS_WARN_STREAM(
"dms_check_rate should be between 0 and 1000. Your value: " << this->m_update_frequency
102 <<
", using default: 20.");
103 this->m_update_frequency = 20;
109 if (expiration_ms <= 0 || expiration_ms > 1000)
111 ROS_WARN_STREAM(
"dms_expiration should be between 0 and 1000. Your value: " << expiration_ms
112 <<
", using default: 100.");
115 this->m_expiration_time = ros::Duration(expiration_ms / 1000.0);
118 int emergencystop_expiration_time;
120 if (emergencystop_expiration_time <= 0 || emergencystop_expiration_time > 10000)
122 ROS_WARN_STREAM(
"emergencystop_expiration should be between 0 and 10000. Your value: " 123 << emergencystop_expiration_time <<
", using default: 3000.");
124 emergencystop_expiration_time = 3000;
126 this->m_emergencystop_expiration_time = ros::Duration(emergencystop_expiration_time / 1000.0);
129 int mode_override_parameter;
132 this->m_mode_override = (
DriveMode)mode_override_parameter;
136 ROS_WARN_STREAM(
"Invalid value for mode override.");
142 ROS_WARN_STREAM(
"Drive Mode Override is enabled. The car will drive even if no key is pressed.");
146 int main(
int argc,
char** argv)
148 ros::init(argc, argv,
"dms_controller");
150 dmsController.
spin();
constexpr const char * TOPIC_DRIVE_MODE
int main(int argc, char **argv)
constexpr const char * TOPIC_HEARTBEAT_MANUAL
constexpr const char * PARAMETER_MODE_OVERRIDE
constexpr const char * TOPIC_HEARTBEAT_AUTONOMOUS
constexpr const char * TOPIC_EMERGENCYSTOP
constexpr const char * PARAMETER_EMERGENCYSTOP_EXPIRATION
constexpr const char * PARAMETER_DMS_CHECK_RATE
constexpr const char * PARAMETER_DMS_EXPIRATION
constexpr DriveMode NO_OVERRIDE
constexpr const char * TOPIC_COMMAND_EMERGENCYSTOP