Autonomous Racing  1
f1tenth Project Group of Technical University Dortmund, Germany
wall_following.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <cmath>
5 #include <cstdlib>
6 #include <iostream>
7 
8 #include "drive_msgs/drive_param.h"
9 #include "pid_controller.h"
11 #include "sensor_msgs/LaserScan.h"
12 #include "std_msgs/Bool.h"
13 #include "std_msgs/Float64.h"
14 #include "wall.h"
15 #include <ros/console.h>
16 #include <ros/ros.h>
17 
18 #include <dynamic_reconfigure/server.h>
19 #include <wallfollowing1/wallfollowing1Config.h>
20 
21 constexpr const char* TOPIC_DRIVE_PARAMETERS = "/input/drive_param/autonomous";
22 constexpr const char* TOPIC_LASER_SCAN = "/scan";
23 constexpr const char* TOPIC_EMERGENCY_STOP = "/emergency_stop";
24 constexpr const char* TOPIC_VISUALIZATION = "/wallfollowing_visualization";
25 
26 constexpr const char* LIDAR_FRAME = "laser";
27 
28 constexpr float DEG_TO_RAD = M_PI / 180.0;
29 
31 {
32  public:
33  WallFollowing();
34 
35  private:
36  // Discard lidar measurements outside this range
37  float m_min_range = 0.2;
38  float m_max_range = 30;
39 
40  float m_fallback_range = 4;
41 
42  float m_sample_angle_1 = 30 * DEG_TO_RAD;
43  float m_sample_angle_2 = 70 * DEG_TO_RAD;
44 
45  float m_wall_following_max_speed = 0.25;
46  float m_wall_following_min_speed = 0.2;
47 
48  // The car will aim to reach the target wall distance after travelling this distance.
49  // The higher this number, the more aggressively the car will cut corners.
50  float m_prediction_distance = 2;
51  // The desired distance between the wall and the car
52  float m_target_wall_distance = 0.5;
53 
54  float m_time_between_scans = 0.025;
55 
56  ros::NodeHandle m_node_handle;
57 
58  dynamic_reconfigure::Server<wallfollowing1::wallfollowing1Config> m_dyn_cfg_server;
59 
60  ros::Subscriber m_lidar_subscriber;
61  ros::Publisher m_drive_parameter_publisher;
62  RvizGeometryPublisher m_debug_geometry;
63 
64  PIDController m_pid_controller = PIDController(5, 0.01, 0.2);
65 
66  void followSingleWall(const sensor_msgs::LaserScan::ConstPtr& lidar, bool right_wall);
67  void followWalls(const sensor_msgs::LaserScan::ConstPtr& lidar);
68  Wall getWall(const sensor_msgs::LaserScan::ConstPtr& lidar, bool right_wall);
69 
70  void lidarCallback(const sensor_msgs::LaserScan::ConstPtr& lidar);
71  void publishDriveParameters(float velocity, float angle);
72 
73  void updateDynamicConfig();
74 
80  float getRangeAtDegree(const sensor_msgs::LaserScan::ConstPtr& lidar, float angle);
81 };
constexpr float DEG_TO_RAD
constexpr const char * TOPIC_VISUALIZATION
constexpr const char * TOPIC_DRIVE_PARAMETERS
Definition: wall.h:7
constexpr const char * TOPIC_EMERGENCY_STOP
constexpr const char * LIDAR_FRAME
constexpr const char * TOPIC_LASER_SCAN