perception_interfaces 1.2.0
Loading...
Searching...
No Matches
Functions
convenience_state_getters.hpp File Reference

Convenience getter functions for object state members. More...

#include <perception_msgs_utils/checks.hpp>
#include <perception_msgs_utils/covariance_transform.hpp>
#include <perception_msgs_utils/state_getters.hpp>
#include <perception_msgs_utils/state_index.hpp>
#include <algorithm>
#include <cmath>

Go to the source code of this file.

Functions

std::vector< double > perception_msgs::object_access::getContinuousState (const ObjectState &state)
 Get the continuous state for a given object state.
 
template<typename T >
std::vector< double > perception_msgs::object_access::getContinuousState (const T &obj)
 Get the continuous state for a given template object that contains an object state.
 
std::vector< long int > perception_msgs::object_access::getDiscreteState (const ObjectState &state)
 Get the discrete state for a given object state.
 
template<typename T >
std::vector< long int > perception_msgs::object_access::getDiscreteState (const T &obj)
 Get the discrete state for a given template object that contains an object state.
 
std::vector< double > perception_msgs::object_access::getContinuousStateCovariance (const ObjectState &state)
 Get the full continuous state covariance for a given object state. Empty storage yields INVALID diagonals and zero cross terms without modifying the state.
 
template<typename T >
std::vector< double > perception_msgs::object_access::getContinuousStateCovariance (const T &obj)
 Get the continuous state covariance for a given template object that contains an object state.
 
double perception_msgs::object_access::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.
 
template<typename T >
double perception_msgs::object_access::getContinuousStateCovarianceAt (const T &obj, const unsigned int i, const unsigned int j)
 Get the continuous state covariance entry (i,j) for a given template object that contains an object state.
 
std::vector< double > perception_msgs::object_access::getContinuousStateCovarianceDiagonal (const ObjectState &state)
 Get the continuous state covariance diagonal for a given object state.
 
template<typename T >
std::vector< double > perception_msgs::object_access::getContinuousStateCovarianceDiagonal (const T &obj)
 Get the continuous state covariance diagonal for a given template object that contains an object state.
 
gm::Point perception_msgs::object_access::getPosition (const ObjectState &state)
 Get the position of a given object state.
 
template<typename T >
gm::Point perception_msgs::object_access::getPosition (const T &obj)
 Get the position of a given template object that contains an object state.
 
gm::Quaternion perception_msgs::object_access::getOrientation (const ObjectState &state)
 Get the orientation of a given object state.
 
template<typename T >
gm::Quaternion perception_msgs::object_access::getOrientation (const T &obj)
 Get the orientation of a given template object that contains an object state.
 
gm::Pose perception_msgs::object_access::getPose (const ObjectState &state)
 Get the pose of a given object state.
 
gm::Point perception_msgs::object_access::getCenterPosition (const ObjectState &state)
 Get the object's geometric center position.
 
template<typename T >
gm::Point perception_msgs::object_access::getCenterPosition (const T &object)
 Get the object's geometric center position.
 
template<typename T >
gm::Pose perception_msgs::object_access::getPose (const T &obj)
 Get the pose of a given template object that contains an object state.
 
std::vector< double > perception_msgs::object_access::getPoseCovariance (const ObjectState &state)
 Get the pose covariance of a given object state.
 
template<typename T >
std::vector< double > perception_msgs::object_access::getPoseCovariance (const T &obj)
 Get the pose covariance of a given template object that contains an object state.
 
gm::PoseWithCovariance perception_msgs::object_access::getPoseWithCovariance (const ObjectState &state)
 Get the pose with covariance of a given object state.
 
template<typename T >
gm::PoseWithCovariance perception_msgs::object_access::getPoseWithCovariance (const T &obj)
 Get the pose with covariance of a given template object that contains an object state.
 
gm::Vector3 perception_msgs::object_access::getVelocity (const ObjectState &state)
 Get the velocity of a given object state.
 
template<typename T >
gm::Vector3 perception_msgs::object_access::getVelocity (const T &obj)
 Get the velocity of a given template object that contains an object state.
 
double perception_msgs::object_access::getVelocityMagnitude (const ObjectState &state)
 Get the velocity magnitude of a given object state.
 
template<typename T >
double perception_msgs::object_access::getVelocityMagnitude (const T &obj)
 Get the velocity magnitude of a given template object that contains an object state.
 
gm::Vector3 perception_msgs::object_access::getAcceleration (const ObjectState &state)
 Get the acceleration of a given object state.
 
template<typename T >
gm::Vector3 perception_msgs::object_access::getAcceleration (const T &obj)
 Get the acceleration of a given template object that contains an object state.
 
double perception_msgs::object_access::getAccelerationMagnitude (const ObjectState &state)
 Get the acceleration magnitude of a given object state.
 
template<typename T >
double perception_msgs::object_access::getAccelerationMagnitude (const T &obj)
 Get the acceleration magnitude of a given template object that contains an object state.
 
double perception_msgs::object_access::getRollInDeg (const ObjectState &state)
 Get the roll in degree of a given object state.
 
