Skip to content

Commit

Permalink
#7 Optimize with 3.5 throttle
Browse files Browse the repository at this point in the history
  • Loading branch information
dongdongO committed Apr 15, 2024
1 parent 70198d5 commit 2e51b4a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 3 additions & 2 deletions control_ws/src/pure_pursuit/src/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ void Control::publisher_timer_callback() {

this->controller.purepursuit_control(this->refPoses, this->target_velocity, this->currPose.x, this->currPose.y, this->currPose.yaw, this->currPose.v);

this->speedCommand = this->controller.getThrottle();
// this->speedCommand = this->controller.getThrottle();
this->speedCommand = 0.5;
// this->steerCommand = - this->controller.getDelta() * 180 / M_PI;
this->steerCommand = this->controller.getDelta();

Expand All @@ -74,7 +75,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.737;
drive_msg->linear.x = speed;
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
20 changes: 14 additions & 6 deletions control_ws/src/stanley/src/control.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "control.hpp"

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

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

Expand Down Expand Up @@ -39,14 +39,15 @@ void Control::path_callback(const nav_msgs::msg::Path::SharedPtr path_msg) {

void Control::velocity_callback(const example_interfaces::msg::Float64::SharedPtr velocity_msg) {
this->velocityValid = false;
std::cout << "target speed : " << velocity_msg->data << std::endl;
this->target_velocity = velocity_msg->data;
this->velocityValid = true;
}

void Control::pose_callback(const nav_msgs::msg::Odometry::SharedPtr pose_msg) {
this->poseValid = false;
this->currPose.x = pose_msg->pose.pose.position.x * 100 + 22.656; // [cm]
this->currPose.y = pose_msg->pose.pose.position.y * 100 + 47.281; // [cm]
this->currPose.x = pose_msg->pose.pose.position.x * 100 + 33; // [cm]
this->currPose.y = pose_msg->pose.pose.position.y * 100 + 50; // [cm]

tf2::Quaternion q(
pose_msg->pose.pose.orientation.x,
Expand All @@ -69,16 +70,23 @@ void Control::publisher_timer_callback() {
this->controller.stanley_control(this->refPoses, this->target_velocity, this->currPose.x, this->currPose.y, this->currPose.yaw, this->currPose.v);

this->speedCommand = this->controller.getThrottle();
// this->speedCommand = 0.5;
this->steerCommand = this->controller.getDelta();

Path lastRefPose = this->refPoses.back();
if ((std::pow(this->currPose.x - lastRefPose.x, 2) + std::pow(this->currPose.y - lastRefPose.y, 2)) < 40.0) {
std::cout << "Finished!!!" << std::endl;
this->speedCommand = 0.0;
}

this->publish_drive(this->speedCommand, this->steerCommand);
}

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

Expand Down
8 changes: 4 additions & 4 deletions control_ws/src/stanley/src/controller/stanley.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ void Stanley::stanley_control(std::vector<Path> refPoses, double target_v, doubl
this->target_speed = target_v;
this->refPoses = refPoses;
this->update_state(x, y, yaw, v);
std::cout << "Current Speed : " << this->v << " Current accerleration : " << this->acceleration << std::endl;
std::cout << "Current Speed : " << this->v << " Current accerleration : " << this->acceleration << " Target Speed : " << target_v << std::endl;

this->acceleration = this->pid_speed_control();
// this->acceleration = this->pid_speed_control();
this->update_target_node();
this->delta = this->stanley_steer_calc();
this->stanley_throttle_calc();
Expand Down Expand Up @@ -117,8 +117,8 @@ double Stanley::pi_2_pi(double angle) {
}

void Stanley::stanley_throttle_calc() {
this->v += this->acceleration * this->dt;
// std::cout << "Accerleration : " << this->acceleration << " V: " << this->v << std::endl;
// this->v += this->acceleration * this->dt;
this->v = this->target_speed;
}

bool Stanley::isNearby(std::vector<double> cpoint, std::vector<double> target_point) {
Expand Down

0 comments on commit 2e51b4a

Please sign in to comment.