22#include "absl/strings/str_cat.h"
34 original_localization_ = localization;
35 if (!ConstructExceptLinearVelocity(localization)) {
36 std::string msg = absl::StrCat(
37 "Fail to update because ConstructExceptLinearVelocity error.",
38 "localization:\n", localization.DebugString());
41 if (localization.has_measurement_time()) {
43 }
else if (localization.
header().has_timestamp_sec()) {
45 }
else if (chassis.has_header() && chassis.
header().has_timestamp_sec()) {
46 AERROR <<
"Unable to use location timestamp for vehicle state. Use chassis "
51 if (chassis.has_gear_location()) {
57 if (chassis.has_speed_mps()) {
58 vehicle_state_.set_linear_velocity(chassis.
speed_mps());
59 if (!FLAGS_reverse_heading_vehicle_state &&
65 if (chassis.has_steering_percentage()) {
69 static constexpr double kEpsilon = 0.1;
71 vehicle_state_.set_kappa(0.0);
82bool VehicleStateProvider::ConstructExceptLinearVelocity(
84 if (!localization.has_pose()) {
85 AERROR <<
"Invalid localization input.";
90 if (FLAGS_use_navigation_mode) {
91 ADEBUG <<
"Skip localization update when it is in use_navigation_mode.";
95 vehicle_state_.mutable_pose()->CopyFrom(localization.
pose());
96 if (localization.
pose().has_position()) {
104 if (localization.
pose().has_heading()) {
105 vehicle_state_.set_heading(localization.
pose().
heading());
107 vehicle_state_.set_heading(
109 orientation.qy(), orientation.qz()));
112 if (FLAGS_enable_map_reference_unify) {
113 if (!localization.
pose().has_angular_velocity_vrf()) {
114 AERROR <<
"localization.pose().has_angular_velocity_vrf() must be true "
115 "when FLAGS_enable_map_reference_unify is true.";
118 vehicle_state_.set_angular_velocity(
121 if (!localization.
pose().has_linear_acceleration_vrf()) {
122 AERROR <<
"localization.pose().has_linear_acceleration_vrf() must be "
123 "true when FLAGS_enable_map_reference_unify is true.";
126 vehicle_state_.set_linear_acceleration(
129 if (!localization.
pose().has_angular_velocity()) {
130 AERROR <<
"localization.pose() has no angular velocity.";
133 vehicle_state_.set_angular_velocity(
136 if (!localization.
pose().has_linear_acceleration()) {
137 AERROR <<
"localization.pose() has no linear acceleration.";
140 vehicle_state_.set_linear_acceleration(
144 if (localization.
pose().has_euler_angles()) {
150 orientation.qy(), orientation.qz());
151 vehicle_state_.set_roll(euler_angle.roll());
152 vehicle_state_.set_pitch(euler_angle.pitch());
153 vehicle_state_.set_yaw(euler_angle.yaw());
172 return vehicle_state_.
heading();
200 return vehicle_state_.
pose();
204 return original_localization_.
pose();
212 return vehicle_state_;
216 Eigen::Vector3d vec_distance(0.0, 0.0, 0.0);
220 vec_distance[0] = 0.0;
221 vec_distance[1] = v * t;
230 if (vehicle_state_.
pose().has_orientation()) {
232 Eigen::Quaternion<double> quaternion(orientation.qw(), orientation.qx(),
233 orientation.qy(), orientation.qz());
234 Eigen::Vector3d pos_vec(vehicle_state_.
x(), vehicle_state_.
y(),
236 const Eigen::Vector3d future_pos_3d =
237 quaternion.toRotationMatrix() * vec_distance + pos_vec;
238 return math::Vec2d(future_pos_3d[0], future_pos_3d[1]);
243 return math::Vec2d(vec_distance[0] + vehicle_state_.
x(),
244 vec_distance[1] + vehicle_state_.
y());
248 const double rear_to_com_distance)
const {
251 if ((FLAGS_state_transform_to_com_reverse &&
253 (FLAGS_state_transform_to_com_drive &&
255 v << 0.0, rear_to_com_distance, 0.0;
259 Eigen::Vector3d pos_vec(vehicle_state_.
x(), vehicle_state_.
y(),
262 Eigen::Vector3d com_pos_3d = v + pos_vec;
265 if (vehicle_state_.
pose().has_orientation()) {
267 Eigen::Quaternion<double> quaternion(orientation.qw(), orientation.qx(),
268 orientation.qy(), orientation.qz());
270 com_pos_3d = quaternion.toRotationMatrix() * v + pos_vec;
A general class to denote the return status of an API call.
static Status OK()
generate a success status.
Status Update(const localization::LocalizationEstimate &localization, const canbus::Chassis &chassis)
Constructor by information of localization and chassis.
double linear_velocity() const
Get the vehicle's linear velocity.
const localization::Pose & pose() const
double angular_velocity() const
Get the vehicle's angular velocity.
double yaw() const
Get the vehicle yaw angle.
const localization::Pose & original_pose() const
double x() const
Get the x-coordinate of vehicle position.
double kappa() const
Get the kappa of vehicle position.
double z() const
Get the z coordinate of vehicle position.
double pitch() const
Get the vehicle pitch angle.
const VehicleState & vehicle_state() const
double steering_percentage() const
Get the vehicle's steering angle.
double gear() const
Get the vehicle's gear position.
void set_linear_velocity(const double linear_velocity)
Set the vehicle's linear velocity.
double roll() const
Get the vehicle roll angle.
math::Vec2d ComputeCOMPosition(const double rear_to_com_distance) const
Compute the position of center of mass(COM) of the vehicle, given the distance from rear wheels to th...
double y() const
Get the y-coordinate of vehicle position.
double linear_acceleration() const
Get the vehicle's linear acceleration.
double heading() const
Get the heading of vehicle position, which is the angle between the vehicle's heading direction and t...
math::Vec2d EstimateFuturePosition(const double t) const
Estimate future position from current position and heading, along a period of time,...
Implements a class of 2-dimensional vectors.
Defines the EulerAnglesZXY class.
EulerAnglesZXY< double > EulerAnglesZXYd
double QuaternionToHeading(const double qw, const double qx, const double qy, const double qz)
Contains a number of helper functions related to quaternions.
optional GearPosition gear_location
optional apollo::common::Header header
optional DrivingMode driving_mode
optional float steering_percentage
optional apollo::localization::Pose pose
optional double steering_percentage
optional double linear_velocity
optional double linear_acceleration
optional apollo::canbus::Chassis::GearPosition gear
optional double timestamp
optional double angular_velocity
optional apollo::localization::Pose pose
optional double measurement_time
optional apollo::common::Header header
optional apollo::common::Point3D euler_angles
optional apollo::common::Point3D linear_acceleration_vrf
optional apollo::common::Point3D linear_acceleration
optional apollo::common::Quaternion orientation
optional apollo::common::Point3D angular_velocity_vrf
optional apollo::common::PointENU position
optional apollo::common::Point3D angular_velocity