wip-behaviors #3
@@ -29,6 +29,7 @@ set(
|
|||||||
SOURCES
|
SOURCES
|
||||||
src/simple_move.cpp
|
src/simple_move.cpp
|
||||||
src/simple_rotate.cpp
|
src/simple_rotate.cpp
|
||||||
|
src/simple_translate_x.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(ament_cmake REQUIRED)
|
find_package(ament_cmake REQUIRED)
|
||||||
|
|||||||
53
toid_behaviors/include/toid_behaviors/simple_translate_x.hpp
Normal file
53
toid_behaviors/include/toid_behaviors/simple_translate_x.hpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "toid_behaviors/simple_move.hpp"
|
||||||
|
#include "toid_msgs/action/simple_translate_x.hpp"
|
||||||
|
|
||||||
|
namespace toid
|
||||||
|
{
|
||||||
|
using TranslateAction = toid_msgs::action::SimpleTranslateX;
|
||||||
|
using namespace nav2_behaviors;
|
||||||
|
|
||||||
|
class SimpleTranslateXBehavior : public SimpleMove<TranslateAction>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SimpleTranslateXBehavior();
|
||||||
|
~SimpleTranslateXBehavior();
|
||||||
|
|
||||||
|
void configureCB() override;
|
||||||
|
|
||||||
|
ResultStatus onStart(
|
||||||
|
const std::shared_ptr<const TranslateAction::Goal> command, const geometry_msgs::msg::Pose & pose,
|
||||||
|
const geometry_msgs::msg::Twist & vel) override;
|
||||||
|
|
||||||
|
ResultStatus updateVel(
|
||||||
|
const geometry_msgs::msg::Pose & pose, const geometry_msgs::msg::Twist & vel,
|
||||||
|
geometry_msgs::msg::Twist & out_vel) override;
|
||||||
|
|
||||||
|
virtual nav2_core::CostmapInfoType getResourceInfo() override {
|
||||||
|
return nav2_core::CostmapInfoType::NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
//Goal
|
||||||
|
double target_distance_;
|
||||||
|
double target_angle_;
|
||||||
|
double target_sign_;
|
||||||
|
geometry_msgs::msg::Pose initial_pose_;
|
||||||
|
|
||||||
|
//State
|
||||||
|
double speed_;
|
||||||
|
|
||||||
|
//Config
|
||||||
|
double max_vel_accel_;
|
||||||
|
double max_vel_decel_;
|
||||||
|
double max_vel_speed_;
|
||||||
|
double min_vel_speed_;
|
||||||
|
double max_angular_speed_;
|
||||||
|
|
||||||
|
double kp_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace toid
|
||||||
|
|
||||||
96
toid_behaviors/src/simple_translate_x.cpp
Normal file
96
toid_behaviors/src/simple_translate_x.cpp
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
#include "toid_behaviors/simple_translate_x.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include "angles/angles.h"
|
||||||
|
#include "tf2/convert.hpp"
|
||||||
|
|
||||||
|
namespace toid
|
||||||
|
{
|
||||||
|
|
||||||
|
SimpleTranslateXBehavior::SimpleTranslateXBehavior() : SimpleMove<TranslateAction>() {}
|
||||||
|
SimpleTranslateXBehavior::~SimpleTranslateXBehavior() {}
|
||||||
|
|
||||||
|
void SimpleTranslateXBehavior::configureCB()
|
||||||
|
{
|
||||||
|
auto node = node_.lock();
|
||||||
|
nav2_util::declare_parameter_if_not_declared(
|
||||||
|
node, behavior_name_ + ".max_vel_accel", rclcpp::ParameterValue(2.0));
|
||||||
|
node->get_parameter(behavior_name_ + ".max_vel_accel", max_vel_accel_);
|
||||||
|
|
||||||
|
nav2_util::declare_parameter_if_not_declared(
|
||||||
|
node, behavior_name_ + ".max_vel_decel", rclcpp::ParameterValue(1.0));
|
||||||
|
node->get_parameter(behavior_name_ + ".max_vel_decel", max_vel_decel_);
|
||||||
|
|
||||||
|
nav2_util::declare_parameter_if_not_declared(
|
||||||
|
node, behavior_name_ + ".max_vel_speed", rclcpp::ParameterValue(0.4));
|
||||||
|
node->get_parameter(behavior_name_ + ".max_vel_speed", max_vel_speed_);
|
||||||
|
|
||||||
|
nav2_util::declare_parameter_if_not_declared(
|
||||||
|
node, behavior_name_ + ".min_vel_speed", rclcpp::ParameterValue(0.007));
|
||||||
|
node->get_parameter(behavior_name_ + ".min_vel_speed", min_vel_speed_);
|
||||||
|
|
||||||
|
nav2_util::declare_parameter_if_not_declared(
|
||||||
|
node, behavior_name_ + ".max_angular_speed", rclcpp::ParameterValue(1.0));
|
||||||
|
node->get_parameter(behavior_name_ + ".max_angular_speed", max_angular_speed_);
|
||||||
|
|
||||||
|
nav2_util::declare_parameter_if_not_declared(
|
||||||
|
node, behavior_name_ + ".kp", rclcpp::ParameterValue(5.0));
|
||||||
|
node->get_parameter(behavior_name_ + ".kp", kp_);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultStatus SimpleTranslateXBehavior::onStart(
|
||||||
|
const std::shared_ptr<const TranslateAction::Goal> command, const geometry_msgs::msg::Pose & pose,
|
||||||
|
const geometry_msgs::msg::Twist & vel)
|
||||||
|
{
|
||||||
|
target_distance_ = command->distance;
|
||||||
|
target_angle_ = tf2::getYaw(pose.orientation);
|
||||||
|
target_sign_ = (target_distance_ < 0) ? -1.0 : 1.0;
|
||||||
|
|
||||||
|
target_distance_ *= target_sign_;
|
||||||
|
|
||||||
|
initial_pose_ = pose;
|
||||||
|
speed_ = vel.angular.x;
|
||||||
|
|
||||||
|
return ResultStatus{Status::SUCCEEDED};
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultStatus SimpleTranslateXBehavior::updateVel(
|
||||||
|
const geometry_msgs::msg::Pose & pose, const geometry_msgs::msg::Twist &,
|
||||||
|
geometry_msgs::msg::Twist & out_vel)
|
||||||
|
{
|
||||||
|
const double current_yaw = tf2::getYaw(pose.orientation);
|
||||||
|
const double angle_dist = angles::shortest_angular_distance(current_yaw, target_angle_);
|
||||||
|
|
||||||
|
const double dx = pose.position.x - initial_pose_.position.x;
|
||||||
|
const double dy = pose.position.y - initial_pose_.position.y;
|
||||||
|
const double dist_passed = target_sign_ * (dx * cos(target_angle_) + dy * sin(target_angle_));
|
||||||
|
|
||||||
|
const double lower_bound = speed_ - control_duration_ * max_vel_accel_;
|
||||||
|
const double upper_bound = speed_ + control_duration_ * max_vel_accel_;
|
||||||
|
|
||||||
|
float vel = std::clamp(max_vel_speed_, lower_bound, upper_bound);
|
||||||
|
float max_vel_to_stop =
|
||||||
|
0.8 * std::sqrt(2.0 * max_vel_decel_ * std::abs(target_distance_ - dist_passed));
|
||||||
|
|
||||||
|
vel = std::min(vel, max_vel_to_stop);
|
||||||
|
const double w = std::clamp(kp_ * angle_dist, -max_angular_speed_, max_angular_speed_);
|
||||||
|
|
||||||
|
if (dist_passed >= target_distance_) {
|
||||||
|
out_vel.linear.x = 0;
|
||||||
|
out_vel.angular.z = 0;
|
||||||
|
return ResultStatus{Status::SUCCEEDED};
|
||||||
|
}
|
||||||
|
|
||||||
|
out_vel.linear.x = target_sign_ * vel;
|
||||||
|
out_vel.angular.z = w;
|
||||||
|
|
||||||
|
speed_ = vel;
|
||||||
|
|
||||||
|
return ResultStatus{Status::RUNNING};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace toid
|
||||||
|
|
||||||
|
#include "pluginlib/class_list_macros.hpp"
|
||||||
|
PLUGINLIB_EXPORT_CLASS(toid::SimpleTranslateXBehavior, nav2_core::Behavior);
|
||||||
@@ -3,5 +3,8 @@
|
|||||||
<class type="toid::SimpleRotateBehavior" base_class_type="nav2_core::Behavior">
|
<class type="toid::SimpleRotateBehavior" base_class_type="nav2_core::Behavior">
|
||||||
<description></description>
|
<description></description>
|
||||||
</class>
|
</class>
|
||||||
|
<class type="toid::SimpleTranslateXBehavior" base_class_type="nav2_core::Behavior">
|
||||||
|
<description></description>
|
||||||
|
</class>
|
||||||
</library>
|
</library>
|
||||||
</class_libraries>
|
</class_libraries>
|
||||||
@@ -12,6 +12,7 @@ find_package(rosidl_default_generators REQUIRED)
|
|||||||
rosidl_generate_interfaces(${PROJECT_NAME}
|
rosidl_generate_interfaces(${PROJECT_NAME}
|
||||||
"srv/SendDouble.srv"
|
"srv/SendDouble.srv"
|
||||||
"action/SimpleRotate.action"
|
"action/SimpleRotate.action"
|
||||||
|
"action/SimpleTranslateX.action"
|
||||||
)
|
)
|
||||||
|
|
||||||
ament_package()
|
ament_package()
|
||||||
12
toid_msgs/action/SimpleTranslateX.action
Normal file
12
toid_msgs/action/SimpleTranslateX.action
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
uint8 IGNORE_OBSTACLES=1
|
||||||
|
|
||||||
|
float64 distance
|
||||||
|
uint8 mode 0
|
||||||
|
---
|
||||||
|
uint16 NONE=0
|
||||||
|
uint16 TF_ERROR=1
|
||||||
|
|
||||||
|
builtin_interfaces/Duration total_elapsed_time
|
||||||
|
uint16 error_code
|
||||||
|
string error_msg
|
||||||
|
---
|
||||||
@@ -22,7 +22,7 @@ behavior_server:
|
|||||||
local_footprint_topic: local_costmap/published_footprint
|
local_footprint_topic: local_costmap/published_footprint
|
||||||
global_footprint_topic: global_costmap/published_footprint
|
global_footprint_topic: global_costmap/published_footprint
|
||||||
cycle_frequency: 50.0
|
cycle_frequency: 50.0
|
||||||
behavior_plugins: ["backup", "spin", "drive_on_heading", "assisted_teleop", "wait", "rotate"]
|
behavior_plugins: ["backup", "spin", "drive_on_heading", "assisted_teleop", "wait", "rotate", "translateX"]
|
||||||
spin:
|
spin:
|
||||||
plugin: "nav2_behaviors::Spin"
|
plugin: "nav2_behaviors::Spin"
|
||||||
backup:
|
backup:
|
||||||
@@ -37,6 +37,8 @@ behavior_server:
|
|||||||
plugin: "toid::SimpleRotateBehavior"
|
plugin: "toid::SimpleRotateBehavior"
|
||||||
max_angular_accel: 4.0
|
max_angular_accel: 4.0
|
||||||
max_angular_decel: 1.0
|
max_angular_decel: 1.0
|
||||||
|
translateX:
|
||||||
|
plugin: "toid::SimpleTranslateXBehavior"
|
||||||
local_frame: map
|
local_frame: map
|
||||||
global_frame: map
|
global_frame: map
|
||||||
robot_base_frame: base_footprint
|
robot_base_frame: base_footprint
|
||||||
|
|||||||
Reference in New Issue
Block a user