template<typename T >
double perception_msgs::object_access::getRollInDeg (const T &obj)
 Get the roll in degree of a given template object that contains an object state.
 
double perception_msgs::object_access::getPitchInDeg (const ObjectState &state)
 Get the pitch in degree of a given object state.
 
template<typename T >
double perception_msgs::object_access::getPitchInDeg (const T &obj)
 Get the pitch in degree of a given template object that contains an object state.
 
double perception_msgs::object_access::getYawInDeg (const ObjectState &state)
 Get the yaw in degree of a given object state.
 
template<typename T >
double perception_msgs::object_access::getYawInDeg (const T &obj)
 Get the yaw in degree of a given template object that contains an object state.
 
gm::PoseWithCovariance perception_msgs::object_access::getVelocityXYZWithCovariance (const ObjectState &state)
 Get the velocity XYZ with covariance of a object state.
 
template<typename T >
gm::PoseWithCovariance perception_msgs::object_access::getVelocityXYZWithCovariance (const T &obj)
 Get the velocity XYZ with covariance of a given template object that contains an object state.
 
gm::Vector3 perception_msgs::object_access::getVelocityXYZ (const ObjectState &state)
 Get the velocity XYZ of a given object state.
 
template<typename T >
gm::Vector3 perception_msgs::object_access::getVelocityXYZ (const T &obj)
 Get the velocity XYZ of a given template object that contains an object state.
 
double perception_msgs::object_access::getVelX (const ObjectState &state)
 Get the x-velocity of a given object state.
 
template<typename T >
double perception_msgs::object_access::getVelX (const T &obj)
 Get the x-velocity of a given template object that contains an object state.
 
double perception_msgs::object_access::getVelY (const ObjectState &state)
 Get the y-velocity of a given object state.
 
template<typename T >
double perception_msgs::object_access::getVelY (const T &obj)
 Get the y-velocity of a given template object that contains an object state.
 
gm::PoseWithCovariance perception_msgs::object_access::getAccelerationXYZWithCovariance (const ObjectState &state)
 Get the acceleration XYZ with covariance of a given object state.
 
template<typename T >
gm::PoseWithCovariance perception_msgs::object_access::getAccelerationXYZWithCovariance (const T &obj)
 Get the acceleration XYZ with covariance of a given template object that contains an object state.
 
gm::Vector3 perception_msgs::object_access::getAccelerationXYZ (const ObjectState &state)
 Get the acceleration XYZ of a given object state.
 
template<typename T >
gm::Vector3 perception_msgs::object_access::getAccelerationXYZ (const T &obj)
 Get the acceleration XYZ of a given template object that contains an object state.
 
double perception_msgs::object_access::getAccX (const ObjectState &state)
 Get the x-acceleration of a given object state.
 
template<typename T >
double perception_msgs::object_access::getAccX (const T &obj)
 Get the x-acceleration of a given template object that contains an object state.
 
double perception_msgs::object_access::getAccY (const ObjectState &state)
 Get the y-acceleration of a given object state.
 
template<typename T >
double perception_msgs::object_access::getAccY (const T &obj)
 Get the y-acceleration of a given template object that contains an object state.
 
ObjectClassification perception_msgs::object_access::getClassWithHighestProbability (const ObjectState &state)
 Get the classification with highest probability of a given object state.
 
template<typename T >
ObjectClassification perception_msgs::object_access::getClassWithHighestProbability (const T &obj)
 Get the classification with highest probability of a given template object that contains an object state.
 

Detailed Description

Convenience getter functions for object state members.

Definition in file convenience_state_getters.hpp.

Function Documentation

◆ getAcceleration() [1/2]

gm::Vector3 perception_msgs::object_access::getAcceleration ( const ObjectState &  state)
inline

Get the acceleration of a given object state.

Parameters
state
Returns
gm::Vector3

Definition at line 414 of file convenience_state_getters.hpp.

414 {
415 gm::Vector3 acceleration;
416 acceleration.x = getAccLon(state);
417 acceleration.y = getAccLat(state);
418 acceleration.z = 0.0;
419 return acceleration;
420}
double getAccLon(const ObjectState &state)
Get the longitudinal acceleration for a given object state.
double getAccLat(const ObjectState &state)
Get the lateral acceleration for a given object state.

◆ getAcceleration() [2/2]

template<typename T >
gm::Vector3 perception_msgs::object_access::getAcceleration ( const T &  obj)
inline

Get the acceleration of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::Vector3

Definition at line 430 of file convenience_state_getters.hpp.

430 {
431 return getAcceleration(obj.state);
432}
gm::Vector3 getAcceleration(const ObjectState &state)
Get the acceleration of a given object state.

◆ getAccelerationMagnitude() [1/2]

double perception_msgs::object_access::getAccelerationMagnitude ( const ObjectState &  state)
inline

Get the acceleration magnitude of a given object state.

Parameters
state
Returns
double

Definition at line 440 of file convenience_state_getters.hpp.

440 {
441 gm::Vector3 acc = getAcceleration(state);
442 using namespace std;
443 return sqrt(pow(acc.x, 2) + pow(acc.y, 2) + pow(acc.z, 2));
444}

◆ getAccelerationMagnitude() [2/2]

