WheelTrackedVehiclePlugin.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef GAZEBO_WHEELTRACKEDVEHICLEPLUGIN_HH
19 #define GAZEBO_WHEELTRACKEDVEHICLEPLUGIN_HH
20 
21 
22 #include <memory>
23 #include <string>
24 #include <unordered_map>
25 #include <vector>
26 
27 #include "gazebo/physics/Joint.hh"
28 
30 
31 namespace gazebo
32 {
51  {
52  public: WheelTrackedVehiclePlugin() = default;
53 
54  public: virtual ~WheelTrackedVehiclePlugin() = default;
55 
59  public: void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf) override;
60 
62  public: void Init() override;
63 
65  public: void Reset() override;
66 
71  protected: void SetTrackVelocityImpl(double _left, double _right) override;
72 
75  protected: void UpdateTrackSurface() override;
76 
83  protected: void LoadWheel(physics::ModelPtr &_model, Tracks &_track,
84  const std::string &_jointName);
85 
88  protected: struct WheelInfo
89  {
92 
94  std::string jointName;
95 
97  // cppcheck-suppress unusedStructMember
98  double radius;
99  };
100 
101  typedef std::shared_ptr<WheelInfo> WheelInfoPtr;
102  typedef std::vector<WheelInfoPtr> WheelInfo_V;
103 
105  protected: std::unordered_map<Tracks, WheelInfo_V> wheels;
106 
108  protected: std::unordered_map<Tracks, double> trackVelocity;
109 
111  protected: double defaultWheelRadius;
112 
115 
117  protected: std::mutex mutex;
118 
119  private: event::ConnectionPtr updateConnection;
120 
121  private: void OnUpdate();
122  };
123 }
124 
125 #endif
std::unordered_map< Tracks, WheelInfo_V > wheels
The wheels on the LEFT/RIGHT track.
Definition: WheelTrackedVehiclePlugin.hh:105
boost::shared_ptr< World > WorldPtr
Definition: PhysicsTypes.hh:90
void Init() override
Initialize the plugin.
double radius
Radius of the wheel (used to convert linear to angular speed).
Definition: WheelTrackedVehiclePlugin.hh:98
Forward declarations for the common classes.
Definition: Animation.hh:26
std::mutex mutex
Mutex to protect updates.
Definition: WheelTrackedVehiclePlugin.hh:117
virtual ~WheelTrackedVehiclePlugin()=default
std::string jointName
Name of the hinge joint.
Definition: WheelTrackedVehiclePlugin.hh:94
Holds information about each wheel.
Definition: WheelTrackedVehiclePlugin.hh:88
boost::shared_ptr< Joint > JointPtr
Definition: PhysicsTypes.hh:118
std::shared_ptr< WheelInfo > WheelInfoPtr
Definition: WheelTrackedVehiclePlugin.hh:101
void UpdateTrackSurface() override
Update surface parameters of the tracks to correspond to the values set in this plugin.
std::vector< WheelInfoPtr > WheelInfo_V
Definition: WheelTrackedVehiclePlugin.hh:102
void Reset() override
Reset the plugin.
void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf) override
Called when the plugin is loaded.
An approximate model of non-deformable tracks emulated by wheels.
Definition: WheelTrackedVehiclePlugin.hh:49
std::unordered_map< Tracks, double > trackVelocity
Desired velocities of the tracks.
Definition: WheelTrackedVehiclePlugin.hh:108
boost::shared_ptr< Connection > ConnectionPtr
Definition: CommonTypes.hh:134
double defaultWheelRadius
The radius (in meters) used for wheels where autodetection fails.
Definition: WheelTrackedVehiclePlugin.hh:111
boost::shared_ptr< Model > ModelPtr
Definition: PhysicsTypes.hh:94
An abstract gazebo model plugin for tracked vehicles.
Definition: TrackedVehiclePlugin.hh:79
Tracks
Enum for distinguishing between left and right tracks.
Definition: TrackedVehiclePlugin.hh:40
physics::JointPtr joint
The hinge joint connecting the wheel to the track/body.
Definition: WheelTrackedVehiclePlugin.hh:91
physics::WorldPtr world
Pointer to the world the model lives in.
Definition: WheelTrackedVehiclePlugin.hh:114
void LoadWheel(physics::ModelPtr &_model, Tracks &_track, const std::string &_jointName)
Load a wheel connected to joint named jointName and append it to this->wheels[track].
void SetTrackVelocityImpl(double _left, double _right) override
Set new target velocity for the tracks.