Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/noetic-devel-backup' into noetic…
Browse files Browse the repository at this point in the history
…-devel
  • Loading branch information
mkorkmz committed Jul 19, 2023
2 parents 6d10593 + 351f7e0 commit 3842303
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
.vscode
7 changes: 7 additions & 0 deletions include/twist_mux/twist_mux.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ class TwistMux
// @todo alternatively we do the following:
typedef std::list<VelocityTopicHandle> velocity_topic_container;
typedef std::list<LockTopicHandle> lock_topic_container;
typedef std::list<LockTopicHandle> backward_filter_topic_container;
typedef std::list<LockTopicHandle> forward_filter_topic_container;

TwistMux(int window_size = 10);
~TwistMux();

bool hasPriority(const VelocityTopicHandle& twist);

bool filterBackwardMovement();
bool filterForwardMovement();

void publishTwist(const geometry_msgs::TwistConstPtr& msg);

void updateDiagnostics(const ros::TimerEvent& event);
Expand All @@ -81,6 +86,8 @@ class TwistMux
//handle_container<LockTopicHandle> lock_hs_;
boost::shared_ptr<velocity_topic_container> velocity_hs_;
boost::shared_ptr<lock_topic_container> lock_hs_;
boost::shared_ptr<backward_filter_topic_container> backward_filter_hs_;
boost::shared_ptr<forward_filter_topic_container> forward_filter_hs_;

ros::Publisher cmd_pub_;

Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package>
<name>twist_mux</name>
<version>3.1.3</version>
<version>4.1.1</version>
<description>
Twist multiplexer, which multiplex several velocity commands (topics) and
allows to priorize or disable them (locks).
Expand Down
45 changes: 45 additions & 0 deletions src/twist_mux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ TwistMux::TwistMux(int window_size)
/// Get topics and locks:
velocity_hs_ = boost::make_shared<velocity_topic_container>();
lock_hs_ = boost::make_shared<lock_topic_container>();
backward_filter_hs_ = boost::make_shared<backward_filter_topic_container>();
forward_filter_hs_ = boost::make_shared<forward_filter_topic_container>();

getTopicHandles(nh, nh_priv, "topics", *velocity_hs_);
getTopicHandles(nh, nh_priv, "locks" , *lock_hs_ );
getTopicHandles(nh, nh_priv, "backward_filters" , *backward_filter_hs_ );
getTopicHandles(nh, nh_priv, "forward_filters" , *forward_filter_hs_ );

/// Publisher for output topic:
cmd_pub_ = nh.advertise<geometry_msgs::Twist>("cmd_vel_out", 1);
Expand All @@ -82,6 +87,19 @@ void TwistMux::updateDiagnostics(const ros::TimerEvent& event)

void TwistMux::publishTwist(const geometry_msgs::TwistConstPtr& msg)
{
if(filterBackwardMovement() && msg->linear.x > 0.0)
{
geometry_msgs::Twist zmsg;
cmd_pub_.publish(zmsg);
return;
}
if (filterForwardMovement() && msg->linear.x < 0.0)
{
geometry_msgs::Twist zmsg;
cmd_pub_.publish(zmsg);
return;
}

cmd_pub_.publish(*msg);
}

Expand Down Expand Up @@ -163,4 +181,31 @@ bool TwistMux::hasPriority(const VelocityTopicHandle& twist)
return twist.getName() == velocity_name;
}

bool TwistMux::filterBackwardMovement()
{
for(const auto& backward_filter_h : *backward_filter_hs_)
{
if(backward_filter_h.isLocked())
{
return true;
}
}

return false;
}

bool TwistMux::filterForwardMovement()
{
for(const auto& forward_filter_h : *forward_filter_hs_)
{
if(forward_filter_h.isLocked())
{
return true;
}
}

return false;
}


} // namespace twist_mux

0 comments on commit 3842303

Please sign in to comment.