template<typename T >
double perception_msgs::object_access::getAccelerationMagnitude ( const T &  obj)
inline

Get the acceleration magnitude of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 454 of file convenience_state_getters.hpp.

454 {
455 return getAccelerationMagnitude(obj.state);
456}
double getAccelerationMagnitude(const ObjectState &state)
Get the acceleration magnitude of a given object state.

◆ getAccelerationXYZ() [1/2]

gm::Vector3 perception_msgs::object_access::getAccelerationXYZ ( const ObjectState &  state)
inline

Get the acceleration XYZ of a given object state.

Parameters
state
Returns
gm::Vector3

Definition at line 711 of file convenience_state_getters.hpp.

711 {
712 gm::Vector3 acc_lon_lat, acc_xyz;
713 acc_lon_lat = getAcceleration(state);
714 tf2::Quaternion q;
715 q.setRPY(0.0, 0.0, getYaw(state));
716 gm::TransformStamped tf;
717 tf.transform.rotation = tf2::toMsg(q);
718 tf2::doTransform(acc_lon_lat, acc_xyz, tf);
719 return acc_xyz;
720}
double getYaw(const ObjectState &state)
Get the yaw for a given object state.

◆ getAccelerationXYZ() [2/2]

template<typename T >
gm::Vector3 perception_msgs::object_access::getAccelerationXYZ ( const T &  obj)
inline

Get the acceleration XYZ of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::Vector3

Definition at line 730 of file convenience_state_getters.hpp.

730 {
731 return getAccelerationXYZ(obj.state);
732}
gm::Vector3 getAccelerationXYZ(const ObjectState &state)
Get the acceleration XYZ of a given object state.

◆ getAccelerationXYZWithCovariance() [1/2]

gm::PoseWithCovariance perception_msgs::object_access::getAccelerationXYZWithCovariance ( const ObjectState &  state)
inline

Get the acceleration XYZ with covariance of a given object state.

Parameters
state
Returns
gm::PoseWithCovariance

Definition at line 654 of file convenience_state_getters.hpp.

654 {
655 gm::PoseWithCovariance acc_lon_lat, acc_xyz;
656 acc_lon_lat.pose.position.x = getAccLon(state);
657 acc_lon_lat.pose.position.y = getAccLat(state);
658 acc_lon_lat.pose.position.z = 0.0;
659
660 int ix, jx, n = 2;
661 auto model_id = state.model_id;
662 for (int i = 0; i < n; i++) {
663 for (int j = 0; j < n; j++) {
664 if (i == 0 && hasAccLon(model_id))
665 ix = indexAccLon(model_id);
666 else if (i == 1 && hasAccLat(model_id))
667 ix = indexAccLat(model_id);
668 else
669 continue;
670
671 if (j == 0 && hasAccLon(model_id))
672 jx = indexAccLon(model_id);
673 else if (j == 1 && hasAccLat(model_id))
674 jx = indexAccLat(model_id);
675 else
676 continue;
677
678 acc_lon_lat.covariance.at(6 * i + j) = getContinuousStateCovarianceAt(state, ix, jx);
679 }
680 }
681
682 tf2::Quaternion q;
683 q.setRPY(0.0, 0.0, getYaw(state));
684 gm::TransformStamped tf;
685 tf.transform.rotation = tf2::toMsg(q);
686 gm::PoseWithCovarianceStamped acc_lon_lat_stamped, acc_xyz_stamped;
687 acc_lon_lat_stamped.pose = acc_lon_lat;
688 transformPoseWithCovariance(acc_lon_lat_stamped, acc_xyz_stamped, tf);
689 acc_xyz = acc_xyz_stamped.pose;
690 return acc_xyz;
691}
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.
bool hasAccLat(const unsigned char &model_id)
Indicates if given model contains a lateral acceleration.
int indexAccLon(const unsigned char &model_id)
Get the vector-index that stores the longitudinal acceleration 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.
bool hasAccLon(const unsigned char &model_id)
Indicates if given model contains a longitudinal acceleration.

◆ getAccelerationXYZWithCovariance() [2/2]

template<typename T >
gm::PoseWithCovariance perception_msgs::object_access::getAccelerationXYZWithCovariance ( const T &  obj)
inline

Get the acceleration XYZ with covariance of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::PoseWithCovariance

Definition at line 701 of file convenience_state_getters.hpp.

701 {
702 return getAccelerationXYZWithCovariance(obj.state);
703}
gm::PoseWithCovariance getAccelerationXYZWithCovariance(const ObjectState &state)
Get the acceleration XYZ with covariance of a given object state.

◆ getAccX() [1/2]

double perception_msgs::object_access::getAccX ( const ObjectState &  state)
inline

Get the x-acceleration of a given object state.

Parameters
state
Returns
double

Definition at line 740 of file convenience_state_getters.hpp.

740{ return getAccelerationXYZ(state).x; }

◆ getAccX() [2/2]

template<typename T >
double perception_msgs::object_access::getAccX ( const T &  obj)
inline

Get the x-acceleration of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 750 of file convenience_state_getters.hpp.

