3 #include <tuw_nav_msgs/ControllerState.h> 6 #define NSEC_2_SECS(A) ((float)A / 1000000000.0) 8 int main(
int argc,
char **argv)
10 std::string name(
"pid_controller");
27 action_server(n,
"execute_path", [&](
const auto& goal) {this->onGoalReceived(goal);},
false)
29 twist_publisher = n.
advertise<geometry_msgs::Twist>(
"cmd_vel", 1000);
30 state_publisher = n.
advertise<tuw_nav_msgs::ControllerState>(
"state_trajectory_ctrl", 10);
33 action_server.start();
38 pt.
x = pose->pose.pose.position.x;
39 pt.
y = pose->pose.pose.position.y;
41 tf::Quaternion q(pose->pose.pose.orientation.x, pose->pose.pose.orientation.y, pose->pose.pose.orientation.z,
42 pose->pose.pose.orientation.w);
44 double roll, pitch, yaw;
45 m.
getRPY(roll, pitch, yaw);
59 command.angular.z = w;
64 tuw_nav_msgs::ControllerState controller_state;
65 controller_state.progress_in_relation_to = path.header.seq;
66 controller_state.header.frame_id = path.header.frame_id;
70 controller_state.state = controller_state.STATE_DRIVING;
72 controller_state.state = controller_state.STATE_IDLE;
78 std::string
s = command.data;
80 ROS_INFO(
"Multi Robot Controller: received %s", s.c_str());
81 if (s.compare(
"run") == 0) {
83 }
else if (s.compare(
"stop") == 0) {
85 }
else if (s.compare(
"step") == 0) {
94 const auto& path = goal->path;
95 if (path.poses.empty()) {
112 tuw_local_controller_msgs::ExecutePathResult result;
113 geometry_msgs::Pose pose;
120 while (progress < goal->path.poses.size()) {
128 tuw_local_controller_msgs::ExecutePathFeedback feedback;
129 feedback.current_step = progress;
143 auto it = path.poses.begin();
144 std::vector<PathPoint> path_points;
145 for (; it != path.poses.end(); ++it)
149 tf::Quaternion q(it->pose.orientation.x, it->pose.orientation.y, it->pose.orientation.z, it->pose.orientation.w);
151 double roll, pitch, yaw;
152 m.
getRPY(roll, pitch, yaw);
154 pt.
x = it->pose.position.x;
155 pt.
y = it->pose.position.y;
158 path_points.push_back(pt);
164 setPath(std::make_shared<std::vector<PathPoint>>(path_points));
ros::Publisher twist_publisher
void publishFeedback(const FeedbackConstPtr &feedback)
ros::NodeHandle n_param_
Node handler to the current node.
void setPath(std::shared_ptr< std::vector< PathPoint >> _path)
Set the path the contorler has to follow.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void onCommandReceived(const std_msgs::String command)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
actionlib::SimpleActionServer< tuw_local_controller_msgs::ExecutePathAction > action_server
size_t getProgress()
return progress,
void setState(state s)
Set the State (run stop step wait_step)
void onGoalReceived(const tuw_local_controller_msgs::ExecutePathGoalConstPtr &goal)
void setSucceeded(const Result &result=Result(), const std::string &text=std::string(""))
void setPID(float _Kp, float _Ki, float _Kd)
sets the control parameters
void getSpeed(float *_v, float *_w)
Returns the current speed values.
void setupController(const nav_msgs::Path &path, const ControllerConfig &config)
void publish(const boost::shared_ptr< M > &message) const
void setPreempted(const Result &result=Result(), const std::string &text=std::string(""))
ROSLIB_DECL std::string command(const std::string &cmd)
bool getParam(const std::string &key, std::string &s) const
void setSpeedParams(float _max_v, float _max_w)
Set the Speed Params of the controller.
void publishControllerState(const nav_msgs::Path &path)
bool isPreemptRequested()
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
ControllerNode(ros::NodeHandle &n)
Construct a new Controller Node object.
int main(int argc, char **argv)
void setGoalRadius(float _r)
Set the Goal Radius.
void update(PathPoint _odom, float _delta_t)
updates the controller with the current robot position
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
void onPoseReceived(const geometry_msgs::PoseWithCovarianceStampedConstPtr &pose)
bool isActive()
return progress, passed waypoints on the given path
ros::Publisher state_publisher