Skip to content

Commit

Permalink
refactor(pure_pursuit): make lookahead distance calculation more tuna…
Browse files Browse the repository at this point in the history
  • Loading branch information
brkay54 authored Nov 16, 2022
1 parent 115abf6 commit 2572398
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version='1.0' encoding='UTF-8'?>
<root>
<tabbed_widget parent="main_window" name="Main Window">
<Tab containers="1" tab_name="tab1">
<Container>
<DockSplitter sizes="0.5;0.5" orientation="-" count="2">
<DockArea name="Lookahead Distance">
<plot flip_y="false" mode="TimeSeries" flip_x="false" style="Lines">
<range right="80.040302" top="4.460166" bottom="-0.166817" left="0.000000"/>
<limitY/>
<curve color="#1f77b4" name="/control/trajectory_follower/controller_node_exe/debug/ld_outputs/data.0">
<transform alias="Velocity_LD" name="Scale/Offset">
<options value_scale="1.0" time_offset="0" value_offset="0"/>
</transform>
</curve>
<curve color="#d62728" name="/control/trajectory_follower/controller_node_exe/debug/ld_outputs/data.1">
<transform alias="Curvature_LD" name="Scale/Offset">
<options value_scale="1.0" time_offset="0" value_offset="0"/>
</transform>
</curve>
<curve color="#1ac938" name="/control/trajectory_follower/controller_node_exe/debug/ld_outputs/data.2">
<transform alias="Lateral_Error_LD" name="Scale/Offset">
<options value_scale="1.0" time_offset="0" value_offset="0"/>
</transform>
</curve>
<curve color="#ff7f0e" name="/control/trajectory_follower/controller_node_exe/debug/ld_outputs/data.3">
<transform alias="Total_LD" name="Scale/Offset">
<options value_scale="1.0" time_offset="0" value_offset="0"/>
</transform>
</curve>
</plot>
</DockArea>
<DockSplitter sizes="0.333538;0.332925;0.333538" orientation="|" count="3">
<DockArea name="Velocity">
<plot flip_y="false" mode="TimeSeries" flip_x="false" style="Lines">
<range right="80.040302" top="0.100000" bottom="-0.100000" left="0.000000"/>
<limitY/>
<curve color="#f14cc1" name="/control/trajectory_follower/controller_node_exe/debug/ld_outputs/data.6">
<transform alias="Velocity" name="Scale/Offset">
<options value_scale="1.0" time_offset="0" value_offset="0"/>
</transform>
</curve>
</plot>
</DockArea>
<DockArea name="Lateral Error">
<plot flip_y="false" mode="TimeSeries" flip_x="false" style="Lines">
<range right="80.040302" top="0.537336" bottom="0.537336" left="0.000000"/>
<limitY/>
<curve color="#9467bd" name="/control/trajectory_follower/controller_node_exe/debug/ld_outputs/data.5">
<transform alias="Lateral_Error" name="Scale/Offset">
<options value_scale="1.0" time_offset="0" value_offset="0"/>
</transform>
</curve>
</plot>
</DockArea>
<DockArea name="Curvature">
<plot flip_y="false" mode="TimeSeries" flip_x="false" style="Lines">
<range right="80.040302" top="0.000473" bottom="0.000426" left="0.000000"/>
<limitY/>
<curve color="#17becf" name="/control/trajectory_follower/controller_node_exe/debug/ld_outputs/data.4">
<transform alias="Curvature" name="Scale/Offset">
<options value_scale="1.0" time_offset="0" value_offset="0"/>
</transform>
</curve>
</plot>
</DockArea>
</DockSplitter>
</DockSplitter>
</Container>
</Tab>
<currentTabIndex index="0"/>
</tabbed_widget>
<use_relative_time_offset enabled="1"/>
<!-- - - - - - - - - - - - - - - -->
<!-- - - - - - - - - - - - - - - -->
<Plugins>
<plugin ID="DataLoad CSV">
<default time_axis="" delimiter="0"/>
</plugin>
<plugin ID="DataLoad ROS2 bags">
<use_header_stamp value="false"/>
<discard_large_arrays value="true"/>
<max_array_size value="100"/>
<boolean_strings_to_number value="true"/>
<remove_suffix_from_strings value="true"/>
</plugin>
<plugin ID="DataLoad ULog"/>
<plugin ID="ROS2 Topic Subscriber">
<use_header_stamp value="true"/>
<discard_large_arrays value="true"/>
<max_array_size value="100"/>
<boolean_strings_to_number value="true"/>
<remove_suffix_from_strings value="true"/>
</plugin>
<plugin ID="UDP Server"/>
<plugin ID="WebSocket Server"/>
<plugin ID="ZMQ Subscriber"/>
<plugin ID="Fast Fourier Transform"/>
<plugin ID="Quaternion to RPY"/>
<plugin ID="Reactive Script Editor">
<library code="--[[ Helper function to create a series from arrays&#xa;&#xa; new_series: a series previously created with ScatterXY.new(name)&#xa; prefix: prefix of the timeseries, before the index of the array&#xa; suffix_X: suffix to complete the name of the series containing the X value. If [nil], use the index of the array.&#xa; suffix_Y: suffix to complete the name of the series containing the Y value&#xa; timestamp: usually the tracker_time variable&#xa; &#xa; Example:&#xa; &#xa; Assuming we have multiple series in the form:&#xa; &#xa; /trajectory/node.{X}/position/x&#xa; /trajectory/node.{X}/position/y&#xa; &#xa; where {N} is the index of the array (integer). We can create a reactive series from the array with:&#xa; &#xa; new_series = ScatterXY.new(&quot;my_trajectory&quot;) &#xa; CreateSeriesFromArray( new_series, &quot;/trajectory/node&quot;, &quot;position/x&quot;, &quot;position/y&quot;, tracker_time );&#xa;--]]&#xa;&#xa;function CreateSeriesFromArray( new_series, prefix, suffix_X, suffix_Y, timestamp )&#xa; &#xa; --- clear previous values&#xa; new_series:clear()&#xa; &#xa; --- Append points to new_series&#xa; index = 0&#xa; while(true) do&#xa;&#xa; x = index;&#xa; -- if not nil, get the X coordinate from a series&#xa; if suffix_X ~= nil then &#xa; series_x = TimeseriesView.find( string.format( &quot;%s.%d/%s&quot;, prefix, index, suffix_X) )&#xa; if series_x == nil then break end&#xa; x = series_x:atTime(timestamp)&#x9; &#xa; end&#xa; &#xa; series_y = TimeseriesView.find( string.format( &quot;%s.%d/%s&quot;, prefix, index, suffix_Y) )&#xa; if series_y == nil then break end &#xa; y = series_y:atTime(timestamp)&#xa; &#xa; new_series:push_back(x,y)&#xa; index = index+1&#xa; end&#xa;end&#xa;&#xa;--[[ Similar to the built-in function GetSeriesNames(), but select only the names with a give prefix. --]]&#xa;&#xa;function GetSeriesNamesByPrefix(prefix)&#xa; -- GetSeriesNames(9 is a built-in function&#xa; all_names = GetSeriesNames()&#xa; filtered_names = {}&#xa; for i, name in ipairs(all_names) do&#xa; -- check the prefix&#xa; if name:find(prefix, 1, #prefix) then&#xa; table.insert(filtered_names, name);&#xa; end&#xa; end&#xa; return filtered_names&#xa;end&#xa;&#xa;--[[ Modify an existing series, applying offsets to all their X and Y values&#xa;&#xa; series: an existing timeseries, obtained with TimeseriesView.find(name)&#xa; delta_x: offset to apply to each x value&#xa; delta_y: offset to apply to each y value &#xa; &#xa;--]]&#xa;&#xa;function ApplyOffsetInPlace(series, delta_x, delta_y)&#xa; -- use C++ indeces, not Lua indeces&#xa; for index=0, series:size()-1 do&#xa; x,y = series:at(index)&#xa; series:set(index, x + delta_x, y + delta_y)&#xa; end&#xa;end&#xa;"/>
<scripts/>
</plugin>
<plugin ID="CSV Exporter"/>
<plugin ID="ROS2 Topic Re-Publisher"/>
</Plugins>
<!-- - - - - - - - - - - - - - - -->
<previouslyLoaded_Datafiles/>
<previouslyLoaded_Streamer name="ROS2 Topic Subscriber"/>
<!-- - - - - - - - - - - - - - - -->
<customMathEquations/>
<snippets/>
<!-- - - - - - - - - - - - - - - -->
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "geometry_msgs/msg/pose_stamped.hpp"
#include "geometry_msgs/msg/twist_stamped.hpp"
#include "nav_msgs/msg/odometry.hpp"
#include "tier4_debug_msgs/msg/float32_multi_array_stamped.hpp"