750 {
751 return getAccX(obj.state);
752}
double getAccX(const ObjectState &state)
Get the x-acceleration of a given object state.

◆ getAccY() [1/2]

double perception_msgs::object_access::getAccY ( const ObjectState &  state)
inline

Get the y-acceleration of a given object state.

Parameters
state
Returns
double

Definition at line 760 of file convenience_state_getters.hpp.

760{ return getAccelerationXYZ(state).y; }

◆ getAccY() [2/2]

template<typename T >
double perception_msgs::object_access::getAccY ( const T &  obj)
inline

Get the y-acceleration of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 770 of file convenience_state_getters.hpp.

770 {
771 return getAccY(obj.state);
772}
double getAccY(const ObjectState &state)
Get the y-acceleration of a given object state.

◆ getCenterPosition() [1/2]

gm::Point perception_msgs::object_access::getCenterPosition ( const ObjectState &  state)
inline

Get the object's geometric center position.

Parameters
stateThe state to get the center position from
Returns
gm::Point The position of the object's geometric center

Definition at line 231 of file convenience_state_getters.hpp.

231 {
232 gm::Point position = getPosition(state);
233 const auto orientation = getOrientation(state);
234 const gm::Vector3 offset_to_center = state.reference_point.translation_to_geometric_center;
235 tf2::Quaternion q;
236 tf2::fromMsg(orientation, q);
237 const tf2::Vector3 offset_to_center_tf2(offset_to_center.x, offset_to_center.y, offset_to_center.z);
238 const tf2::Vector3 rotated_offset_to_center = tf2::quatRotate(q, offset_to_center_tf2);
239 position.x += rotated_offset_to_center.x();
240 position.y += rotated_offset_to_center.y();
241 position.z += rotated_offset_to_center.z();
242 return position;
243}
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.

◆ getCenterPosition() [2/2]

template<typename T >
gm::Point perception_msgs::object_access::getCenterPosition ( const T &  object)
inline

Get the object's geometric center position.

Template Parameters
T
Parameters
objectThe object to get the center position from
Returns
gm::Position The position of the object's geometric center

Definition at line 253 of file convenience_state_getters.hpp.

253 {
254 return getCenterPosition(object.state);
255}
gm::Point getCenterPosition(const ObjectState &state)
Get the object's geometric center position.

◆ getClassWithHighestProbability() [1/2]

ObjectClassification perception_msgs::object_access::getClassWithHighestProbability ( const ObjectState &  state)
inline

Get the classification with highest probability of a given object state.

Parameters
state
Returns
ObjectClassification

Definition at line 782 of file convenience_state_getters.hpp.

782 {
783 ObjectClassification highest_prob_class;
784 auto highest_prob_class_it = std::max_element(
785 state.classifications.begin(), state.classifications.end(),
786 [](const ObjectClassification& c1, const ObjectClassification& c2) { return c1.probability < c2.probability; });
787 if (highest_prob_class_it == state.classifications.end()) {
788 highest_prob_class.probability = -1.0;
789 highest_prob_class.type = ObjectClassification::UNKNOWN;
790 } else {
791 highest_prob_class = *highest_prob_class_it;
792 }
793 return highest_prob_class;
794}

◆ getClassWithHighestProbability() [2/2]

template<typename T >
ObjectClassification perception_msgs::object_access::getClassWithHighestProbability ( const T &  obj)
inline

Get the classification with highest probability of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
ObjectClassification

Definition at line 804 of file convenience_state_getters.hpp.

804 {
805 return getClassWithHighestProbability(obj.state);
806}
ObjectClassification getClassWithHighestProbability(const ObjectState &state)
Get the classification with highest probability of a given object state.

◆ getContinuousState() [1/2]

std::vector< double > perception_msgs::object_access::getContinuousState ( const ObjectState &  state)
inline

Get the continuous state for a given object state.

Parameters
state
Returns
std::vector<double>

Definition at line 31 of file convenience_state_getters.hpp.

31 {
33 return state.continuous_state;
34}
void sanityCheckContinuousState(const ObjectState &state)
Perform sanity check on continuous state of given object state.
Definition checks.hpp:63

◆ getContinuousState() [2/2]

template<typename T >
std::vector< double > perception_msgs::object_access::getContinuousState ( const T &  obj)
inline

Get the continuous state for a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
std::vector<double>

Definition at line 44 of file convenience_state_getters.hpp.

44 {
45 return getContinuousState(obj.state);
46}
std::vector< double > getContinuousState(const ObjectState &state)
Get the continuous state for a given object state.

◆ getContinuousStateCovariance() [1/2]

std::vector< double > perception_msgs::object_access::getContinuousStateCovariance ( const ObjectState &  state)
inline

Get the full continuous state covariance for a given object state. Empty storage yields INVALID diagonals and zero cross terms without modifying the state.

Parameters
state
Returns
std::vector<double>

Definition at line 78 of file convenience_state_getters.hpp.

