18namespace perception_msgs {
20namespace object_access {
32 return state.continuous_state;
55 return state.discrete_state;
78 return state.continuous_state_covariance;
104 return covariance[n * i + j];
129 std::vector<double> diagonal(n);
156 position.x =
getX(state);
157 position.y =
getY(state);
158 position.z =
getZ(state);
182 double roll{0}, pitch{0}, yaw{0};
186 q.setRPY(roll, pitch, yaw);
187 return tf2::toMsg(q);
208inline gm::Pose
getPose(
const ObjectState& state) {
224 const gm::Vector3 offset_to_center = state.reference_point.translation_to_geometric_center;
226 tf2::fromMsg(orientation, q);
227 const tf2::Vector3 offset_to_center_tf2(offset_to_center.x, offset_to_center.y, offset_to_center.z);
228 const tf2::Vector3 rotated_offset_to_center = tf2::quatRotate(q, offset_to_center_tf2);
229 position.x += rotated_offset_to_center.x();
230 position.y += rotated_offset_to_center.y();
231 position.z += rotated_offset_to_center.z();
267 const int model_id = state.model_id;
268 std::vector<double> pose_covariance(n * n, 0.0);
270 for (
int i = 0; i < n; i++) {
271 for (
int j = 0; j < n; j++) {
272 if (i == 0 &&
hasX(model_id))
274 else if (i == 1 &&
hasY(model_id))
276 else if (i == 2 &&
hasZ(model_id))
278 else if (i == 3 &&
hasRoll(model_id))
280 else if (i == 4 &&
hasPitch(model_id))
282 else if (i == 5 &&
hasYaw(model_id))
287 if (j == 0 &&
hasX(model_id))
289 else if (j == 1 &&
hasY(model_id))
291 else if (j == 2 &&
hasZ(model_id))
293 else if (j == 3 &&
hasRoll(model_id))
295 else if (j == 4 &&
hasPitch(model_id))
297 else if (j == 5 &&
hasYaw(model_id))
305 return pose_covariance;
328 gm::PoseWithCovariance pose_with_covariance;
329 pose_with_covariance.pose =
getPose(state);
331 gm::PoseWithCovariance::_covariance_type covariance;
332 std::copy(covariance_vector.begin(), covariance_vector.end(), covariance.begin());
333 pose_with_covariance.covariance = covariance;
334 return pose_with_covariance;
356 gm::Vector3 velocity;
384 return sqrt(pow(vel.x, 2) + pow(vel.y, 2) + pow(vel.z, 2));
405 gm::Vector3 acceleration;
408 acceleration.z = 0.0;
433 return sqrt(pow(acc.x, 2) + pow(acc.y, 2) + pow(acc.z, 2));
517 gm::PoseWithCovariance vel_lon_lat, vel_xyz;
518 vel_lon_lat.pose.position.x =
getVelLon(state);
519 vel_lon_lat.pose.position.y =
getVelLat(state);
520 vel_lon_lat.pose.position.z = 0.0;
523 auto model_id = state.model_id;
524 for (
int i = 0; i < n; i++) {
525 for (
int j = 0; j < n; j++) {
545 q.setRPY(0.0, 0.0,
getYaw(state));
546 gm::TransformStamped tf;
547 tf.transform.rotation = tf2::toMsg(q);
550 gm::PoseWithCovarianceStamped vel_lon_lat_stamped, vel_xyz_stamped;
551 vel_lon_lat_stamped.pose = vel_lon_lat;
552 tf2::doTransform(vel_lon_lat_stamped, vel_xyz_stamped, tf);
553 vel_xyz = vel_xyz_stamped.pose;
555 tf2::doTransform(vel_lon_lat, vel_xyz, tf);
580 gm::Vector3 vel_lon_lat, vel_xyz;
583 q.setRPY(0.0, 0.0,
getYaw(state));
584 gm::TransformStamped tf;
585 tf.transform.rotation = tf2::toMsg(q);
586 tf2::doTransform(vel_lon_lat, vel_xyz, tf);
649 gm::PoseWithCovariance acc_lon_lat, acc_xyz;
650 acc_lon_lat.pose.position.x =
getAccLon(state);
651 acc_lon_lat.pose.position.y =
getAccLat(state);
652 acc_lon_lat.pose.position.z = 0.0;
655 auto model_id = state.model_id;
656 for (
int i = 0; i < n; i++) {
657 for (
int j = 0; j < n; j++) {
677 q.setRPY(0.0, 0.0,
getYaw(state));
678 gm::TransformStamped tf;
679 tf.transform.rotation = tf2::toMsg(q);
681 gm::PoseWithCovarianceStamped acc_lon_lat_stamped, acc_xyz_stamped;
682 acc_lon_lat_stamped.pose = acc_lon_lat;
683 tf2::doTransform(acc_lon_lat_stamped, acc_xyz_stamped, tf);
684 acc_xyz = acc_xyz_stamped.pose;
686 tf2::doTransform(acc_lon_lat, acc_xyz, tf);
710 gm::Vector3 acc_lon_lat, acc_xyz;
713 q.setRPY(0.0, 0.0,
getYaw(state));
714 gm::TransformStamped tf;
715 tf.transform.rotation = tf2::toMsg(q);
716 tf2::doTransform(acc_lon_lat, acc_xyz, tf);
781 ObjectClassification highest_prob_class;
782 auto highest_prob_class_it = std::max_element(
783 state.classifications.begin(), state.classifications.end(),
784 [](
const ObjectClassification& c1,
const ObjectClassification& c2) { return c1.probability < c2.probability; });
785 if (highest_prob_class_it == state.classifications.end()) {
786 highest_prob_class.probability = -1.0;
787 highest_prob_class.type = ObjectClassification::UNKNOWN;
789 highest_prob_class = *highest_prob_class_it;
791 return highest_prob_class;
Object state sanity checks.
void sanityCheckContinuousState(const ObjectState &state)
Perform sanity check on continuous state of given object state.
gm::PoseWithCovariance getAccelerationXYZWithCovariance(const ObjectState &state)
Get the acceleration XYZ with covariance of a given object state.
double getAccX(const ObjectState &state)
Get the x-acceleration of a given object state.
ObjectClassification getClassWithHighestProbability(const ObjectState &state)
Get the classification with highest probability of a given object state.
std::vector< double > getContinuousStateCovariance(const ObjectState &state)
Get the continuous state covariance for a given object state.
gm::Point getCenterPosition(const ObjectState &state)
Get the object's geometric center position.
double getPitchInDeg(const ObjectState &state)
Get the pitch in degree of a given object state.
double getVelocityMagnitude(const ObjectState &state)
Get the velocity magnitude of a given object state.
double getAccelerationMagnitude(const ObjectState &state)
Get the acceleration magnitude of a given object state.
double getAccY(const ObjectState &state)
Get the y-acceleration of a given object state.
std::vector< double > getContinuousState(const ObjectState &state)
Get the continuous state for a given object state.
gm::Point getPosition(const ObjectState &state)
Get the position of a given object state.
gm::Quaternion getOrientation(const ObjectState &state)
Get the orientation of a given object state.
double getContinuousStateCovarianceAt(const ObjectState &state, const unsigned int i, const unsigned int j)
Get the continuous state covariance entry (i,j) for a given object state.
double getYawInDeg(const ObjectState &state)
Get the yaw in degree of a given object state.
gm::Vector3 getVelocityXYZ(const ObjectState &state)
Get the velocity XYZ of a given object state.
gm::PoseWithCovariance getPoseWithCovariance(const ObjectState &state)
Get the pose with covariance of a given object state.
gm::Vector3 getAcceleration(const ObjectState &state)
Get the acceleration of a given object state.
gm::Pose getPose(const ObjectState &state)
Get the pose of a given object state.
std::vector< double > getPoseCovariance(const ObjectState &state)
Get the pose covariance of a given object state.
gm::PoseWithCovariance getVelocityXYZWithCovariance(const ObjectState &state)
Get the velocity XYZ with covariance of a object state.
gm::Vector3 getVelocity(const ObjectState &state)
Get the velocity of a given object state.
gm::Vector3 getAccelerationXYZ(const ObjectState &state)
Get the acceleration XYZ of a given object state.
double getRollInDeg(const ObjectState &state)
Get the roll in degree of a given object state.
std::vector< double > getContinuousStateCovarianceDiagonal(const ObjectState &state)
Get the continuous state covariance diagonal for a given object state.
double getVelY(const ObjectState &state)
Get the y-velocity of a given object state.
std::vector< long int > getDiscreteState(const ObjectState &state)
Get the discrete state for a given object state.
double getVelX(const ObjectState &state)
Get the x-velocity of a given object state.
Getter functions for objects state members.
double getZ(const ObjectState &state)
Get the z-position for a given object state.
double getRoll(const ObjectState &state)
Get the roll for a given object state.
double getVelLon(const ObjectState &state)
Get the longitudinal velocity for a given object state.
double getAccLon(const ObjectState &state)
Get the longitudinal acceleration for a given object state.
double getPitch(const ObjectState &state)
Get the pitch for a given object state.
double getYaw(const ObjectState &state)
Get the yaw for a given object state.
double getAccLat(const ObjectState &state)
Get the lateral acceleration for a given object state.
double getY(const ObjectState &state)
Get the y-position for a given object state.
double getX(const ObjectState &state)
Get the x-position for a given object state.
double getVelLat(const ObjectState &state)
Get the longitudinal velocity for a given object state.
Object state vector indices based on state model.
bool hasYaw(const unsigned char &model_id)
Indicates if given model contains a yaw.
int indexVelLon(const unsigned char &model_id)
Get the vector-index that stores the longitudinal velocity for a given model-id.
int indexRoll(const unsigned char &model_id)
Get the vector-index that stores the roll for a given model-id.
bool hasZ(const unsigned char &model_id)
Indicates if given model contains a z-position.
bool hasAccLat(const unsigned char &model_id)
Indicates if given model contains a lateral acceleration.
bool hasVelLat(const unsigned char &model_id)
Indicates if given model contains a lateral velocity.
int indexVelLat(const unsigned char &model_id)
Get the vector-index that stores the lateral velocity for a given model-id.
bool hasY(const unsigned char &model_id)
Indicates if given model contains a y-position.
bool hasRoll(const unsigned char &model_id)
Indicates if given model contains a roll.
int indexY(const unsigned char &model_id)
Get the vector-index that stores the y-position for a given model-id.
bool hasX(const unsigned char &model_id)
Indicates if given model contains an x-position.
bool hasVelLon(const unsigned char &model_id)
Indicates if given model contains a longitudinal velocity.
int indexZ(const unsigned char &model_id)
Get the vector-index that stores the z-position for a given model-id.
int indexAccLon(const unsigned char &model_id)
Get the vector-index that stores the longitudinal acceleration for a given model-id.
bool hasPitch(const unsigned char &model_id)
Indicates if given model contains a pitch.
int indexPitch(const unsigned char &model_id)
Get the vector-index that stores the pitch for a given model-id.
int indexAccLat(const unsigned char &model_id)
Get the vector-index that stores the lateral acceleration for a given model-id.
int indexX(const unsigned char &model_id)
Get the vector-index that stores the x-position for a given model-id.
bool hasAccLon(const unsigned char &model_id)
Indicates if given model contains a longitudinal acceleration.
int indexYaw(const unsigned char &model_id)
Get the vector-index that stores the yaw for a given model-id.
int getContinuousStateSize(const ObjectState &state)
Get the continuous state size for a given object state.