#include <boost/optional.hpp> // To be replaced by std::optional in C++17

Expand Down Expand Up @@ -76,13 +77,18 @@ struct Param
double max_steering_angle; // [rad]

// Algorithm Parameters
double lookahead_distance_ratio;
double ld_velocity_ratio;
double ld_lateral_error_ratio;
double ld_curvature_ratio;
double min_lookahead_distance;
double max_lookahead_distance;
double reverse_min_lookahead_distance; // min_lookahead_distance in reverse gear
double converged_steer_rad_;
double prediction_ds;
double prediction_distance_length; // Total distance of prediction trajectory
double resampling_ds;
double curvature_calculation_distance;
double long_ld_lateral_error_threshold;
};

struct DebugData
Expand All @@ -105,6 +111,9 @@ class PurePursuitLateralController : public LateralControllerBase
autoware_auto_vehicle_msgs::msg::SteeringReport::ConstSharedPtr current_steering_;
boost::optional<AckermannLateralCommand> prev_cmd_;

// Debug Publisher
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr pub_debug_marker_;
rclcpp::Publisher<tier4_debug_msgs::msg::Float32MultiArrayStamped>::SharedPtr pub_debug_values_;
// Predicted Trajectory publish
rclcpp::Publisher<autoware_auto_planning_msgs::msg::Trajectory>::SharedPtr
pub_predicted_trajectory_;
Expand All @@ -122,9 +131,6 @@ class PurePursuitLateralController : public LateralControllerBase
tf2_ros::TransformListener tf_listener_;
geometry_msgs::msg::PoseStamped::ConstSharedPtr current_pose_;