78 {
80 if (!state.continuous_state_covariance.empty()) return state.continuous_state_covariance;
81 const int n = getContinuousStateSize(state.model_id);
82 std::vector<double> covariance(n * n, CONTINUOUS_STATE_COVARIANCE_INIT);
83 for (int i = 0; i < n; ++i) covariance[n * i + i] = CONTINUOUS_STATE_COVARIANCE_INVALID;
84 return covariance;
85}
void sanityCheckContinuousStateCovariance(const ObjectState &state)
Perform sanity check on continuous state covariance of given object state.
Definition checks.hpp:103
int getContinuousStateSize(const ObjectState &state)
Get the continuous state size for a given object state.
Definition utils.hpp:30

◆ getContinuousStateCovariance() [2/2]

template<typename T >
std::vector< double > perception_msgs::object_access::getContinuousStateCovariance ( const T &  obj)
inline

Get the continuous state covariance for a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
std::vector<double>

Definition at line 95 of file convenience_state_getters.hpp.

95 {
96 return getContinuousStateCovariance(obj.state);
97}
std::vector< double > getContinuousStateCovariance(const ObjectState &state)
Get the full continuous state covariance for a given object state. Empty storage yields INVALID diago...

◆ getContinuousStateCovarianceAt() [1/2]

double perception_msgs::object_access::getContinuousStateCovarianceAt ( const ObjectState &  state,
const unsigned int  i,
const unsigned int  j 
)
inline

Get the continuous state covariance entry (i,j) for a given object state.

Parameters
state
i
j
Returns
double

Definition at line 107 of file convenience_state_getters.hpp.

107 {
108 const int n = getContinuousStateSize(state);
109 if (i >= static_cast<unsigned int>(n) || j >= static_cast<unsigned int>(n))
110 throw std::out_of_range("Covariance coordinates out of range");
112 const auto& covariance = state.continuous_state_covariance;
113 if (covariance.empty()) return i == j ? CONTINUOUS_STATE_COVARIANCE_INVALID : CONTINUOUS_STATE_COVARIANCE_INIT;
114 return covariance.at(n * i + j);
115}

◆ getContinuousStateCovarianceAt() [2/2]

template<typename T >
double perception_msgs::object_access::getContinuousStateCovarianceAt ( const T &  obj,
const unsigned int  i,
const unsigned int  j 
)
inline

Get the continuous state covariance entry (i,j) for a given template object that contains an object state.

Template Parameters
T
Parameters
obj
i
j
Returns
double

Definition at line 127 of file convenience_state_getters.hpp.

127 {
128 return getContinuousStateCovarianceAt(obj.state, i, j);
129}

◆ getContinuousStateCovarianceDiagonal() [1/2]

std::vector< double > perception_msgs::object_access::getContinuousStateCovarianceDiagonal ( const ObjectState &  state)
inline

Get the continuous state covariance diagonal for a given object state.

Parameters
state
Returns
std::vector<double>

Definition at line 137 of file convenience_state_getters.hpp.

137 {
138 const int n = getContinuousStateSize(state);
139 std::vector<double> diagonal(n);
140 for (int i = 0; i < n; i++) diagonal[i] = getContinuousStateCovarianceAt(state, i, i);
141 return diagonal;
142}

◆ getContinuousStateCovarianceDiagonal() [2/2]

template<typename T >
std::vector< double > perception_msgs::object_access::getContinuousStateCovarianceDiagonal ( const T &  obj)
inline

Get the continuous state covariance diagonal for a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
std::vector<double>

Definition at line 152 of file convenience_state_getters.hpp.

152 {
153 return getContinuousStateCovarianceDiagonal(obj.state);
154}
std::vector< double > getContinuousStateCovarianceDiagonal(const ObjectState &state)
Get the continuous state covariance diagonal for a given object state.

◆ getDiscreteState() [1/2]

std::vector< long int > perception_msgs::object_access::getDiscreteState ( const ObjectState &  state)
inline

Get the discrete state for a given object state.

Parameters
state
Returns
std::vector<long int>

Definition at line 54 of file convenience_state_getters.hpp.

54 {
56 return state.discrete_state;
57}

◆ getDiscreteState() [2/2]

template<typename T >
std::vector< long int > perception_msgs::object_access::getDiscreteState ( const T &  obj)
inline

Get the discrete state for a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
std::vector<long int>

Definition at line 67 of file convenience_state_getters.hpp.

67 {
68 return getDiscreteState(obj.state);
69}
std::vector< long int > getDiscreteState(const ObjectState &state)
Get the discrete state for a given object state.

◆ getOrientation() [1/2]

gm::Quaternion perception_msgs::object_access::getOrientation ( const ObjectState &  state)
inline

Get the orientation of a given object state.

Parameters
state
Returns
gm::Quaternion

Definition at line 190 of file convenience_state_getters.hpp.

190 {
191 tf2::Quaternion q;
192 double roll{0}, pitch{0}, yaw{0};
193 if (hasRoll(state.model_id)) roll = getRoll(state);
194 if (hasPitch(state.model_id)) pitch = getPitch(state);
195 if (hasYaw(state.model_id)) yaw = getYaw(state);
196 q.setRPY(roll, pitch, yaw);
197 return tf2::toMsg(q);
198}
double getRoll(const ObjectState &state)
Get the roll for a given object state.
double getPitch(const ObjectState &state)
Get the pitch for a given object state.
bool hasYaw(const unsigned char &model_id)
Indicates if given model contains a yaw.
bool hasRoll(const unsigned char &model_id)
Indicates if given model contains a roll.
bool hasPitch(const unsigned char &model_id)
Indicates if given model contains a pitch.

