Skip to content

Commit e8b5780

Browse files
committed
Fixed the problem with the controller
Orientations of robots in the plan was wrong
1 parent 684d79f commit e8b5780

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

fpp_ros/src/fpp_controller_master.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,44 @@ namespace fpp
290290
Eigen::Vector2f pose = path_planner_formation.getRobotPosWorldCS(robot_info_it->robot_name);
291291
new_pose.pose.position.x = pose[0];
292292
new_pose.pose.position.y = pose[1];
293-
new_pose.pose.orientation = formation_pose_in_plan.pose.orientation;
293+
new_pose.pose.position.z = 0.0;
294+
295+
// new_pose.pose.orientation = formation_pose_in_plan.pose.orientation;
294296

295297
this->robot_plan_list_[robot_info_it->robot_name].push_back(new_pose);
296298
}
297299
}
298300

299-
301+
//Calc orientation for each point of the robot plans
302+
for(const std::shared_ptr<fpp_data_classes::RobotInfo> &robot_info_it: this->robot_info_list_)
303+
{
304+
// for(geometry_msgs::PoseStamped formation_pose_in_plan_: this->robot_plan_list_[robot_info_it->robot_name])
305+
// {
306+
307+
// }
308+
309+
// < is necessary because we just copy elements from one vector (0 until size()) to the other
310+
for(uint path_counter = 0; path_counter < this->robot_plan_list_[robot_info_it->robot_name].size(); path_counter++)
311+
{
312+
// Calculate orientation for each point of the plan with the current position and the last one
313+
if(path_counter == 0) // No previous point so orientation of start will be taken
314+
{
315+
this->robot_plan_list_[robot_info_it->robot_name][path_counter].pose.orientation = formation_plan[0].pose.orientation;
316+
}
317+
else // Some other points are before, so orientation can be calculated
318+
{
319+
float delta_x = this->robot_plan_list_[robot_info_it->robot_name][path_counter].pose.position.x -
320+
this->robot_plan_list_[robot_info_it->robot_name][path_counter - 1].pose.position.x;
321+
float delta_y = this->robot_plan_list_[robot_info_it->robot_name][path_counter].pose.position.y -
322+
this->robot_plan_list_[robot_info_it->robot_name][path_counter - 1].pose.position.y;
323+
double yaw_angle = std::atan2(delta_y, delta_x);
324+
this->robot_plan_list_[robot_info_it->robot_name][path_counter].pose.orientation = tf::createQuaternionMsgFromYaw(yaw_angle);
325+
}
326+
327+
// last_pose = pose; // Safe pose for next iteration
328+
// plan.insert(plan.begin() + plan.size(), pose);
329+
}
330+
}
300331
}
301332

302333
void FPPControllerMaster::updateFootprint()

0 commit comments

Comments
 (0)