Skip to content

Commit 73112ea

Browse files
authored
Merge pull request #22 from Heenne/fpc-enhancement
Fpc enhancement
2 parents cb9696f + 7cb549c commit 73112ea

29 files changed

+2097
-359
lines changed

fpc_ros/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ include_directories(
131131
## Declare a C++ library
132132
set(FPC_DATA_CLASSES_SOURCES
133133

134-
include/fpc_ros/data_classes/local_planner_robot_info.hpp
135-
include/fpc_ros/data_classes/lyapunov_params.hpp)
134+
include/fpc_ros/data_classes/fpc_param_info.hpp
135+
include/fpc_ros/data_classes/fpc_robot_info.hpp
136+
include/fpc_ros/data_classes/lyapunov_params.hpp
137+
include/fpc_ros/data_classes/controller_params.hpp
138+
139+
include/fpc_ros/data_classes/fpc_param_manager.h
140+
src/data_classes/fpc_param_manager.cpp)
136141
add_library(fpc_data_classes ${FPC_DATA_CLASSES_SOURCES})
137142

138143
set(FPC_ROS_SOURCES
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
namespace fpc_data_classes
4+
{
5+
/**
6+
* @brief Contains all settings of the controller that calculates the movement of the robot
7+
*
8+
*/
9+
struct ControllerParams
10+
{
11+
//! This calue defines the frequency the controller is called
12+
float controller_frequency;
13+
//! Max linear forward velocity of the mobile robot
14+
float max_vel_x;
15+
//! Min linear velocity of the mobile robot (if backwards movement are allowed, this is negative)
16+
float min_vel_x;
17+
//! Max rotational movement of the mobile robot (no differentiation between left and right movement)
18+
float max_vel_theta;
19+
//! Min rotational movement of the mobile robot (no differentiation between left and right movement)
20+
float min_vel_theta;
21+
};
22+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#include "ros/ros.h"
4+
5+
#include <string>
6+
#include <vector>
7+
#include <memory>
8+
9+
#include <fpc_ros/data_classes/fpc_robot_info.hpp>
10+
#include <fpc_ros/data_classes/lyapunov_params.hpp>
11+
12+
namespace fpc_data_classes
13+
{
14+
struct FPCParamInfo
15+
{
16+
//! Parameter is defining the tolerance when arriving at the goal in the x and y direction
17+
double xy_default_tolerance;
18+
//! Parameter is defining the tolerance when arriving at the goal for the orientation.
19+
double yaw_default_tolerance;
20+
21+
//! Prune the plan so every position of the original plan that was passed 1m ago will be deleted
22+
bool prune_plan;
23+
//! Params for the controller
24+
fpc_data_classes::ControllerParams controller_params;
25+
26+
//! Param info for all robots included in the formation
27+
std::vector<std::shared_ptr<fpc_data_classes::FPCRobotInfo>> robot_info_list;
28+
//! Param info for the current robot
29+
std::shared_ptr<fpc_data_classes::FPCRobotInfo> current_robot_info;
30+
//! Param info for the master robot
31+
std::shared_ptr<fpc_data_classes::FPCRobotInfo> master_robot_info;
32+
33+
std::string getCurrentRobotName() { return this->current_robot_info->robot_name; }
34+
std::string getCurrentRobotNamespace() { return this->current_robot_info->robot_namespace; }
35+
std::string getCurrentRobotPoseTopic() { return this->current_robot_info->robot_pose_topic; }
36+
std::string getCurrentRobotGroundTruthTopic() { return this->current_robot_info->robot_ground_truth_topic; }
37+
std::string getCurrentRobotOdomTopic() { return this->current_robot_info->robot_odom_topic; }
38+
std::string getCurrentRobotCmdVelTopic() { return this->current_robot_info->robot_cmd_vel_topic; }
39+
LyapunovParams getLyapunovParams() { return this->current_robot_info->lyapunov_params; }
40+
};
41+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#pragma once
2+
3+
#include "ros/ros.h"
4+
5+
#include <string>
6+
#include <memory>
7+
#include <fpc_ros/data_classes/fpc_param_info.hpp>
8+
9+
namespace fpc_data_classes
10+
{
11+
class FPCParamManager
12+
{
13+
public:
14+
FPCParamManager(ros::NodeHandle &nh, ros::NodeHandle &controller_nh);
15+
16+
void getParams();
17+
18+
std::shared_ptr<FPCParamInfo> getLocalPlannerInfo();
19+
20+
private:
21+
ros::NodeHandle &nh_;
22+
ros::NodeHandle &controller_nh_;
23+
24+
std::shared_ptr<FPCParamInfo> fpc_param_info_;
25+
26+
double getNumberFromXMLRPC(XmlRpc::XmlRpcValue value, const std::string full_param_name);
27+
};
28+
}

fpc_ros/include/fpc_ros/data_classes/local_planner_robot_info.hpp renamed to fpc_ros/include/fpc_ros/data_classes/fpc_robot_info.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <string>
44
#include <fpc_ros/data_classes/lyapunov_params.hpp>
5+
#include <fpc_ros/data_classes/controller_params.hpp>
56

67
namespace fpc_data_classes
78
{
@@ -10,7 +11,7 @@ namespace fpc_data_classes
1011
* Data is read from the local_planner_config.yaml and loaded by move_base_flex
1112
*
1213
*/
13-
struct LocalPlannerRobotInfo
14+
struct FPCRobotInfo
1415
{
1516
//! Name of the robot
1617
std::string robot_name;
@@ -20,8 +21,12 @@ namespace fpc_data_classes
2021
bool fpc_master;
2122
//! Topic name where the pose of the robot can be received
2223
std::string robot_pose_topic;
24+
//! Topic name where the ground truth pose of the robot will be published from Gazebo
25+
std::string robot_ground_truth_topic;
2326
//! Topic name where the odometry of the robot can be received
2427
std::string robot_odom_topic;
28+
//! Topic name where the velocity of the robot can be published to
29+
std::string robot_cmd_vel_topic;
2530
//! Params for the lyapunov controller
2631
fpc_data_classes::LyapunovParams lyapunov_params;
2732
};

fpc_ros/include/fpc_ros/fpc_controller_base.h

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <geometry_msgs/Pose.h>
77
#include <geometry_msgs/PoseStamped.h>
88
#include <geometry_msgs/PoseWithCovarianceStamped.h>
9+
#include <geometry_msgs/Twist.h>
910
#include <nav_msgs/Odometry.h>
1011
#include <tf2_ros/buffer.h>
1112
#include <tf/transform_listener.h>
@@ -15,7 +16,7 @@
1516
#include <vector>
1617
#include <eigen3/Eigen/Dense>
1718

18-
#include <fpc_ros/data_classes/local_planner_robot_info.hpp>
19+
#include <fpc_ros/data_classes/fpc_param_info.hpp>
1920
#include <fpp_msgs/LocalPlannerMetaData.h>
2021

2122
namespace fpc
@@ -25,8 +26,7 @@ namespace fpc
2526
public:
2627
#pragma region Constructors
2728
FPCControllerBase(
28-
std::vector<std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo>> &robot_info_list,
29-
std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> &robot_info,
29+
std::shared_ptr<fpc_data_classes::FPCParamInfo> fpc_param_info,
3030
ros::NodeHandle &nh,
3131
ros::NodeHandle &controller_nh);
3232
#pragma endregion
@@ -46,7 +46,7 @@ namespace fpc
4646
geometry_msgs::TwistStamped &cmd_vel,
4747
std::string &message);
4848

49-
virtual void publishMetaData();
49+
virtual void publishMetaData(geometry_msgs::Pose2D target_pose);
5050
#pragma endregion
5151

5252
#pragma region Getter/Setter
@@ -76,41 +76,54 @@ namespace fpc
7676
std::string robot_ns_;
7777

7878
#pragma region ProcessInfo
79-
//! This is all the information that was read from the config file about each robot
80-
std::vector<std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo>> &robot_info_list_;
81-
//! This points to the object that contains the information about this robot
82-
std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> &robot_info_;
83-
//! This point to the object that represents the master in the formation path planner
84-
const std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> master_robot_info_;
79+
std::shared_ptr<fpc_data_classes::FPCParamInfo> fpc_param_info_;
80+
// //! This is all the information that was read from the config file about each robot
81+
// std::vector<std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo>> &robot_info_list_;
82+
// //! This points to the object that contains the information about this robot
83+
// std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> &robot_info_;
84+
// //! This point to the object that represents the master in the formation path planner
85+
// const std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> master_robot_info_;
86+
87+
geometry_msgs::Twist last_published_cmd_vel_;
8588

8689
std::vector<geometry_msgs::PoseStamped> global_plan_;
8790

88-
int pose_index_;
91+
float velocity_factor_;
8992
bool controller_finished_;
9093

9194
geometry_msgs::PoseStamped last_target_pose_;
9295
#pragma endregion
9396

94-
95-
96-
#pragma region Topics/Services/Actions
97+
#pragma region Topics/Services/Actions/Timers
9798
ros::Subscriber robot_amcl_pose_subscriber_;
9899
geometry_msgs::Pose current_robot_amcl_pose_;
99100
ros::Subscriber robot_odom_subscriber_;
100101
nav_msgs::OdometryConstPtr current_robot_odom_;
101102
ros::Subscriber robot_ground_truth_subscriber_; // This subscriber will only work in Gazebo where ground truth is published
102103
nav_msgs::OdometryConstPtr current_robot_ground_truth_;
103104

105+
ros::Publisher cmd_vel_publisher_;
104106
ros::Publisher meta_data_publisher_;
105107
fpp_msgs::LocalPlannerMetaData meta_data_msg_; // This is the msg that will be published. Every info can be stored here and will be reset when message is published.
108+
109+
ros::Timer controller_timer_;
106110
#pragma endregion
107111

108-
#pragma CallbackMethods
112+
#pragma region CallbackMethods
109113
void getRobotPoseCb(const geometry_msgs::PoseWithCovarianceStampedConstPtr &msg);
110114
void getRobotOdomCb(const nav_msgs::OdometryConstPtr &msg);
111115

112116
void getRobotGroundTruthCb(const nav_msgs::OdometryConstPtr &msg);
113117

118+
void onControllerTimerCB(const ros::TimerEvent& timer_event_info);
119+
#pragma endregion
120+
121+
#pragma region Controller Methods
122+
virtual void runController();
123+
float calcLinVelocity(geometry_msgs::Pose2D diff_vector, float scale_factor);
124+
float calcRotVelocity(geometry_msgs::Pose2D diff_vector);
125+
126+
int locateRobotOnPath(geometry_msgs::Pose current_pose);
114127
#pragma endregion
115128

116129
#pragma region ProtectedHelperMethods
@@ -130,12 +143,27 @@ namespace fpc
130143
*/
131144
virtual void initTimers();
132145

133-
std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> getMasterRobotInfo(
134-
const std::vector<std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo>> &robot_info_list);
135-
136146
geometry_msgs::Pose2D convertPose(geometry_msgs::Pose pose_to_convert);
147+
Eigen::Vector3f convertPose(geometry_msgs::Pose2D pose_to_convert);
148+
geometry_msgs::Pose2D calcDiff(geometry_msgs::Pose start_pose, geometry_msgs::Pose end_pose);
137149
geometry_msgs::Pose2D calcDiff(geometry_msgs::Pose2D start_pose, geometry_msgs::Pose2D end_pose);
138150
geometry_msgs::Twist calcDiff(geometry_msgs::Twist start_vel, geometry_msgs::Twist end_vel);
139-
#pragma endregion
151+
float calcEuclideanDiff(geometry_msgs::Pose point1, geometry_msgs::Pose point2);
152+
float calcEuclideanDistance(geometry_msgs::Pose2D vector);
153+
154+
float calcVelocityFactor(geometry_msgs::Pose2D pose_diff, float largest_euclidean_diff);
155+
156+
/**
157+
* @brief Create a transformation matrix to transform points from and to the geometry cs of this object
158+
*
159+
* @param lead_vector_world_cs translation from the world to this cs
160+
* @param rotation Rotation form the world to this cs. Rotation only uses yaw rotation.
161+
* @return Eigen::Matrix<float, 4, 4> Transformation matrix in the x/y area and yaw rotation.
162+
*/
163+
Eigen::Matrix<float, 4, 4> createTransformationMatrix(Eigen::Vector2f lead_vector_world_cs, float rotation);
164+
Eigen::Vector2f transformVector(Eigen::Vector2f vector_to_transform,
165+
Eigen::Vector2f lead_vector,
166+
float rotation);
167+
#pragma endregion
140168
};
141169
}

fpc_ros/include/fpc_ros/fpc_controller_master.h

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,50 @@
44

55
#include <memory>
66
#include <vector>
7+
#include <map>
78

89
#include <fpc_ros/fpc_controller_base.h>
9-
#include <fpc_ros/data_classes/local_planner_robot_info.hpp>
10+
#include <fpp_msgs/NextTargetPoseCommand.h>
1011

1112
namespace fpc
1213
{
1314
class FPCControllerMaster : public fpc::FPCControllerBase
1415
{
1516
public:
1617
FPCControllerMaster(
17-
std::vector<std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo>> &robot_info_list,
18-
std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> &robot_info,
18+
std::shared_ptr<fpc_data_classes::FPCParamInfo> fpc_param_info,
1919
ros::NodeHandle &nh,
2020
ros::NodeHandle &controller_nh);
2121

22+
bool setPlan(const std::vector<geometry_msgs::PoseStamped> &plan) override;
23+
2224
private:
25+
int pose_index_;
26+
27+
std::map<std::string, std::shared_ptr<ros::ServiceClient>> next_target_command_clt_list_;
28+
std::map<std::string, fpp_msgs::NextTargetPoseCommand::Response> saved_command_res_list_;
29+
30+
31+
32+
void runController() override;
33+
34+
/**
35+
* @brief Helper method for intializing all services
36+
*
37+
*/
38+
void initServices() override;
39+
40+
41+
#pragma region Callback Methods
42+
#pragma endregion
43+
44+
#pragma region Helper Methods
45+
bool allSlavesReady();
46+
bool isSlaveReady(std::string robot_name);
47+
float getLargestDiff();
48+
// int getHighestPoseIndex();
49+
// int getLowestPoseIndex();
50+
// fpp_msgs::FPCRobotScaleInfo getHighestLinScaleValue(int next_target_pose);
51+
#pragma endregion
2352
};
2453
}

fpc_ros/include/fpc_ros/fpc_controller_slave.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,36 @@
33
#include "ros/ros.h"
44

55
#include <fpc_ros/fpc_controller_base.h>
6+
#include <fpp_msgs/NextTargetPoseCommand.h>
67

78
namespace fpc
89
{
910
class FPCControllerSlave : public fpc::FPCControllerBase
1011
{
1112
public:
1213
FPCControllerSlave(
13-
std::vector<std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo>> &robot_info_list,
14-
std::shared_ptr<fpc_data_classes::LocalPlannerRobotInfo> &robot_info,
14+
std::shared_ptr<fpc_data_classes::FPCParamInfo> fpc_param_info,
1515
ros::NodeHandle &nh,
1616
ros::NodeHandle &controller_nh);
1717

1818
private:
19+
ros::ServiceServer next_target_command_srv_;
20+
fpp_msgs::NextTargetPoseCommand::Request saved_target_cmd_req_;
21+
22+
geometry_msgs::Pose2D diff_vector_;
23+
24+
/**
25+
* @brief Helper method for intializing all services
26+
*
27+
*/
28+
void initServices() override;
29+
30+
void runController() override;
31+
32+
#pragma region Callback Methods
33+
bool onNextTargetCommand(fpp_msgs::NextTargetPoseCommand::Request &req,
34+
fpp_msgs::NextTargetPoseCommand::Response &res);
35+
36+
#pragma endregion
1937
};
2038
}

0 commit comments

Comments
 (0)