Skip to content

Commit

Permalink
update sfm,, they move, but still some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhanyuGuo committed Feb 13, 2024
1 parent 26f1487 commit 91b260d
Show file tree
Hide file tree
Showing 19 changed files with 1,641 additions and 91 deletions.
4 changes: 2 additions & 2 deletions scripts/main_orca.sh → scripts/main_multi.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
gnome-terminal -- bash -c "./orca.sh"
gnome-terminal -- bash -c "./multi.sh"

echo "Waiting for initialization (sleep 15s)..."
sleep 15
source ../devel/setup.bash
rosrun orca_planner goal_publisher.py
rosrun sim_env goal_publisher.py
2 changes: 1 addition & 1 deletion scripts/orca.sh → scripts/multi.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source ../devel/setup.bash
python ../src/third_party/dynamic_xml_config/main_generate.py user_config_orca.yaml
python ../src/third_party/dynamic_xml_config/main_generate.py user_config_multi.yaml
roslaunch sim_env main.launch
2 changes: 1 addition & 1 deletion src/core/local_planner/orca_planner/include/orca_planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OrcaPlanner : public nav_core::BaseLocalPlanner, local_planner::LocalPlann
private:
costmap_2d::Costmap2DROS* costmap_ros_;
tf2_ros::Buffer* tf_;
bool initialized_, odom_flag_, goal_reached_;
bool initialized_, odom_flag_, goal_reached_, first_plan_;

int agent_number_, agent_id_; // id begin from 1
double d_t_; // control time step
Expand Down
80 changes: 41 additions & 39 deletions src/core/local_planner/orca_planner/src/orca_planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace orca_planner
{

OrcaPlanner::OrcaPlanner()
: initialized_(false), costmap_ros_(nullptr), tf_(nullptr), odom_flag_(false), goal_reached_(false)
: initialized_(false), costmap_ros_(nullptr), tf_(nullptr), odom_flag_(false), goal_reached_(false), first_plan_(true)
{
}

Expand Down Expand Up @@ -90,6 +90,32 @@ void OrcaPlanner::initialize(std::string name, tf2_ros::Buffer* tf, costmap_2d::
}
}

void OrcaPlanner::initState()
{
if (!odom_flag_)
{
ROS_ERROR("Odom not received!");
return;
}

sim_->setTimeStep(d_t_);
sim_->setAgentDefaults(neighbor_dist_, max_neighbors_, time_horizon_, time_horizon_obst_, radius_, max_v_);

for (int i = 0; i < agent_number_; ++i)
{
sim_->addAgent(RVO::Vector2(other_odoms_[i].pose.pose.position.x, other_odoms_[i].pose.pose.position.y));
sim_->setAgentVelocity(i, RVO::Vector2(other_odoms_[i].twist.twist.linear.x, other_odoms_[i].twist.twist.linear.y));
}
}

void OrcaPlanner::odometryCallback(const nav_msgs::OdometryConstPtr& msg, int agent_id)
{
if (!odom_flag_)
odom_flag_ = true;

other_odoms_[agent_id - 1] = *msg;
}

bool OrcaPlanner::setPlan(const std::vector<geometry_msgs::PoseStamped>& orig_global_plan)
{
if (!initialized_)
Expand All @@ -100,8 +126,10 @@ bool OrcaPlanner::setPlan(const std::vector<geometry_msgs::PoseStamped>& orig_gl

ROS_INFO("Got new plan");

if (goal_.x() != orig_global_plan.back().pose.position.x || goal_.y() != orig_global_plan.back().pose.position.y)
if (first_plan_ || goal_.x() != orig_global_plan.back().pose.position.x ||
goal_.y() != orig_global_plan.back().pose.position.y)
{
first_plan_ = false;
goal_ = RVO::Vector2(orig_global_plan.back().pose.position.x, orig_global_plan.back().pose.position.y);
goal_reached_ = false;
}
Expand Down Expand Up @@ -145,6 +173,17 @@ bool OrcaPlanner::computeVelocityCommands(geometry_msgs::Twist& cmd_vel)
return true;
}

void OrcaPlanner::updateState()
{
for (int i = 0; i < agent_number_; ++i)
{
sim_->setAgentPosition(i, RVO::Vector2(other_odoms_[i].pose.pose.position.x, other_odoms_[i].pose.pose.position.y));
sim_->setAgentVelocity(i, RVO::Vector2(other_odoms_[i].twist.twist.linear.x, other_odoms_[i].twist.twist.linear.y));
}

sim_->setAgentPrefVelocity(agent_id_ - 1, RVO::normalize(goal_ - sim_->getAgentPosition(agent_id_ - 1)) * max_v_);
}

bool OrcaPlanner::isGoalReached()
{
if (!initialized_)
Expand All @@ -161,41 +200,4 @@ bool OrcaPlanner::isGoalReached()
return false;
}

void OrcaPlanner::initState()
{
if (!odom_flag_)
{
ROS_ERROR("Odom not received!");
return;
}

sim_->setTimeStep(d_t_);
sim_->setAgentDefaults(neighbor_dist_, max_neighbors_, time_horizon_, time_horizon_obst_, radius_, max_v_);

for (int i = 0; i < agent_number_; ++i)
{
sim_->addAgent(RVO::Vector2(other_odoms_[i].pose.pose.position.x, other_odoms_[i].pose.pose.position.y));
sim_->setAgentVelocity(i, RVO::Vector2(other_odoms_[i].twist.twist.linear.x, other_odoms_[i].twist.twist.linear.y));
}
}

void OrcaPlanner::odometryCallback(const nav_msgs::OdometryConstPtr& msg, int agent_id)
{
if (!odom_flag_)
odom_flag_ = true;

other_odoms_[agent_id - 1] = *msg;
}

void OrcaPlanner::updateState()
{
for (int i = 0; i < agent_number_; ++i)
{
sim_->setAgentPosition(i, RVO::Vector2(other_odoms_[i].pose.pose.position.x, other_odoms_[i].pose.pose.position.y));
sim_->setAgentVelocity(i, RVO::Vector2(other_odoms_[i].twist.twist.linear.x, other_odoms_[i].twist.twist.linear.y));
}

sim_->setAgentPrefVelocity(agent_id_ - 1, RVO::normalize(goal_ - sim_->getAgentPosition(agent_id_ - 1)) * max_v_);
}

} // namespace orca_planner
35 changes: 35 additions & 0 deletions src/core/local_planner/sfm_planner/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
cmake_minimum_required(VERSION 3.0.2)
project(sfm_planner)

