Skip to content

Commit f2d4358

Browse files
HansOerstedsatoshi-ota
authored andcommitted
use the mode to avoid waiting manually. But the 10 seconds delay failed...
Signed-off-by: Zhe Shen <lucidshenzhe@gmail.com>
1 parent 4666525 commit f2d4358

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

Diff for: experiment/unit_step_steer/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ project(unit_step_steer)
44
find_package(autoware_cmake REQUIRED)
55
autoware_package()
66

7+
find_package(autoware_adapi_v1_msgs REQUIRED)
8+
79
add_executable(unit_step_steer src/step_unit_pub.cpp)
810
ament_target_dependencies(unit_step_steer
911
rclcpp
1012
autoware_auto_control_msgs
13+
autoware_adapi_v1_msgs
1114
)
1215

1316
install(TARGETS

Diff for: experiment/unit_step_steer/src/step_unit_pub.cpp

+34-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "rclcpp/rclcpp.hpp"
22
#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
34
#include <limits>
45
#include <chrono>
56
#include "rclcpp/qos.hpp"
@@ -18,42 +19,62 @@ class ControlCommandPublisher : public rclcpp::Node
1819
timer_ = this->create_wall_timer(
1920
std::chrono::milliseconds(100),
2021
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));
2127
}
2228

2329
private:
2430
void publish_control_command()
2531
{
2632
auto control_command = autoware_auto_control_msgs::msg::AckermannControlCommand();
27-
rclcpp::Time now = this->get_clock()->now();
2833

29-
if ((now - start_time_).seconds() < 10.0) {
30-
// For the first 10 seconds, publish zeros
34+
if (operation_mode_ != 2) {
3135
control_command.lateral.steering_tire_angle = 0.0;
3236
control_command.lateral.steering_tire_rotation_rate = 0.0;
3337
control_command.longitudinal.acceleration = 0.0;
3438
control_command.longitudinal.jerk = 0.0;
3539
control_command.longitudinal.speed = 0.001;
40+
start_time_ = this->get_clock()->now();
3641
} 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+
}
4357
}
4458

4559
// 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();
4963

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);
5165
publisher_->publish(control_command);
5266
}
67+
68+
void operation_mode_callback(const autoware_adapi_v1_msgs::msg::OperationModeState::SharedPtr msg)
69+
{
70+
operation_mode_ = msg->mode;
71+
}
5372

5473
rclcpp::Publisher<autoware_auto_control_msgs::msg::AckermannControlCommand>::SharedPtr publisher_;
5574
rclcpp::TimerBase::SharedPtr timer_;
5675
rclcpp::Time start_time_;
76+
rclcpp::Subscription<autoware_adapi_v1_msgs::msg::OperationModeState>::SharedPtr operation_mode_subscriber_;
77+
int operation_mode_{0};
5778
};
5879

5980
int main(int argc, char* argv[])

0 commit comments

Comments
 (0)