Skip to content

Commit 2816246

Browse files
committed
Add brake pub
1 parent 20502b9 commit 2816246

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
### v0.1.1 - WIP
99
- [x] Fix control issue. Does not accelerate in 3D.
10-
- [ ] Add braking
10+
- [x] Add braking
1111
- [ ] Add reversing
1212
- [ ] Add turn output
13+
- [ ] Fix turning bug
1314

1415
### v0.1.2 - WIP
1516
- [ ] Add MPC

include/ap1/control/control_node.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class ControlNode : public rclcpp::Node
4747

4848
// Pubs
4949
rclcpp::Publisher<ap1_msgs::msg::FloatStamped>::SharedPtr turning_angle_pub_;
50-
rclcpp::Publisher<ap1_msgs::msg::FloatStamped>::SharedPtr motor_power_pub_; // between -1 and 1? probably
50+
rclcpp::Publisher<ap1_msgs::msg::FloatStamped>::SharedPtr motor_power_pub_;
51+
rclcpp::Publisher<ap1_msgs::msg::FloatStamped>::SharedPtr brake_pub_;
5152

5253
// Methods
5354
void on_speed_profile(const ap1_msgs::msg::SpeedProfileStamped::SharedPtr speed_profile);

src/control_node.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ void ControlNode::control_loop_callback()
7777
const vec3f acc = controller_->compute_acceleration(velocity, target_path_, speed_profile_->speeds.at(0));
7878

7979
// ALY'S FAVOURITE DEBUG CMD 1
80-
RCLCPP_INFO_THROTTLE(this->get_logger(), *this->get_clock(), 700, "ACC: %.2f, %.2f, %.2f", acc.x, acc.y, acc.z);
80+
// RCLCPP_INFO_THROTTLE(this->get_logger(), *this->get_clock(), 700, "ACC: %.2f, %.2f, %.2f", acc.x, acc.y, acc.z);
8181

8282
// compute acc and throttle using ackermann controller
8383
AckermannController::Command cmd = ackermann_controller_.compute_command(acc, velocity);
8484

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

8888
// pack the turn angle into a message
8989
FloatStamped turn_msg;
@@ -95,9 +95,15 @@ void ControlNode::control_loop_callback()
9595
pwr_msg.header.stamp = this->now();
9696
pwr_msg.value = cmd.throttle; // [-1, 1]
9797

98-
// send both messages out
98+
// pack the brake into a message
99+
FloatStamped brake_msg;
100+
brake_msg.header.stamp = this->now();
101+
brake_msg.value = cmd.brake;
102+
103+
// send all messages out
99104
turning_angle_pub_->publish(turn_msg);
100105
motor_power_pub_->publish(pwr_msg);
106+
brake_pub_->publish(brake_msg);
101107
}
102108

103109
ControlNode::ControlNode(const std::string& cfg_path, float rate_hz)
@@ -121,6 +127,7 @@ ControlNode::ControlNode(const std::string& cfg_path, float rate_hz)
121127
// Pubs
122128
turning_angle_pub_ = this->create_publisher<FloatStamped>("/ap1/control/turn_angle", 1);
123129
motor_power_pub_ = this->create_publisher<FloatStamped>("/ap1/control/motor_power", 1);
130+
brake_pub_ = this->create_publisher<FloatStamped>("/ap1/control/brake", 1);
124131

125132
// Create Control Loop
126133
timer_ = this->create_wall_timer(std::chrono::duration<double>(1.0 / rate_hz),

0 commit comments

Comments
 (0)