-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiffDrivePP.cc
More file actions
62 lines (48 loc) · 2.11 KB
/
diffDrivePP.cc
File metadata and controls
62 lines (48 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <boost/bind.hpp>
#include <gazebo/gazebo.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/common/common.hh>
#include <stdio.h>
#include "DIFF_DRIVE/DDWPFollower.h"
#include "DIFF_DRIVE/load_dd_waypoint.h"
#include "DIFF_DRIVE/dd_structs.h"
#include "V_graph/V_graph.h"
namespace gazebo
{
class DiffDrivePPNavigation : public ModelPlugin
{
public:
std::string chassis = "chassis"; //Vehicle chasis.
diffDriveWP wp;
V_graph *vis_graph = new V_graph("Maps/polyObst.txt", 0.1);
DDWPFollower ddwpFollower = DDWPFollower(vis_graph);
double height = 0.16;
public: void Load(physics::ModelPtr _parent, sdf::ElementPtr /*_sdf*/)
{
// Store the pointer to the model
this->model = _parent;
// Listen to the update event. This event is broadcast every
// simulation iteration.
this->updateConnection = event::Events::ConnectWorldUpdateBegin(
boost::bind(&DiffDrivePPNavigation::OnUpdate, this, _1));
//set position to the first point
std::pair<double,double> start = this->vis_graph->start;
std::vector<std::pair<double,double> > shortest_path = this->vis_graph->shortest_path();
std::reverse(shortest_path.begin(), shortest_path.end());
this->model->SetLinkWorldPose(math::Pose(start.first, start.second, height,0,0,0), chassis);
this->ddwpFollower = DDWPFollower(0.001, shortest_path, 0, 0.1, 1, vis_graph, true, {-50,50}, {-50,50});
}
// Called by the world update start event
public: void OnUpdate(const common::UpdateInfo & /*_info*/)
{
diffDrivePose pose = ddwpFollower.getNextPose();
this->model->SetLinkWorldPose(math::Pose(pose.x, pose.y, height,0,0,pose.theta), chassis);
}
// Pointer to the model
private: physics::ModelPtr model;
// Pointer to the update event connection
private: event::ConnectionPtr updateConnection;
};
// Register this plugin with the simulator
GZ_REGISTER_MODEL_PLUGIN(DiffDrivePPNavigation)
}