Flatland
tricycle_drive.h
1 /*
2  * ______ __ __ __
3  * /\ _ \ __ /\ \/\ \ /\ \__
4  * \ \ \L\ \ __ __ /\_\ \_\ \ \ \____ ___\ \ ,_\ ____
5  * \ \ __ \/\ \/\ \\/\ \ /'_` \ \ '__`\ / __`\ \ \/ /',__\
6  * \ \ \/\ \ \ \_/ |\ \ \/\ \L\ \ \ \L\ \/\ \L\ \ \ \_/\__, `\
7  * \ \_\ \_\ \___/ \ \_\ \___,_\ \_,__/\ \____/\ \__\/\____/
8  * \/_/\/_/\/__/ \/_/\/__,_ /\/___/ \/___/ \/__/\/___/
9  * @copyright Copyright 2017 Avidbots Corp.
10  * @name tricycle.h
11  * @brief Tricycle plugin
12  * @author Mike Brousseau
13  *
14  * Software License Agreement (BSD License)
15  *
16  * Copyright (c) 2017, Avidbots Corp.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions
21  * are met:
22  *
23  * * Redistributions of source code must retain the above copyright
24  * notice, this list of conditions and the following disclaimer.
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  * * Neither the name of the Avidbots Corp. nor the names of its
30  * contributors may be used to endorse or promote products derived
31  * from this software without specific prior written permission.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
36  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
38  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
39  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
40  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  */
46 
47 #include <Box2D/Box2D.h>
48 #include <flatland_plugins/update_timer.h>
49 #include <flatland_server/model_plugin.h>
50 #include <flatland_server/timekeeper.h>
51 #include <geometry_msgs/Twist.h>
52 #include <nav_msgs/Odometry.h>
53 
54 #ifndef FLATLAND_PLUGINS_TRICYCLE_DRIVE_H
55 #define FLATLAND_PLUGINS_TRICYCLE_DRIVE_H
56 
57 using namespace flatland_server;
58 using namespace std;
59 
60 namespace flatland_plugins {
61 
63  public:
64  Body* body_;
68  double axel_track_;
69  double wheelbase_;
70  b2Vec2 rear_center_;
74  double theta_f_;
75 
76  geometry_msgs::Twist twist_msg_;
77  nav_msgs::Odometry odom_msg_;
78  nav_msgs::Odometry ground_truth_msg_;
79  ros::Subscriber twist_sub_;
80  ros::Publisher odom_pub_;
81  ros::Publisher ground_truth_pub_;
82 
83  UpdateTimer update_timer_;
84 
85  default_random_engine rng_;
86  array<normal_distribution<double>, 6> noise_gen_;
87 
93  void OnInitialize(const YAML::Node& config) override;
94 
99  void ComputeJoints();
100 
106  void BeforePhysicsStep(const Timekeeper& timekeeper) override;
107 
113  void TwistCallback(const geometry_msgs::Twist& msg);
114 };
115 }
116 
117 #endif
bool invert_steering_angle_
whether to invert steering angle
Definition: tricycle_drive.h:71
Joint * rear_right_wj_
rear right wheel joint
Definition: tricycle_drive.h:67
double axel_track_
normal distrance between the rear two wheels
Definition: tricycle_drive.h:68
Definition: dummy_model_plugin.h:59
STL namespace.
double wheelbase_
distance between the front and rear wheel
Definition: tricycle_drive.h:69
Joint * front_wj_
front wheel joint
Definition: tricycle_drive.h:65
Definition: body.h:55
Definition: joint.h:63
Definition: tricycle_drive.h:62
b2Vec2 rear_center_
middle point between the two rear wheels
Definition: tricycle_drive.h:70
Definition: timekeeper.h:55
Definition: model_plugin.h:64
Definition: body.h:61
double max_angular_velocity_
The max angular velocity.
Definition: tricycle_drive.h:72
double theta_f_
The current angular offset of the front wheel.
Definition: tricycle_drive.h:74
Joint * rear_left_wj_
rear left wheel joint
Definition: tricycle_drive.h:66
Definition: update_timer.h:55
double target_wheel_angle_
The current target wheel angle.
Definition: tricycle_drive.h:73