◆ getOrientation() [2/2]

template<typename T >
gm::Quaternion perception_msgs::object_access::getOrientation ( const T &  obj)
inline

Get the orientation of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::Quaternion

Definition at line 208 of file convenience_state_getters.hpp.

208 {
209 return getOrientation(obj.state);
210}

◆ getPitchInDeg() [1/2]

double perception_msgs::object_access::getPitchInDeg ( const ObjectState &  state)
inline

Get the pitch in degree of a given object state.

Parameters
state
Returns
double

Definition at line 486 of file convenience_state_getters.hpp.

486{ return getPitch(state) * 180.0 / M_PI; }

◆ getPitchInDeg() [2/2]

template<typename T >
double perception_msgs::object_access::getPitchInDeg ( const T &  obj)
inline

Get the pitch in degree of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 496 of file convenience_state_getters.hpp.

496 {
497 return getPitchInDeg(obj.state);
498}
double getPitchInDeg(const ObjectState &state)
Get the pitch in degree of a given object state.

◆ getPose() [1/2]

gm::Pose perception_msgs::object_access::getPose ( const ObjectState &  state)
inline

Get the pose of a given object state.

Parameters
state
Returns
gm::Pose

Definition at line 218 of file convenience_state_getters.hpp.

218 {
219 gm::Pose pose;
220 pose.position = getPosition(state);
221 pose.orientation = getOrientation(state);
222 return pose;
223}

◆ getPose() [2/2]

template<typename T >
gm::Pose perception_msgs::object_access::getPose ( const T &  obj)
inline

Get the pose of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::Pose

Definition at line 265 of file convenience_state_getters.hpp.

265 {
266 return getPose(obj.state);
267}
gm::Pose getPose(const ObjectState &state)
Get the pose of a given object state.

◆ getPoseCovariance() [1/2]

std::vector< double > perception_msgs::object_access::getPoseCovariance ( const ObjectState &  state)
inline

Get the pose covariance of a given object state.

Parameters
state
Returns
std::vector<double>

Definition at line 275 of file convenience_state_getters.hpp.

275 {
276 const int n = 6;
277 const int model_id = state.model_id;
278 std::vector<double> pose_covariance(n * n, CONTINUOUS_STATE_COVARIANCE_INIT);
279 int ix, jx;
280 for (int i = 0; i < n; i++) {
281 for (int j = 0; j < n; j++) {
282 if (i == 0 && hasX(model_id))
283 ix = indexX(model_id);
284 else if (i == 1 && hasY(model_id))
285 ix = indexY(model_id);
286 else if (i == 2 && hasZ(model_id))
287 ix = indexZ(model_id);
288 else if (i == 3 && hasRoll(model_id))
289 ix = indexRoll(model_id);
290 else if (i == 4 && hasPitch(model_id))
291 ix = indexPitch(model_id);
292 else if (i == 5 && hasYaw(model_id))
293 ix = indexYaw(model_id);
294 else
295 continue;
296
297 if (j == 0 && hasX(model_id))
298 jx = indexX(model_id);
299 else if (j == 1 && hasY(model_id))
300 jx = indexY(model_id);
301 else if (j == 2 && hasZ(model_id))
302 jx = indexZ(model_id);
303 else if (j == 3 && hasRoll(model_id))
304 jx = indexRoll(model_id);
305 else if (j == 4 && hasPitch(model_id))
306 jx = indexPitch(model_id);
307 else if (j == 5 && hasYaw(model_id))
308 jx = indexYaw(model_id);
309 else
310 continue;
311
312 pose_covariance[n * i + j] = getContinuousStateCovarianceAt(state, ix, jx);
313 }
314 }
315 return pose_covariance;
316}
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 hasY(const unsigned char &model_id)
Indicates if given model contains a y-position.
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.
int indexZ(const unsigned char &model_id)
Get the vector-index that stores the z-position for a given model-id.
int indexPitch(const unsigned char &model_id)
Get the vector-index that stores the pitch 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.
int indexYaw(const unsigned char &model_id)
Get the vector-index that stores the yaw for a given model-id.

◆ getPoseCovariance() [2/2]

template<typename T >
std::vector< double > perception_msgs::object_access::getPoseCovariance ( const T &  obj)
inline

Get the pose covariance of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
std::vector<double>

Definition at line 326 of file convenience_state_getters.hpp.

326 {
327 return getPoseCovariance(obj.state);
328}
std::vector< double > getPoseCovariance(const ObjectState &state)
Get the pose covariance of a given object state.

◆ getPoseWithCovariance() [1/2]

gm::PoseWithCovariance perception_msgs::object_access::getPoseWithCovariance ( const ObjectState &  state)
inline

Get the pose with covariance of a given object state.

Parameters
state
Returns
gm::PoseWithCovariance

Definition at line 337 of file convenience_state_getters.hpp.

