Skip to content
Snippets Groups Projects
Commit d34fa6fd authored by Martí Morta Garriga's avatar Martí Morta Garriga
Browse files

publisher in mainNodeThread since cmd_vel is not sent in a constant rate

parent 5f3a2245
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ class SafeCmdAlgNode : public algorithm_base::IriBaseAlgorithm<SafeCmdAlgorithm> ...@@ -46,6 +46,7 @@ class SafeCmdAlgNode : public algorithm_base::IriBaseAlgorithm<SafeCmdAlgorithm>
// [publisher attributes] // [publisher attributes]
ros::Publisher cmd_vel_safe_publisher_; ros::Publisher cmd_vel_safe_publisher_;
geometry_msgs::Twist Twist_msg_; geometry_msgs::Twist Twist_msg_;
geometry_msgs::Twist last_twist_;
// [subscriber attributes] // [subscriber attributes]
ros::Subscriber cmd_vel_subscriber_; ros::Subscriber cmd_vel_subscriber_;
......
...@@ -35,12 +35,24 @@ void SafeCmdAlgNode::mainNodeThread(void) ...@@ -35,12 +35,24 @@ void SafeCmdAlgNode::mainNodeThread(void)
{ {
// [fill msg structures] // [fill msg structures]
//this->Twist_msg_.data = my_var; //this->Twist_msg_.data = my_var;
Twist_msg_ = last_twist_;
if(front_obstacle_ && last_twist_.linear.x > 0.0)
{
Twist_msg_.linear.x = 0.0;
ROS_WARN("heading to front obstacle avoided");
}
if(rear_obstacle_ && last_twist_.linear.x < 0.0)
{
Twist_msg_.linear.x = 0.0;
ROS_WARN("heading to rear obstacle avoided");
}
// [fill srv structure and make request to the server] // [fill srv structure and make request to the server]
// [fill action structure and make request to the action server] // [fill action structure and make request to the action server]
// [publish messages] // [publish messages]
cmd_vel_safe_publisher_.publish(Twist_msg_);
} }
...@@ -52,16 +64,7 @@ void SafeCmdAlgNode::cmd_vel_callback(const geometry_msgs::Twist::ConstPtr& msg) ...@@ -52,16 +64,7 @@ void SafeCmdAlgNode::cmd_vel_callback(const geometry_msgs::Twist::ConstPtr& msg)
//use appropiate mutex to shared variables if necessary //use appropiate mutex to shared variables if necessary
//this->alg_.lock(); //this->alg_.lock();
//this->cmd_vel_mutex_.enter(); //this->cmd_vel_mutex_.enter();
Twist_msg_=*msg; last_twist_=*msg;
if(front_obstacle_ && msg->linear.x > 0.0)
Twist_msg_.linear.x = 0.0;
if(rear_obstacle_ && msg->linear.x < 0.0)
Twist_msg_.linear.x = 0.0;
cmd_vel_safe_publisher_.publish(Twist_msg_);
//unlock previously blocked shared variables //unlock previously blocked shared variables
//this->alg_.unlock(); //this->alg_.unlock();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment