18 #ifndef SPEED_OBSERVER_H 19 #define SPEED_OBSERVER_H 29 #include <prbt_hardware_support/FrameSpeeds.h> 30 #include <prbt_hardware_support/SetSpeedLimit.h> 62 bool setSpeedLimitCb(SetSpeedLimit::Request& req, SetSpeedLimit::Response& res);
90 const unsigned short int max_num_retries = 10)
const;
98 std::pair<tf2::Vector3, ros::Time>
getLatestPose(
const std::string& frame)
const;
117 static double speedFromTwoPoses(
const tf2::Vector3& a,
const tf2::Vector3& b,
const double&
t);
174 #endif // SPEED_OBSERVER_H
std::map< std::string, unsigned int > missed_calculations_
Map to store the number of successive missed frame transform calculations.
std::atomic_bool terminate_
Helper variable to stop observation cycle.
void triggerStop1()
Used to trigger stop of the robot when speed limit is exceeded.
void terminateNow()
This method will terminate the observation cycle started by startObserving().
void waitUntillCanTransform(const std::string &frame, const ros::Time &time, const unsigned short int max_num_retries=10) const
Helper method waiting until TF transformation is available.
std::pair< tf2::Vector3, ros::Time > getLatestPose(const std::string &frame) const
Using tf to get the latest Pose of a frame as tf::Vector3.
SpeedObserver(ros::NodeHandle &nh, std::string &reference_frame, std::vector< std::string > &frames_to_observe)
Create an observer to observe the speed of a list of frames in reference to a reference frame...
geometry_msgs::TransformStamped t
tf2_ros::Buffer tf_buffer_
Needed to receive tf2 transformations over the wire, see https://wiki.ros.org/tf2/Tutorials/.
static double speedFromTwoPoses(const tf2::Vector3 &a, const tf2::Vector3 &b, const double &t)
Calculate the minimal speed that a trajectory between two poses had if the motion was performed withi...
static constexpr double TIME_INTERVAL_EPSILON_S
Epsilon prevents computation of speed for small time intervals.
static constexpr double WAITING_TIME_FOR_TRANSFORM_S
Waiting time for waitUntillCanTransform()
static constexpr uint32_t DEFAULT_QUEUE_SIZE
Default queue size for publisher.
bool isWithinLimit(const double &speed) const
Check if a speed value is within the currently set limit.
static constexpr double DEFAULT_SPEED_LIMIT
Speed limit to be set at launch.
const std::string reference_frame_
Reference frame for all speeds.
const std::vector< std::string > frames_to_observe_
All frames to observe.
bool setSpeedLimitCb(SetSpeedLimit::Request &req, SetSpeedLimit::Response &res)
Callback for service to set the currently active speed limit.
ros::ServiceClient run_permitted_client_
Client for run_permitted service.
TF2SIMD_FORCE_INLINE tf2Scalar tf2Distance(const Vector3 &v1, const Vector3 &v2)
static constexpr unsigned int DEFAULT_ALLOWED_MISSED_CALCULATIONS
Allowed number of missed calculations. If it is exceeded a Stop1 is triggered.
ros::Publisher frame_speeds_pub_
Publisher for frame speed message.
tf2_ros::TransformListener tf_listener
Listing to TF Transforms.
FrameSpeeds createFrameSpeedsMessage(const std::map< std::string, double > &speeds) const
Creates a message to be sent to the 'frame_speeds' topic.
void startObserving(const double frequency, const unsigned int allowed_missed_calculations=DEFAULT_ALLOWED_MISSED_CALCULATIONS)
Starts the observation cycle. The function blocks until ros shuts down.
double current_speed_limit_
Currently active speed limit.