Skip to content

Commit f9e29be

Browse files
committed
Clean imports, comments, msg packaging
1 parent cdb8747 commit f9e29be

3 files changed

Lines changed: 16 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [ ] Add reversing
1313
- [ ] Add turn output
1414
- [ ] Fix turning bug
15+
- [ ] Throttle all main loop logs
1516

1617
### v0.1.2 - WIP
1718
- [ ] Add MPC

src/ackermann_controller.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <algorithm>
88
#include <cmath>
99
#include <fstream>
10+
#include <iostream>
1011
#include <sstream>
1112
#include <stdexcept>
1213
#include <string>
@@ -67,23 +68,16 @@ AckermannController::Command AckermannController::compute_command(const vec3f& a
6768
double speed = vel.length();
6869
double kappa = (speed > EPSILON) ? a_lat / (speed * speed) : 0.0;
6970
double delta = std::atan(cfg_.L * kappa);
70-
delta = std::clamp(delta, -cfg_.delta_max, cfg_.delta_max);
71-
72-
double throttle = 0.0;
73-
double brake = 0.0;
71+
cmd.steering = delta = std::clamp(delta, -cfg_.delta_max, cfg_.delta_max);
7472

7573
if (a_long >= 0.0) {
76-
throttle = std::clamp(a_long / cfg_.a_max * cfg_.throttle_gain, 0.0, 1.0);
77-
brake = 0.0;
74+
cmd.throttle = std::clamp(a_long / cfg_.a_max * cfg_.throttle_gain, 0.0, 1.0);
75+
cmd.brake = 0.0;
7876
} else {
79-
throttle = 0.0;
80-
brake = std::clamp(-a_long / cfg_.a_max * cfg_.brake_gain, 0.0, 1.0);
77+
cmd.throttle = 0.0;
78+
cmd.brake = std::clamp(-a_long / cfg_.a_max * cfg_.brake_gain, 0.0, 1.0);
8179
}
8280

83-
cmd.throttle = throttle;
84-
cmd.brake = brake;
85-
cmd.steering = delta;
86-
8781
return cmd;
8882
}
8983

@@ -93,14 +87,11 @@ AckermannController::Config AckermannController::load_config(const std::string&
9387

9488
auto map = load_csv_config(path);
9589

96-
if (map.count("wheelbase"))
97-
cfg.L = map["wheelbase"];
98-
if (map.count("a_max"))
99-
cfg.a_max = map["a_max"];
100-
if (map.count("delta_max"))
101-
cfg.delta_max = map["delta_max"];
102-
if (map.count("throttle_gain"))
103-
cfg.throttle_gain = map["throttle_gain"];
90+
cfg.L = map["wheelbase"];
91+
cfg.a_max = map["a_max"];
92+
cfg.delta_max = map["delta_max"];
93+
cfg.throttle_gain = map["throttle_gain"];
94+
cfg.brake_gain = map["brake_gain"];
10495

10596
return cfg;
10697
}

src/control_node.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ void ControlNode::control_loop_callback()
5050
return;
5151
}
5252

53-
// the car's current velocity. we only support moving forward atp
53+
// the car's current velocity - the car only ever moves forward G
5454
const vec3f velocity(this->vehicle_speed_->value, 0, 0); // +x is always forward on the car
5555

5656
const bool PATH_IS_STALE = false, SPEED_PROFILE_IS_STALE = false; // TEMP
5757

5858
// if path has no waypoints OR path is too old
5959
if (!target_path_ || target_path_->path.size() < 1 || PATH_IS_STALE) {
60-
RCLCPP_WARN(this->get_logger(), "Target path is cooked fam. Null, not enough waypoints, or old, skipping."); // TODO: should be throttled
60+
RCLCPP_WARN_THROTTLE(this->get_logger(), *this->get_clock(), 5000, "Target path is invalid. Null, not enough waypoints, or old, skipping.");
6161
return;
6262
}
6363

6464
// if speed profile has no waypoints or speed profile is too old
6565
if (!speed_profile_ || speed_profile_->speeds.size() < 1 || SPEED_PROFILE_IS_STALE) {
66-
RCLCPP_WARN(this->get_logger(), "Speed profile is cooked fam. Null, not enough waypoints, or old, skipping.");
66+
RCLCPP_WARN_THROTTLE(this->get_logger(), *this->get_clock(), 5000, "Speed profile is invalid. Null, not enough waypoints, or old, skipping.");
6767
return;
6868
}
6969

@@ -77,7 +77,7 @@ void ControlNode::control_loop_callback()
7777
AckermannController::Command cmd = ackermann_controller_.compute_command(acc, velocity);
7878

7979
// ALY'S FAVOURITE DEBUG CMD 2
80-
// RCLCPP_INFO_THROTTLE(this->get_logger(), *this->get_clock(), 700, "CMD: {throttle: %.2f, steering: %.2f}", cmd.throttle, cmd.steering);
80+
// RCLCPP_INFO_THROTTLE(this->get_logger(), *this->get_clock(), 700, "CMD: {throttle: %.2f, steering: %.2f, brake: %.2f}", cmd.throttle, cmd.steering, cmd.brake);
8181

8282
// pack the turn angle into a message
8383
FloatStamped turn_msg;

0 commit comments

Comments
 (0)