-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiffDrive.cc
More file actions
60 lines (46 loc) · 1.92 KB
/
diffDrive.cc
File metadata and controls
60 lines (46 loc) · 1.92 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
#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"
namespace gazebo
{
class DiffDriveNavigation : public ModelPlugin
{
public:
std::string chassis = "chassis"; //Vehicle chasis.
diffDriveWP wp;
DDWPFollower ddwpFollower;
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(&DiffDriveNavigation::OnUpdate, this, _1));
//load waypoints
this->wp = loadDiffDriveWaipoint("Maps/waypoint_dd.txt");
//set position to the first point
this->model->SetLinkWorldPose(math::Pose(this->wp.points[0].first, this->wp.points[0].second,height,0,0,0), chassis);
this->ddwpFollower = DDWPFollower(0.001, wp.points, wp.theta_init, wp.vel_max, wp.w_max,
true, {-1,11}, {-1,11});
}
// 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(DiffDriveNavigation)
}