17namespace perception_msgs
20namespace object_access
33 state.continuous_state = val;
58 state.discrete_state = val;
83 state.continuous_state_covariance = val;
109 ObjectState & state,
const unsigned int i,
const unsigned int j,
const double val)
113 state.continuous_state_covariance[n * i + j] = val;
127 T & obj,
const unsigned int i,
const unsigned int j,
const double val)
166inline void setPosition(ObjectState & state,
const gm::Point val,
const bool reset_covariance =
true)
168 setX(state, val.x, reset_covariance);
169 setY(state, val.y, reset_covariance);
170 setZ(state, val.z, reset_covariance);
182inline void setPosition(T & obj,
const gm::Point val,
const bool reset_covariance =
true)
194inline void setPosition(ObjectState & state,
const std::array<double, 3> & val,
const bool reset_covariance =
true)
196 setX(state, val[0], reset_covariance);
197 setY(state, val[1], reset_covariance);
198 setZ(state, val[2], reset_covariance);
210inline void setPosition(T & obj,
const std::array<double, 3> & val,
const bool reset_covariance =
true)
222inline void setOrientation(ObjectState & state,
const gm::Quaternion & val,
const bool reset_covariance =
true)
225 tf2::fromMsg(val, q);
226 double roll, pitch, yaw;
227 tf2::Matrix3x3(q).getRPY(roll, pitch, yaw);
228 if (
hasRoll(state.model_id))
setRoll(state, roll, reset_covariance);
230 if (
hasYaw(state.model_id))
setYaw(state, yaw, reset_covariance);
242inline void setOrientation(T & obj,
const gm::Quaternion & val,
const bool reset_covariance =
true)
254inline void setOrientation(ObjectState & state,
const std::array<double, 3> & val,
const bool reset_covariance =
true)
256 if (
hasRoll(state.model_id))
setRoll(state, val[0], reset_covariance);
258 if (
hasYaw(state.model_id))
setYaw(state, val[2], reset_covariance);
270inline void setOrientation(T & obj,
const std::array<double, 3> & val,
const bool reset_covariance =
true)
282inline void setPose(ObjectState & state,
const gm::Pose & val,
const bool reset_covariance =
true)
284 setPosition(state, val.position, reset_covariance);
297inline void setPose(T & obj,
const gm::Pose & val,
const bool reset_covariance =
true)
299 setPose(obj.state, val, reset_covariance);
311 ObjectState & state,
const std::array<double, 3> & xyz,
const std::array<double, 3> & rpy,
const bool reset_covariance =
true)
327inline void setPose(T & obj,
const std::array<double, 3> & xyz,
const std::array<double, 3> & rpy,
const bool reset_covariance =
true)
329 setPose(obj.state, xyz, rpy, reset_covariance);
339 ObjectState & state,
const gm::PoseWithCovariance::_covariance_type & val)
342 const int model_id = state.model_id;
345 for (
int i = 0; i < n; i++) {
348 case 0: i_valid =
hasX(model_id); ix = i_valid ?
indexX(model_id) : 0;
break;
349 case 1: i_valid =
hasY(model_id); ix = i_valid ?
indexY(model_id) : 0;
break;
350 case 2: i_valid =
hasZ(model_id); ix = i_valid ?
indexZ(model_id) : 0;
break;
351 case 3: i_valid =
hasRoll(model_id); ix = i_valid ?
indexRoll(model_id) : 0;
break;
353 case 5: i_valid =
hasYaw(model_id); ix = i_valid ?
indexYaw(model_id) : 0;
break;
355 if (!i_valid)
continue;
357 for (
int j = 0; j < n; j++) {
360 case 0: j_valid =
hasX(model_id); jx = j_valid ?
indexX(model_id) : 0;
break;
361 case 1: j_valid =
hasY(model_id); jx = j_valid ?
indexY(model_id) : 0;
break;
362 case 2: j_valid =
hasZ(model_id); jx = j_valid ?
indexZ(model_id) : 0;
break;
363 case 3: j_valid =
hasRoll(model_id); jx = j_valid ?
indexRoll(model_id) : 0;
break;
365 case 5: j_valid =
hasYaw(model_id); jx = j_valid ?
indexYaw(model_id) : 0;
break;
367 if (!j_valid)
continue;
394 setPose(state, val.pose,
false);
418inline void setVelocity(ObjectState & state,
const gm::Vector3 & val,
const bool reset_covariance =
true)
420 setVelLon(state, val.x, reset_covariance);
421 setVelLat(state, val.y, reset_covariance);
432inline void setVelocity(T & obj,
const gm::Vector3 & val,
const bool reset_covariance =
true)
444inline void setVelocity(ObjectState & state,
const std::array<double, 2> & val,
const bool reset_covariance =
true)
446 setVelLon(state, val[0], reset_covariance);
447 setVelLat(state, val[1], reset_covariance);
459inline void setVelocity(T & obj,
const std::array<double, 2> & val,
const bool reset_covariance =
true)
471inline void setAcceleration(ObjectState & state,
const gm::Vector3 & val,
const bool reset_covariance =
true)
473 setAccLon(state, val.x, reset_covariance);
474 setAccLat(state, val.y, reset_covariance);
486inline void setAcceleration(T & obj,
const gm::Vector3 & val,
const bool reset_covariance =
true)
498inline void setAcceleration(ObjectState & state,
const std::array<double, 2> & val,
const bool reset_covariance =
true)
500 setAccLon(state, val[0], reset_covariance);
501 setAccLat(state, val[1], reset_covariance);
513inline void setAcceleration(T & obj,
const std::array<double, 2> & val,
const bool reset_covariance =
true)
527inline void setRollInDeg(ObjectState & state,
const double val,
const bool reset_covariance =
true)
529 setRoll(state, val * M_PI / 180.0, reset_covariance);
541inline void setRollInDeg(T & obj,
const double val,
const bool reset_covariance =
true)
553inline void setPitchInDeg(ObjectState & state,
const double val,
const bool reset_covariance =
true)
555 setPitch(state, val * M_PI / 180.0, reset_covariance);
567inline void setPitchInDeg(T & obj,
const double val,
const bool reset_covariance =
true)
579inline void setYawInDeg(ObjectState & state,
const double val,
const bool reset_covariance =
true)
581 setYaw(state, val * M_PI / 180.0, reset_covariance);
593inline void setYawInDeg(T & obj,
const double val,
const bool reset_covariance =
true)
609 ObjectState & state,
const gm::Vector3 & vel_xyz_in,
const double yaw,
const double var_vel_x,
610 const double var_vel_y,
const double cov_vel_xy)
612 gm::PoseWithCovariance vel_lon_lat, vel_xyz;
613 vel_xyz.pose.position.x = vel_xyz_in.x;
614 vel_xyz.pose.position.y = vel_xyz_in.y;
615 vel_xyz.pose.position.z = 0.0;
617 vel_xyz.covariance.at(0) = var_vel_x;
618 vel_xyz.covariance.at(1) = cov_vel_xy;
619 vel_xyz.covariance.at(6) = cov_vel_xy;
620 vel_xyz.covariance.at(7) = var_vel_y;
623 q.setRPY(0.0, 0.0, -yaw);
624 gm::TransformStamped tf;
625 tf.transform.rotation = tf2::toMsg(q);
628 gm::PoseWithCovarianceStamped vel_lon_lat_stamped, vel_xyz_stamped;
629 vel_xyz_stamped.pose = vel_xyz;
630 tf2::doTransform(vel_xyz_stamped, vel_lon_lat_stamped, tf);
631 vel_lon_lat = vel_lon_lat_stamped.pose;
633 tf2::doTransform(vel_xyz, vel_lon_lat, tf);
636 setVelocity(state, {vel_lon_lat.pose.position.x, vel_lon_lat.pose.position.y},
false);
637 setYaw(state, yaw,
false);
640 auto model_id = state.model_id;
641 for (
int i = 0; i < n; i++) {
642 for (
int j = 0; j < n; j++) {
675 T & obj,
const gm::Vector3 & vel_xyz_in,
const double yaw,
const double var_vel_x,
676 const double var_vel_y,
const double cov_vel_xy)
689inline void setVelocityXYZYaw(ObjectState & state,
const gm::Vector3 & vel_xyz,
const double yaw,
const bool reset_covariance =
true)
691 gm::Vector3 vel_lon_lat, vel_xyz_in;
692 vel_xyz_in = vel_xyz;
694 q.setRPY(0.0, 0.0, -yaw);
695 gm::TransformStamped tf;
696 tf.transform.rotation = tf2::toMsg(q);
697 tf2::doTransform(vel_xyz_in, vel_lon_lat, tf);
699 setYaw(state, yaw, reset_covariance);
712inline void setVelocityXYZYaw(T & obj,
const gm::Vector3 & vel_xyz,
const double yaw,
const bool reset_covariance =
true)
728 ObjectState & state,
const gm::Vector3 & acc_xyz_in,
const double yaw,
const double var_acc_x,
729 const double var_acc_y,
const double cov_acc_xy)
731 gm::PoseWithCovariance acc_lon_lat, acc_xyz;
732 acc_xyz.pose.position.x = acc_xyz_in.x;
733 acc_xyz.pose.position.y = acc_xyz_in.y;
734 acc_xyz.pose.position.z = 0.0;
736 acc_xyz.covariance.at(0) = var_acc_x;
737 acc_xyz.covariance.at(1) = cov_acc_xy;
738 acc_xyz.covariance.at(6) = cov_acc_xy;
739 acc_xyz.covariance.at(7) = var_acc_y;
742 q.setRPY(0.0, 0.0, -yaw);
743 gm::TransformStamped tf;
744 tf.transform.rotation = tf2::toMsg(q);
747 gm::PoseWithCovarianceStamped acc_lon_lat_stamped, acc_xyz_stamped;
748 acc_xyz_stamped.pose = acc_xyz;
749 tf2::doTransform(acc_xyz_stamped, acc_lon_lat_stamped, tf);
750 acc_lon_lat = acc_lon_lat_stamped.pose;
752 tf2::doTransform(acc_xyz, acc_lon_lat, tf);
755 setAcceleration(state, {acc_lon_lat.pose.position.x, acc_lon_lat.pose.position.y},
false);
756 setYaw(state, yaw,
false);
759 auto model_id = state.model_id;
760 for (
int i = 0; i < n; i++) {
761 for (
int j = 0; j < n; j++) {
794 T & obj,
const gm::Vector3 & acc_xyz_in,
const double yaw,
const double var_acc_x,
795 const double var_acc_y,
const double cov_acc_xy)
809 ObjectState & state,
const gm::Vector3 & acc_xyz,
const double yaw,
const bool reset_covariance =
true)
811 gm::Vector3 acc_lon_lat, acc_xyz_in;
812 acc_xyz_in = acc_xyz;
814 q.setRPY(0.0, 0.0, -yaw);
815 gm::TransformStamped tf;
816 tf.transform.rotation = tf2::toMsg(q);
817 tf2::doTransform(acc_xyz_in, acc_lon_lat, tf);
819 setYaw(state, yaw, reset_covariance);
832inline void setAccelerationXYZYaw(T & obj,
const gm::Vector3 & acc_xyz,
const double yaw,
const bool reset_covariance =
true)
Object state sanity checks.
void sanityCheckContinuousState(const ObjectState &state)
Perform sanity check on continuous state of given object state.
void sanityCheckContinuousStateCovariance(const ObjectState &state)
Perform sanity check on continuous state covariance of given object state.
void sanityCheckDiscreteState(const ObjectState &state)
Perform sanity check on discrete state of given object state.
void setPosition(ObjectState &state, const gm::Point val, const bool reset_covariance=true)
Set the position of a given object state.
void setContinuousStateCovarianceDiagonal(ObjectState &state, const std::vector< double > val)
Set the continuous state covariance diagonal of a given object state.
void setContinuousState(ObjectState &state, const std::vector< double > &val)
Set the continuous state of a given object state.
void setPitchInDeg(ObjectState &state, const double val, const bool reset_covariance=true)
Set the pitch in degree of a given object state.
void setPose(ObjectState &state, const gm::Pose &val, const bool reset_covariance=true)
Set the pose of a given object state.
void setAccelerationXYZYawWithCovariance(ObjectState &state, const gm::Vector3 &acc_xyz_in, const double yaw, const double var_acc_x, const double var_acc_y, const double cov_acc_xy)
Set the acceleration XYZ and yaw with covariance of a given object state.
void setAcceleration(ObjectState &state, const gm::Vector3 &val, const bool reset_covariance=true)
Set the acceleration of a given object state.
void setVelocityXYZYawWithCovariance(ObjectState &state, const gm::Vector3 &vel_xyz_in, const double yaw, const double var_vel_x, const double var_vel_y, const double cov_vel_xy)
Set the velocity XYZ and yaw with covariance of a given object state.
void setRollInDeg(ObjectState &state, const double val, const bool reset_covariance=true)
Set the roll in degree of a given object state.
void setContinuousStateCovarianceAt(ObjectState &state, const unsigned int i, const unsigned int j, const double val)
Set the continuous state covariance entry at (i,j) of a given object state.
void setDiscreteState(ObjectState &state, const std::vector< long int > &val)
Set the discrete state of a given object state.
void setVelocity(ObjectState &state, const gm::Vector3 &val, const bool reset_covariance=true)
Set the velocity of a given object state.
void setOrientation(ObjectState &state, const gm::Quaternion &val, const bool reset_covariance=true)
Set the orientation of a given object state.
void setPoseCovariance(ObjectState &state, const gm::PoseWithCovariance::_covariance_type &val)
Set the pose covariance of a given object state.
void setYawInDeg(ObjectState &state, const double val, const bool reset_covariance=true)
Set the yaw in degree of a given object state.
void setAccelerationXYZYaw(ObjectState &state, const gm::Vector3 &acc_xyz, const double yaw, const bool reset_covariance=true)
Set the acceleration XYZ and yaw of a given template object that contains an object state.
void setVelocityXYZYaw(ObjectState &state, const gm::Vector3 &vel_xyz, const double yaw, const bool reset_covariance=true)
Set the velocity XYZ and yaw of a given object state.
void setContinuousStateCovariance(ObjectState &state, const std::vector< double > &val)
Set the continuous state covariance of a given object state.
void setPoseWithCovariance(ObjectState &state, const gm::PoseWithCovariance &val)
Set the pose with covariance of 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.
Setter functions for objects state members.
void setAccLat(ObjectState &state, const double val, const bool reset_covariance=true)
Set the lateral acceleration for a given object state.
void setAccLon(ObjectState &state, const double val, const bool reset_covariance=true)
Set the longitudinal acceleration for a given object state.
void setVelLon(ObjectState &state, const double val, const bool reset_covariance=true)
Set the longitdunial velocity for a given object state.
void setX(ObjectState &state, const double val, const bool reset_covariance=true)
Set the x-position for a given object state.
void setY(ObjectState &state, const double val, const bool reset_covariance=true)
Set the y-position for a given object state.
void setVelLat(ObjectState &state, const double val, const bool reset_covariance=true)
Set the lateral velocity for a given object state.
void setYaw(ObjectState &state, const double val, const bool reset_covariance=true)
Set the yaw for a given object state.
void setRoll(ObjectState &state, const double val, const bool reset_covariance=true)
Set the roll for a given object state.
void setPitch(ObjectState &state, const double val, const bool reset_covariance=true)
Set the pitch for a given object state.
void setZ(ObjectState &state, const double val, const bool reset_covariance=true)
Set the z-position for a given object state.
int getContinuousStateSize(const ObjectState &state)
Get the continuous state size for a given object state.