// Debug Publisher
rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr pub_debug_marker_;

void publishDebugMarker() const;

/**
Expand All @@ -148,9 +154,6 @@ class PurePursuitLateralController : public LateralControllerBase
boost::optional<PpOutput> calcTargetCurvature(
bool is_control_output, geometry_msgs::msg::Pose pose);

boost::optional<autoware_auto_planning_msgs::msg::TrajectoryPoint> calcTargetPoint(
geometry_msgs::msg::Pose pose) const;

/**
* @brief It takes current pose, control command, and delta distance. Then it calculates next pose
* of vehicle.
Expand All @@ -165,6 +168,12 @@ class PurePursuitLateralController : public LateralControllerBase

bool calcIsSteerConverged(const AckermannLateralCommand & cmd);

double calcLookaheadDistance(
const double lateral_error, const double curvature, const double velocity, const double min_ld,
const bool is_control_cmd);

double calcCurvature(const size_t closest_idx);

// Debug
mutable DebugData debug_data_;
};
Expand Down
2 changes: 1 addition & 1 deletion control/pure_pursuit/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<buildtool_depend>ament_cmake_auto</buildtool_depend>

<build_depend>autoware_cmake</build_depend>

<depend>autoware_auto_control_msgs</depend>
<depend>autoware_auto_planning_msgs</depend>
<depend>boost</depend>
Expand All @@ -31,6 +30,7 @@
<depend>tf2_geometry_msgs</depend>
<depend>tf2_ros</depend>
<depend>tier4_autoware_utils</depend>
<depend>tier4_debug_msgs</depend>
<depend>trajectory_follower</depend>
<depend>vehicle_info_util</depend>
<depend>visualization_msgs</depend>
Expand Down
Loading

0 comments on commit 2572398

Please sign in to comment.