1
1
#include " rclcpp/rclcpp.hpp"
2
2
#include " autoware_auto_control_msgs/msg/ackermann_control_command.hpp"
3
+ #include " autoware_adapi_v1_msgs/msg/operation_mode_state.hpp" // src/autoware/autoware_adapi_msgs/autoware_adapi_v1_msgs/operation_mode/msg/OperationModeState.msg
3
4
#include < limits>
4
5
#include < chrono>
5
6
#include " rclcpp/qos.hpp"
@@ -18,42 +19,62 @@ class ControlCommandPublisher : public rclcpp::Node
18
19
timer_ = this ->create_wall_timer (
19
20
std::chrono::milliseconds (100 ),
20
21
std::bind (&ControlCommandPublisher::publish_control_command, this ));
22
+ // Set up the subscriber for the operation mode state
23
+ operation_mode_subscriber_ = this ->create_subscription <autoware_adapi_v1_msgs::msg::OperationModeState>(
24
+ " /api/operation_mode/state" ,
25
+ 10 ,
26
+ std::bind (&ControlCommandPublisher::operation_mode_callback, this , std::placeholders::_1));
21
27
}
22
28
23
29
private:
24
30
void publish_control_command ()
25
31
{
26
32
auto control_command = autoware_auto_control_msgs::msg::AckermannControlCommand ();
27
- rclcpp::Time now = this ->get_clock ()->now ();
28
33
29
- if ((now - start_time_).seconds () < 10.0 ) {
30
- // For the first 10 seconds, publish zeros
34
+ if (operation_mode_ != 2 ) {
31
35
control_command.lateral .steering_tire_angle = 0.0 ;
32
36
control_command.lateral .steering_tire_rotation_rate = 0.0 ;
33
37
control_command.longitudinal .acceleration = 0.0 ;
34
38
control_command.longitudinal .jerk = 0.0 ;
35
39
control_command.longitudinal .speed = 0.001 ;
40
+ start_time_ = this ->get_clock ()->now ();
36
41
} else {
37
- // After 10 seconds, publish the actual values
38
- control_command.lateral .steering_tire_angle = 0.5 ;
39
- control_command.lateral .steering_tire_rotation_rate = std::numeric_limits<double >::infinity ();
40
- control_command.longitudinal .acceleration = 0.0 ; // Set to your desired value
41
- control_command.longitudinal .jerk = 0.0 ; // Set to your desired value
42
- control_command.longitudinal .speed = 0.001 ; // Set to your desired value
42
+ if ((this ->get_clock ()->now () - start_time_).seconds () < 10.0 ) {
43
+ // For the first 10 seconds, publish zeros
44
+ control_command.lateral .steering_tire_angle = 0.0 ;
45
+ control_command.lateral .steering_tire_rotation_rate = 0.0 ;
46
+ control_command.longitudinal .acceleration = 0.0 ;
47
+ control_command.longitudinal .jerk = 0.0 ;
48
+ control_command.longitudinal .speed = 0.001 ;
49
+ } else {
50
+ // After 10 seconds, publish the actual values
51
+ control_command.lateral .steering_tire_angle = 0.5 ;
52
+ control_command.lateral .steering_tire_rotation_rate = std::numeric_limits<double >::infinity ();
53
+ control_command.longitudinal .acceleration = 0.0 ; // Set to your desired value
54
+ control_command.longitudinal .jerk = 0.0 ; // Set to your desired value
55
+ control_command.longitudinal .speed = 0.001 ; // Set to your desired value
56
+ }
43
57
}
44
58
45
59
// Set the time stamp
46
- control_command.stamp = now;
47
- control_command.lateral .stamp = now;
48
- control_command.longitudinal .stamp = now;
60
+ control_command.stamp = this -> get_clock ()-> now () ;
61
+ control_command.lateral .stamp = this -> get_clock ()-> now () ;
62
+ control_command.longitudinal .stamp = this -> get_clock ()-> now () ;
49
63
50
- RCLCPP_INFO (this ->get_logger (), " Publishing control command at time '%u.%09u'" , control_command.stamp .sec , control_command.stamp .nanosec );
64
+ // RCLCPP_INFO(this->get_logger(), "Publishing control command at time '%u.%09u'", control_command.stamp.sec, control_command.stamp.nanosec);
51
65
publisher_->publish (control_command);
52
66
}
67
+
68
+ void operation_mode_callback (const autoware_adapi_v1_msgs::msg::OperationModeState::SharedPtr msg)
69
+ {
70
+ operation_mode_ = msg->mode ;
71
+ }
53
72
54
73
rclcpp::Publisher<autoware_auto_control_msgs::msg::AckermannControlCommand>::SharedPtr publisher_;
55
74
rclcpp::TimerBase::SharedPtr timer_;
56
75
rclcpp::Time start_time_;
76
+ rclcpp::Subscription<autoware_adapi_v1_msgs::msg::OperationModeState>::SharedPtr operation_mode_subscriber_;
77
+ int operation_mode_{0 };
57
78
};
58
79
59
80
int main (int argc, char * argv[])
0 commit comments