Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
vehicle.cpp
Go to the documentation of this file.
2
5
6VehicleAdapter::VehicleAdapter(std::shared_ptr<SENode> se_node) : Adapter(se_node) {
8 this->node_->create_subscription<custom_interfaces::msg::OperationalStatus>(
9 "/vehicle/operational_status", 10,
10 [this](const custom_interfaces::msg::OperationalStatus::SharedPtr msg) {
11 RCLCPP_DEBUG(this->node_->get_logger(),
12 "Operational status received. Mission: %d - Go: %d", msg->as_mission,
13 msg->go_signal);
14 this->node_->_go_ = msg->go_signal;
15 this->node_->_mission_ = common_lib::competition_logic::Mission(msg->as_mission);
16 });
17 this->_yaw_accy_imu_subscription_.subscribe(this->node_, "/vehicle/imu_yaw_acc_y");
18 this->_roll_accx_imu_subscription_.subscribe(this->node_, "/vehicle/imu_roll_acc_x");
19 const ImuPolicy imu_policy(10);
20 this->_imu_sync_ = std::make_shared<message_filters::Synchronizer<ImuPolicy>>(
22 this->_imu_sync_->registerCallback(&VehicleAdapter::imu_subscription_callback, this);
23
24 this->_free_acceleration_subscription_.subscribe(this->node_, "/filter/free_acceleration");
25 this->_angular_velocity_subscription_.subscribe(this->node_, "/imu/angular_velocity");
26 const XsensImuPolicy xsens_imu_policy(10);
27 this->_xsens_imu_sync_ = std::make_shared<message_filters::Synchronizer<XsensImuPolicy>>(
30
31 this->_rl_wheel_rpm_subscription_.subscribe(this->node_, "/vehicle/rl_rpm");
32 this->_rr_wheel_rpm_subscription_.subscribe(this->node_, "/vehicle/rr_rpm");
33 this->_steering_angle_subscription_.subscribe(this->node_, "/vehicle/bosch_steering_angle");
34 const WheelSteerPolicy policy(10);
35 this->_sync_ = std::make_shared<message_filters::Synchronizer<WheelSteerPolicy>>(
38 this->_sync_->registerCallback(&VehicleAdapter::wheel_speeds_subscription_callback, this);
39
40 this->_finished_client_ =
41 this->node_->create_client<std_srvs::srv::Trigger>("/as_srv/mission_finished");
42}
43
45 const custom_interfaces::msg::WheelRPM& rl_wheel_rpm_msg,
46 const custom_interfaces::msg::WheelRPM& rr_wheel_rpm_msg,
47 const custom_interfaces::msg::SteeringAngle& steering_angle_msg) {
48 RCLCPP_INFO(this->node_->get_logger(), "Received WSS!");
49
50 this->node_->_wheel_speeds_subscription_callback(rl_wheel_rpm_msg.rl_rpm, rr_wheel_rpm_msg.rr_rpm,
51 0.0, 0.0, steering_angle_msg.steering_angle,
52 steering_angle_msg.header.stamp);
53}
54
56 const custom_interfaces::msg::ImuData& roll_accx_data,
57 const custom_interfaces::msg::ImuData& yaw_accy_data) {
58 auto imu_msg = sensor_msgs::msg::Imu();
59 imu_msg.angular_velocity.z = yaw_accy_data.gyro;
60 imu_msg.linear_acceleration.x = roll_accx_data.acc;
61 imu_msg.linear_acceleration.y = yaw_accy_data.acc;
62 this->node_->_imu_subscription_callback(imu_msg);
63}
64
66 const geometry_msgs::msg::Vector3Stamped::SharedPtr& free_acceleration_msg,
67 const geometry_msgs::msg::Vector3Stamped::SharedPtr& angular_velocity_msg) {
68 auto imu_msg = sensor_msgs::msg::Imu();
69 imu_msg.angular_velocity.z = angular_velocity_msg->vector.z;
70 imu_msg.linear_acceleration.x = free_acceleration_msg->vector.x;
71 imu_msg.linear_acceleration.y = free_acceleration_msg->vector.y;
72 this->node_->_imu_subscription_callback(imu_msg);
73}
74
75// TODO: implement a more complex logic, like the one in inspection node
77 this->_finished_client_->async_send_request(
78 std::make_shared<std_srvs::srv::Trigger::Request>(),
79 [this](rclcpp::Client<std_srvs::srv::Trigger>::SharedFuture future) {
80 if (future.get()->success) {
81 RCLCPP_INFO(this->node_->get_logger(), "Finished signal sent");
82 } else {
83 RCLCPP_ERROR(this->node_->get_logger(), "Failed to send finished signal");
84 }
85 });
86}
Class that handles the communication between the SpeedEstimation node and the other nodes in the syst...
Definition adapter.hpp:21
std::shared_ptr< SENode > node_
Definition adapter.hpp:23
friend class VehicleAdapter
Definition planning.hpp:88
rclcpp::Client< std_srvs::srv::Trigger >::SharedPtr _finished_client_
Client for finished signal.
Definition vehicle.hpp:53
message_filters::Subscriber< custom_interfaces::msg::ImuData > _yaw_accy_imu_subscription_
Definition vehicle.hpp:33
message_filters::Subscriber< custom_interfaces::msg::WheelRPM > _rr_wheel_rpm_subscription_
Subscriber for rr wheel rpm.
Definition vehicle.hpp:23
message_filters::sync_policies::ApproximateTime< custom_interfaces::msg::ImuData, custom_interfaces::msg::ImuData > ImuPolicy
Policy for synchronizing IMU data.
Definition vehicle.hpp:37
message_filters::Subscriber< custom_interfaces::msg::ImuData > _roll_accx_imu_subscription_
Definition vehicle.hpp:32
message_filters::Subscriber< custom_interfaces::msg::SteeringAngle > _steering_angle_subscription_
Subscriber for steering angle.
Definition vehicle.hpp:25
void xsens_imu_subscription_callback(const geometry_msgs::msg::Vector3Stamped::SharedPtr &free_acceleration_msg, const geometry_msgs::msg::Vector3Stamped::SharedPtr &angular_velocity_msg)
Xsens IMU subscription callback, which receives both free acceleration and angular velocity data sepa...
Definition vehicle.cpp:65
std::shared_ptr< message_filters::Synchronizer< WheelSteerPolicy > > _sync_
Synchronizer for wheel speeds and steering angle.
Definition vehicle.hpp:46
message_filters::sync_policies::ApproximateTime< geometry_msgs::msg::Vector3Stamped, geometry_msgs::msg::Vector3Stamped > XsensImuPolicy
Policy for synchronizing Xsens IMU data.
Definition vehicle.hpp:40
rclcpp::Subscription< custom_interfaces::msg::OperationalStatus >::SharedPtr _operational_status_subscription_
Subscriber for operational status.
Definition vehicle.hpp:27
message_filters::sync_policies::ApproximateTime< custom_interfaces::msg::WheelRPM, custom_interfaces::msg::WheelRPM, custom_interfaces::msg::SteeringAngle > WheelSteerPolicy
Policy for synchronizing wheel speeds and steering angle.
Definition vehicle.hpp:44
message_filters::Subscriber< geometry_msgs::msg::Vector3Stamped > _free_acceleration_subscription_
Definition vehicle.hpp:29
void imu_subscription_callback(const custom_interfaces::msg::ImuData &roll_accx_data, const custom_interfaces::msg::ImuData &yaw_accy_data)
IMU subscriptio callback, which receives both roll and yaw acceleration data separately and synchroni...
Definition vehicle.cpp:55
std::shared_ptr< message_filters::Synchronizer< ImuPolicy > > _imu_sync_
Definition vehicle.hpp:48
message_filters::Subscriber< custom_interfaces::msg::WheelRPM > _rl_wheel_rpm_subscription_
Subscriber for rl wheel rpm.
Definition vehicle.hpp:21
message_filters::Subscriber< geometry_msgs::msg::Vector3Stamped > _angular_velocity_subscription_
Definition vehicle.hpp:30
void finish() final
Function that sends the finish signal to the respective node.
Definition vehicle.cpp:76
std::shared_ptr< message_filters::Synchronizer< XsensImuPolicy > > _xsens_imu_sync_
Definition vehicle.hpp:50
void wheel_speeds_subscription_callback(const custom_interfaces::msg::WheelRPM &rl_wheel_rpm_msg, const custom_interfaces::msg::WheelRPM &rr_wheel_rpm_msg, const custom_interfaces::msg::SteeringAngle &steering_angle_msg)
Wheel speed subscription callback, which receives both wheel speeds and steering angle through a sync...
Definition vehicle.cpp:44