Skip to content

Commit

Permalink
#7 Find basic parameter value for purepursuit and stanley
Browse files Browse the repository at this point in the history
  • Loading branch information
dongdongO committed Apr 13, 2024
1 parent d7189df commit 70198d5
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions algorithm/src/controller/stanley.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Stanley::Stanley(std::vector<std::vector<double>> route, double resolution, double speed, std::vector<double> cpoint,
double k, double ks) {
// Vehicle Config
this->WB = this->car.WB/resolution;

// Vehicle Status
this->x = cpoint[0];
this->y = cpoint[1];
Expand All @@ -19,9 +22,6 @@ Stanley::Stanley(std::vector<std::vector<double>> route, double resolution, doub
// this->ki = this->car.ki;
// this->kd = this->car.kd;

// Vehicle Config
this->WB = this->car.WB/resolution;

// System Config
this->dt = 0.1;

Expand Down
36 changes: 18 additions & 18 deletions algorithm/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "map/hybrid_astar_map.hpp"
#include "hybrid-a-star/a_star.hpp"

#include "controller/pure_pursuit.hpp"
// #include "controller/pure_pursuit.hpp"
#include "controller/stanley.hpp"

#include "utils/matplotlibcpp.h"
Expand Down Expand Up @@ -60,8 +60,8 @@ int main() {
// std::vector<std::vector<double>> control_path = purepursuit.getTrajectory();
// std::vector<int> target_nodes = purepursuit.getTargetnode();

double k = 0.2;
double ks = 1.0;
double k = 10.0;
double ks = 20.0;

auto stanley = Stanley(route, resolution, speed, cpoint, k, ks);
stanley.stanley_control();
Expand Down Expand Up @@ -115,21 +115,21 @@ int main() {
// Show path
plt::plot(path_x, path_y, "r-");

// Show Control
if(i < control_path.size()) {
std::vector<int> path_x = {static_cast<int>(control_path[i][0])};
std::vector<int> path_y = {static_cast<int>(control_path[i][1])};
plt::plot(path_x, path_y, "bo");
}

if(i < target_nodes.size()) {
int target_node_index = target_nodes[i];
if(target_node_index < route.size()) {
std::vector<int> target_x = {static_cast<int>(route[target_node_index][0])};
std::vector<int> target_y = {static_cast<int>(route[target_node_index][1])};
plt::plot(target_x, target_y, "go");
}
}
// // Show Control
// if(i < control_path.size()) {
// std::vector<int> path_x = {static_cast<int>(control_path[i][0])};
// std::vector<int> path_y = {static_cast<int>(control_path[i][1])};
// plt::plot(path_x, path_y, "bo");
// }

// if(i < target_nodes.size()) {
// int target_node_index = target_nodes[i];
// if(target_node_index < route.size()) {
// std::vector<int> target_x = {static_cast<int>(route[target_node_index][0])};
// std::vector<int> target_y = {static_cast<int>(route[target_node_index][1])};
// plt::plot(target_x, target_y, "go");
// }
// }

plt::pause(0.01);
}
Expand Down
4 changes: 2 additions & 2 deletions control_ws/src/pure_pursuit/src/control.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "control.hpp"

Control::Control() : rclcpp::Node("vehicle_control") {
this->controller = PurePursuit(2.7, 0.5, 4.0);
this->controller = PurePursuit(2.7, 1.0, 10.0);

// Subscribe
path_subscription_ = this->create_subscription<nav_msgs::msg::Path>(
Expand Down Expand Up @@ -74,7 +74,7 @@ void Control::publisher_timer_callback() {

void Control::publish_drive(float speed, float steer) {
auto drive_msg = std::make_unique<geometry_msgs::msg::Twist>();
drive_msg->linear.x = speed * 0.8;
drive_msg->linear.x = speed * 0.737;
drive_msg->angular.z = steer;
std::cout << "Publish Throttle : " << speed << " Publish Steering : " << steer << std::endl;
this->drive_publisher_->publish(std::move(drive_msg));
Expand Down
4 changes: 2 additions & 2 deletions control_ws/src/stanley/src/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Control::Control() : rclcpp::Node("vehicle_control") {
double k = 0.5;
double ks = 1.0;
double ks = 10.0;

this->controller = Stanley(k, ks);

Expand Down Expand Up @@ -76,7 +76,7 @@ void Control::publisher_timer_callback() {

void Control::publish_drive(float speed, float steer) {
auto drive_msg = std::make_unique<geometry_msgs::msg::Twist>();
drive_msg->linear.x = speed;
drive_msg->linear.x = speed*0.737;
drive_msg->angular.z = steer;
// std::cout << "Publish Throttle : " << speed << " Publish Steering : " << steer << std::endl;
this->drive_publisher_->publish(std::move(drive_msg));
Expand Down

0 comments on commit 70198d5

Please sign in to comment.