YawControl.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015-2018, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef YAWCONTROL_H
36 #define YAWCONTROL_H
37 
38 #include <math.h>
39 
40 namespace dbw_mkz_twist_controller {
41 
42 class YawControl {
43 public:
45  YawControl(double wheelbase, double steering_ratio, double steering_wheel_angle_max = INFINITY, double lateral_accel_max = INFINITY) :
46  lateral_accel_max_(fabs(lateral_accel_max)), steering_wheel_angle_max_(steering_wheel_angle_max), steering_ratio_(steering_ratio), wheelbase_(wheelbase) {}
47  void setWheelBase(double val) { wheelbase_ = val; }
48  void setSteeringRatio(double val) { steering_ratio_ = val; }
49  void setLateralAccelMax(double val) { lateral_accel_max_ = fabs(val); }
50  double getSteeringWheelAngle(double cmd_vx, double cmd_wz, double speed) {
51  double steering_wheel_angle;
52  if (fabsf(speed) > 0.5) { // When moving, use measured speed to compute steering angle to improve accuracy
53  steering_wheel_angle = steering_ratio_ * atan(wheelbase_ * cmd_wz / speed);
54  } else { // Use commanded speed to control radius at measured speeds below 0.5 m/s
55  if (fabsf(cmd_vx) > 0.1) {
56  steering_wheel_angle = steering_ratio_ * atan(wheelbase_ * cmd_wz / cmd_vx);
57  } else {
58  // Hits here if both measured speed and commanded speed are small;
59  // set steering to zero to avoid large changes in steering command
60  // due to dividing by small numbers.
61  steering_wheel_angle = 0;
62  }
63  }
64 
65  if (steering_wheel_angle > steering_wheel_angle_max_) {
66  steering_wheel_angle = steering_wheel_angle_max_;
67  } else if (steering_wheel_angle < -steering_wheel_angle_max_) {
68  steering_wheel_angle = -steering_wheel_angle_max_;
69  }
70 
71  return steering_wheel_angle;
72  }
73 private:
77  double wheelbase_;
78 };
79 
80 }
81 
82 #endif // YAWCONTROL_H
83 
double getSteeringWheelAngle(double cmd_vx, double cmd_wz, double speed)
Definition: YawControl.h:50
YawControl(double wheelbase, double steering_ratio, double steering_wheel_angle_max=INFINITY, double lateral_accel_max=INFINITY)
Definition: YawControl.h:45


dbw_mkz_twist_controller
Author(s): Micho Radovnikovich , Kevin Hallenbeck
autogenerated on Thu Nov 14 2019 03:46:10