337 {
338 gm::PoseWithCovariance pose_with_covariance;
339 pose_with_covariance.pose = getPose(state);
340 std::vector<double> covariance_vector = getPoseCovariance(state);
341 gm::PoseWithCovariance::_covariance_type covariance;
342 std::copy(covariance_vector.begin(), covariance_vector.end(), covariance.begin());
343 pose_with_covariance.covariance = covariance;
344 return pose_with_covariance;
345}

◆ getPoseWithCovariance() [2/2]

template<typename T >
gm::PoseWithCovariance perception_msgs::object_access::getPoseWithCovariance ( const T &  obj)
inline

Get the pose with covariance of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::PoseWithCovariance

Definition at line 355 of file convenience_state_getters.hpp.

355 {
356 return getPoseWithCovariance(obj.state);
357}
gm::PoseWithCovariance getPoseWithCovariance(const ObjectState &state)
Get the pose with covariance of a given object state.

◆ getPosition() [1/2]

gm::Point perception_msgs::object_access::getPosition ( const ObjectState &  state)
inline

Get the position of a given object state.

Parameters
state
Returns
gm::Point

Definition at line 164 of file convenience_state_getters.hpp.

164 {
165 gm::Point position;
166 position.x = getX(state);
167 position.y = getY(state);
168 position.z = getZ(state);
169 return position;
170}
double getZ(const ObjectState &state)
Get the z-position 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.

◆ getPosition() [2/2]

template<typename T >
gm::Point perception_msgs::object_access::getPosition ( const T &  obj)
inline

Get the position of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::Point

Definition at line 180 of file convenience_state_getters.hpp.

180 {
181 return getPosition(obj.state);
182}

◆ getRollInDeg() [1/2]

double perception_msgs::object_access::getRollInDeg ( const ObjectState &  state)
inline

Get the roll in degree of a given object state.

Parameters
state
Returns
double

Definition at line 466 of file convenience_state_getters.hpp.

466{ return getRoll(state) * 180.0 / M_PI; }

◆ getRollInDeg() [2/2]

template<typename T >
double perception_msgs::object_access::getRollInDeg ( const T &  obj)
inline

Get the roll in degree of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 476 of file convenience_state_getters.hpp.

476 {
477 return getRollInDeg(obj.state);
478}
double getRollInDeg(const ObjectState &state)
Get the roll in degree of a given object state.

◆ getVelocity() [1/2]

gm::Vector3 perception_msgs::object_access::getVelocity ( const ObjectState &  state)
inline

Get the velocity of a given object state.

Parameters
state
Returns
gm::Vector3

Definition at line 365 of file convenience_state_getters.hpp.

365 {
366 gm::Vector3 velocity;
367 velocity.x = getVelLon(state);
368 velocity.y = getVelLat(state);
369 velocity.z = 0.0;
370 return velocity;
371}
double getVelLon(const ObjectState &state)
Get the longitudinal velocity for a given object state.
double getVelLat(const ObjectState &state)
Get the longitudinal velocity for a given object state.

◆ getVelocity() [2/2]

template<typename T >
gm::Vector3 perception_msgs::object_access::getVelocity ( const T &  obj)
inline

Get the velocity of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::Vector3

Definition at line 381 of file convenience_state_getters.hpp.

381 {
382 return getVelocity(obj.state);
383}
gm::Vector3 getVelocity(const ObjectState &state)
Get the velocity of a given object state.

◆ getVelocityMagnitude() [1/2]

double perception_msgs::object_access::getVelocityMagnitude ( const ObjectState &  state)
inline

Get the velocity magnitude of a given object state.

Parameters
state
Returns
double

Definition at line 391 of file convenience_state_getters.hpp.

391 {
392 gm::Vector3 vel = getVelocity(state);
393 using namespace std;
394 return sqrt(pow(vel.x, 2) + pow(vel.y, 2) + pow(vel.z, 2));
395}

◆ getVelocityMagnitude() [2/2]

template<typename T >
double perception_msgs::object_access::getVelocityMagnitude ( const T &  obj)
inline

Get the velocity magnitude of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 405 of file convenience_state_getters.hpp.

405 {
406 return getVelocityMagnitude(obj.state);
407}
double getVelocityMagnitude(const ObjectState &state)
Get the velocity magnitude of a given object state.

◆ getVelocityXYZ() [1/2]

gm::Vector3 perception_msgs::object_access::getVelocityXYZ ( const ObjectState &  state)
inline

Get the velocity XYZ of a given object state.

Parameters
state
Returns
gm::Vector3

Definition at line 585 of file convenience_state_getters.hpp.

585 {
586 gm::Vector3 vel_lon_lat, vel_xyz;
587 vel_lon_lat = getVelocity(state);
588 tf2::Quaternion q;
589 q.setRPY(0.0, 0.0, getYaw(state));
590 gm::TransformStamped tf;
591 tf.transform.rotation = tf2::toMsg(q);
592 tf2::doTransform(vel_lon_lat, vel_xyz, tf);
593 return vel_xyz;
594}

◆ getVelocityXYZ() [2/2]

template<typename T >
gm::Vector3 perception_msgs::object_access::getVelocityXYZ ( const T &  obj)
inline