find_package(catkin REQUIRED COMPONENTS
angles
costmap_2d
geometry_msgs
nav_core
nav_msgs
navfn
pluginlib
roscpp
tf2_geometry_msgs
tf2_ros
base_local_planner
local_planner
)

catkin_package(
INCLUDE_DIRS include
CATKIN_DEPENDS local_planner
)

include_directories(
include
${catkin_INCLUDE_DIRS}
)

add_library(${PROJECT_NAME}
src/sfm_planner.cpp
)

target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
)
204 changes: 204 additions & 0 deletions src/core/local_planner/sfm_planner/include/lightsfm/angle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/***********************************************************************/
/** */
/** angle.hpp */
/** */
/** Copyright (c) 2016, Service Robotics Lab. */
/** http://robotics.upo.es */
/** */
/** All rights reserved. */
/** */
/** Authors: */
/** Ignacio Perez-Hurtado (maintainer) */
/** Jesus Capitan */
/** Fernando Caballero */
/** Luis Merino */
/** */
/** This software may be modified and distributed under the terms */
/** of the BSD license. See the LICENSE file for details. */
/** */
/** http://www.opensource.org/licenses/BSD-3-Clause */
/** */
/***********************************************************************/

#ifndef _ANGLE_HPP_
#define _ANGLE_HPP_

#include <iostream>
#include <cmath>

namespace utils
{
class Angle
{
public:
enum AngleRange
{
// [0, 2*pi) or [0°, 360°)
PositiveOnlyRange,
// (-pi, +pi] or (-180°, 180°]
PositiveNegativeRange
};

Angle() : value(0)
{
}
virtual ~Angle()
{
}

static Angle fromRadian(double value)
{
return Angle(value);
}

static Angle fromDegree(double value)
{
return Angle(value / 180 * M_PI);
}

double toRadian(AngleRange range = PositiveNegativeRange) const
{
if (range == PositiveNegativeRange)
{
return value;
}
else
{
return (value >= 0) ? value : (value + 2 * M_PI);
}
}

double cos() const
{
return std::cos(value);
}

double sin() const
{
return std::sin(value);
}

double toDegree(AngleRange range = PositiveNegativeRange) const
{
double degreeValue = value * 180 / M_PI;
if (range == PositiveNegativeRange)
{
return degreeValue;
}
else
{
return (degreeValue >= 0) ? degreeValue : (degreeValue + 360);
}
}

void setRadian(double value)
{
Angle::value = value;
normalize();
}

void setDegree(double value)
{
Angle::value = value / 180 * M_PI;
normalize();
}

int sign() const
{
if (value == 0)
{
return 0;
}
else if (value > 0)
{
return 1;
}
else
{
return -1;
}
}

Angle operator+(const Angle &other) const
{
return Angle(value + other.value);
}

Angle operator-(const Angle &other) const
{
return Angle(value - other.value);
}

Angle &operator+=(const Angle &other)
{
value += other.value;
normalize();
return *this;
}

Angle &operator-=(const Angle &other)
{
value -= other.value;
normalize();
return *this;
}

bool operator==(const Angle &other) const
{
return value == other.value;
}

bool operator!=(const Angle &other) const
{
return value != other.value;
}

bool operator<(const Angle &other) const
{
return value < other.value;
}

bool operator<=(const Angle &other) const
{
return value <= other.value;
}

bool operator>(const Angle &other) const
{
return value > other.value;
}

bool operator>=(const Angle &other) const
{
return value >= other.value;
}

private:
Angle(double value)
{
Angle::value = value;
normalize();
}

void normalize()
{
while (value <= -M_PI)
value += 2 * M_PI;
while (value > M_PI)
value -= 2 * M_PI;
}

double value;
};
} // namespace utils

namespace std
{
inline ostream &operator<<(ostream &stream, const utils::Angle &alpha)
{
stream << alpha.toRadian();
return stream;
}
} // namespace std

#endif
Loading

0 comments on commit 91b260d

Please sign in to comment.