Formula Student Autonomous Systems
The code for the main driverless system
Loading...
Searching...
No Matches
vehicle_adapter.cpp
Go to the documentation of this file.
2
3VehicleAdapter::VehicleAdapter(const VEParameters& parameters) : VENode(parameters) {
4 this->_free_acceleration_subscription_.subscribe(this, "/filter/free_acceleration");
5 this->_angular_velocity_subscription_.subscribe(this, "/imu/angular_velocity");
6 const XsensImuPolicy xsens_imu_policy(10);
7 this->_xsens_imu_sync_ = std::make_shared<message_filters::Synchronizer<XsensImuPolicy>>(
9 this->_xsens_imu_sync_->registerCallback(&VehicleAdapter::imu_callback, this);
10
11 this->_fl_wheel_rpm_subscription_.subscribe(this, "/vehicle/fl_rpm");
12 this->_fr_wheel_rpm_subscription_.subscribe(this, "/vehicle/fr_rpm");
13
14 const WheelSSPolicy policy(10);
15 this->_wss_sync_ = std::make_shared<message_filters::Synchronizer<WheelSSPolicy>>(
17 this->_wss_sync_->registerCallback(&VehicleAdapter::wss_callback, this);
18
19 this->_steering_angle_sub_ = this->create_subscription<custom_interfaces::msg::SteeringAngle>(
20 "/vehicle/bosch_steering_angle", 1,
21 std::bind(&VehicleAdapter::steering_angle_callback, this, std::placeholders::_1));
22 this->_resolver_sub_ = this->create_subscription<custom_interfaces::msg::WheelRPM>(
23 "/vehicle/motor_rpm", 1,
24 std::bind(&VehicleAdapter::resolver_callback, this, std::placeholders::_1));
25}
26
27void VehicleAdapter::wss_callback(const custom_interfaces::msg::WheelRPM& fl_wheel_rpm_msg,
28 const custom_interfaces::msg::WheelRPM& fr_wheel_rpm_msg) {
30 wss_data.rl_rpm = 0;
31 wss_data.rr_rpm = 0;
32 wss_data.fl_rpm = fl_wheel_rpm_msg.fl_rpm;
33 wss_data.fr_rpm = fr_wheel_rpm_msg.fr_rpm;
34 if (fl_wheel_rpm_msg.fl_rpm > 800 || fr_wheel_rpm_msg.fr_rpm > 800) {
35 RCLCPP_WARN(this->get_logger(), "Wheel RPM is too high");
36 return;
37 }
38 this->_velocity_estimator_->wss_callback(wss_data);
39 this->publish_velocities();
40}
41
42void VehicleAdapter::steering_angle_callback(const custom_interfaces::msg::SteeringAngle msg) {
43 this->_velocity_estimator_->steering_callback(msg.steering_angle);
44 this->publish_velocities();
45}
46
48 const geometry_msgs::msg::Vector3Stamped::SharedPtr& free_acceleration_msg,
49 const geometry_msgs::msg::Vector3Stamped::SharedPtr& angular_velocity_msg) {
51 if (this->number_of_imu_readings < 250) {
52 this->average_imu_bias =
53 (this->average_imu_bias * this->number_of_imu_readings - angular_velocity_msg->vector.z) /
54 (this->number_of_imu_readings + 1);
56 return;
57 }
58 imu_data.rotational_velocity =
59 (angular_velocity_msg->vector.z - this->average_imu_bias); // + 0.001838);
60 imu_data.acceleration_x = free_acceleration_msg->vector.x;
61 imu_data.acceleration_y = free_acceleration_msg->vector.y;
62 this->_velocity_estimator_->imu_callback(imu_data);
63 this->publish_velocities();
64}
65
66void VehicleAdapter::resolver_callback(custom_interfaces::msg::WheelRPM msg) {
67 this->_velocity_estimator_->motor_rpm_callback(msg.rr_rpm);
68 this->publish_velocities();
69}
friend class VehicleAdapter
Definition planning.hpp:88
Node class for the velocity estimation node.
Definition node.hpp:16
void publish_velocities() const
Definition node.cpp:10
std::shared_ptr< VelocityEstimator > _velocity_estimator_
Definition node.hpp:19
rclcpp::Subscription< custom_interfaces::msg::WheelRPM >::SharedPtr _resolver_sub_
void wss_callback(const custom_interfaces::msg::WheelRPM &rl_wheel_rpm_msg, const custom_interfaces::msg::WheelRPM &rr_wheel_rpm_msg)
Wheel speed subscription callback, which receives both wheel speeds through a synchronizer message fi...
std::shared_ptr< message_filters::Synchronizer< WheelSSPolicy > > _wss_sync_
Synchronizer for wheel speeds.
rclcpp::Subscription< custom_interfaces::msg::SteeringAngle >::SharedPtr _steering_angle_sub_
message_filters::sync_policies::ApproximateTime< geometry_msgs::msg::Vector3Stamped, geometry_msgs::msg::Vector3Stamped > XsensImuPolicy
Policy for synchronizing Xsens IMU data.
Definition vehicle.hpp:40
void imu_callback(const geometry_msgs::msg::Vector3Stamped::SharedPtr &free_acceleration_msg, const geometry_msgs::msg::Vector3Stamped::SharedPtr &angular_velocity_msg)
IMU subscription callback, which receives both free acceleration and angular velocity through a synch...
message_filters::Subscriber< custom_interfaces::msg::WheelRPM > _fl_wheel_rpm_subscription_
Subscriber for fl wheel rpm.
void steering_angle_callback(const custom_interfaces::msg::SteeringAngle msg)
Callback for the subscription of the steering angle sensor.
void resolver_callback(custom_interfaces::msg::WheelRPM msg)
Callback for the subscription of the resolver which measures the motor RPM.
message_filters::Subscriber< geometry_msgs::msg::Vector3Stamped > _free_acceleration_subscription_
Definition vehicle.hpp:29
message_filters::sync_policies::ApproximateTime< custom_interfaces::msg::WheelRPM, custom_interfaces::msg::WheelRPM > WheelSSPolicy
Policy for synchronizing wheel speeds.
message_filters::Subscriber< custom_interfaces::msg::WheelRPM > _fr_wheel_rpm_subscription_
Subscriber for fr wheel rpm.
message_filters::Subscriber< geometry_msgs::msg::Vector3Stamped > _angular_velocity_subscription_
Definition vehicle.hpp:30
std::shared_ptr< message_filters::Synchronizer< XsensImuPolicy > > _xsens_imu_sync_
Definition vehicle.hpp:50