Get the velocity XYZ of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::Vector3

Definition at line 604 of file convenience_state_getters.hpp.

604 {
605 return getVelocityXYZ(obj.state);
606}
gm::Vector3 getVelocityXYZ(const ObjectState &state)
Get the velocity XYZ of a given object state.

◆ getVelocityXYZWithCovariance() [1/2]

gm::PoseWithCovariance perception_msgs::object_access::getVelocityXYZWithCovariance ( const ObjectState &  state)
inline

Get the velocity XYZ with covariance of a object state.

Parameters
state
Returns
gm::PoseWithCovariance

Definition at line 526 of file convenience_state_getters.hpp.

526 {
527 gm::PoseWithCovariance vel_lon_lat, vel_xyz;
528 vel_lon_lat.pose.position.x = getVelLon(state);
529 vel_lon_lat.pose.position.y = getVelLat(state);
530 vel_lon_lat.pose.position.z = 0.0;
531
532 int ix, jx, n = 2;
533 auto model_id = state.model_id;
534 for (int i = 0; i < n; i++) {
535 for (int j = 0; j < n; j++) {
536 if (i == 0 && hasVelLon(model_id))
537 ix = indexVelLon(model_id);
538 else if (i == 1 && hasVelLat(model_id))
539 ix = indexVelLat(model_id);
540 else
541 continue;
542
543 if (j == 0 && hasVelLon(model_id))
544 jx = indexVelLon(model_id);
545 else if (j == 1 && hasVelLat(model_id))
546 jx = indexVelLat(model_id);
547 else
548 continue;
549
550 vel_lon_lat.covariance.at(6 * i + j) = getContinuousStateCovarianceAt(state, ix, jx);
551 }
552 }
553
554 tf2::Quaternion q;
555 q.setRPY(0.0, 0.0, getYaw(state));
556 gm::TransformStamped tf;
557 tf.transform.rotation = tf2::toMsg(q);
558
559 gm::PoseWithCovarianceStamped vel_lon_lat_stamped, vel_xyz_stamped;
560 vel_lon_lat_stamped.pose = vel_lon_lat;
561 transformPoseWithCovariance(vel_lon_lat_stamped, vel_xyz_stamped, tf);
562 vel_xyz = vel_xyz_stamped.pose;
563
564 return vel_xyz;
565}
int indexVelLon(const unsigned char &model_id)
Get the vector-index that stores the longitudinal velocity for a given model-id.
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 hasVelLon(const unsigned char &model_id)
Indicates if given model contains a longitudinal velocity.

◆ getVelocityXYZWithCovariance() [2/2]

template<typename T >
gm::PoseWithCovariance perception_msgs::object_access::getVelocityXYZWithCovariance ( const T &  obj)
inline

Get the velocity XYZ with covariance of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
gm::PoseWithCovariance

Definition at line 575 of file convenience_state_getters.hpp.

575 {
576 return getVelocityXYZWithCovariance(obj.state);
577}
gm::PoseWithCovariance getVelocityXYZWithCovariance(const ObjectState &state)
Get the velocity XYZ with covariance of a object state.

◆ getVelX() [1/2]

double perception_msgs::object_access::getVelX ( const ObjectState &  state)
inline

Get the x-velocity of a given object state.

Parameters
state
Returns
double

Definition at line 614 of file convenience_state_getters.hpp.

614{ return getVelocityXYZ(state).x; }

◆ getVelX() [2/2]

template<typename T >
double perception_msgs::object_access::getVelX ( const T &  obj)
inline

Get the x-velocity of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 624 of file convenience_state_getters.hpp.

624 {
625 return getVelX(obj.state);
626}
double getVelX(const ObjectState &state)
Get the x-velocity of a given object state.

◆ getVelY() [1/2]

double perception_msgs::object_access::getVelY ( const ObjectState &  state)
inline

Get the y-velocity of a given object state.

Parameters
state
Returns
double

Definition at line 634 of file convenience_state_getters.hpp.

634{ return getVelocityXYZ(state).y; }

◆ getVelY() [2/2]

template<typename T >
double perception_msgs::object_access::getVelY ( const T &  obj)
inline

Get the y-velocity of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 644 of file convenience_state_getters.hpp.

644 {
645 return getVelY(obj.state);
646}
double getVelY(const ObjectState &state)
Get the y-velocity of a given object state.

◆ getYawInDeg() [1/2]

double perception_msgs::object_access::getYawInDeg ( const ObjectState &  state)
inline

Get the yaw in degree of a given object state.

Parameters
state
Returns
double

Definition at line 506 of file convenience_state_getters.hpp.

506{ return getYaw(state) * 180.0 / M_PI; }

◆ getYawInDeg() [2/2]

template<typename T >
double perception_msgs::object_access::getYawInDeg ( const T &  obj)
inline

Get the yaw in degree of a given template object that contains an object state.

Template Parameters
T
Parameters
obj
Returns
double

Definition at line 516 of file convenience_state_getters.hpp.

516 {
517 return getYawInDeg(obj.state);
518}
double getYawInDeg(const ObjectState &state)
Get the yaw in degree of a given object state.