Skip to content

Commit

Permalink
Added back separate message for internal controller commands
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutherland333 committed Jun 13, 2024
1 parent e0ec59e commit 2127d00
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
3 changes: 2 additions & 1 deletion rosplane/include/controller_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <rclcpp/rclcpp.hpp>
#include <rosflight_msgs/msg/command.hpp>
#include <rosplane_msgs/msg/controller_commands.hpp>
#include <rosplane_msgs/msg/controller_internals.hpp>
#include <rosplane_msgs/msg/state.hpp>
#include <param_manager.hpp>

Expand Down Expand Up @@ -120,7 +121,7 @@ class controller_base : public rclcpp::Node
/**
* This publisher publishes the current commands in the control algorithm.
*/
rclcpp::Publisher<rosplane_msgs::msg::ControllerCommands>::SharedPtr controller_commands_pub_;
rclcpp::Publisher<rosplane_msgs::msg::ControllerInternals>::SharedPtr controller_internals_pub_;

/**
* This subscriber subscribes to the commands the controller uses to calculate control effort.
Expand Down
21 changes: 10 additions & 11 deletions rosplane/src/controller_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ controller_base::controller_base()

// Advertise published topics.
actuators_pub_ = this->create_publisher<rosflight_msgs::msg::Command>("command", 10);
controller_commands_pub_ = this->create_publisher<rosplane_msgs::msg::ControllerCommands>(
"controller_commands_out", 10);
controller_internals_pub_ = this->create_publisher<rosplane_msgs::msg::ControllerInternals>(
"controller_internals", 10);

// Advertise subscribed topics and set bound callbacks.
controller_commands_sub_ = this->create_subscription<rosplane_msgs::msg::ControllerCommands>(
Expand Down Expand Up @@ -120,25 +120,24 @@ void controller_base::actuator_controls_publish()
actuators_pub_->publish(actuators);

// Publish the current control values
rosplane_msgs::msg::ControllerCommands controller_commands;
controller_commands.header.stamp = now;
controller_commands.phi_c = output.phi_c;
controller_commands.theta_c = output.theta_c;
rosplane_msgs::msg::ControllerInternals controller_internals;
controller_internals.header.stamp = now;
controller_internals.phi_c = output.phi_c;
controller_internals.theta_c = output.theta_c;
switch (output.current_zone) {
case alt_zones::TAKE_OFF:
controller_commands.alt_zone = controller_commands.ZONE_TAKE_OFF;
controller_internals.alt_zone = controller_internals.ZONE_TAKE_OFF;
break;
case alt_zones::CLIMB:
controller_commands.alt_zone = controller_commands.ZONE_CLIMB;
controller_internals.alt_zone = controller_internals.ZONE_CLIMB;
break;
case alt_zones::ALTITUDE_HOLD:
controller_commands.alt_zone = controller_commands.ZONE_ALTITUDE_HOLD;
controller_internals.alt_zone = controller_internals.ZONE_ALTITUDE_HOLD;
break;
default:
break;
}
controller_commands.aux_valid = false;
controller_commands_pub_->publish(controller_commands);
controller_internals_pub_->publish(controller_internals);
}
}

Expand Down
1 change: 1 addition & 0 deletions rosplane_msgs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ find_package(rosidl_default_generators REQUIRED)
set(msg_files
"msg/Command.msg"
"msg/ControllerCommands.msg"
"msg/ControllerInternals.msg"
"msg/CurrentPath.msg"
"msg/State.msg"
"msg/Waypoint.msg"
Expand Down
6 changes: 0 additions & 6 deletions rosplane_msgs/msg/ControllerCommands.msg
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ bool aux_valid # Auxiliary commands valid
# parameter for the controller to use these commands.
float32 theta_c # Commanded pitch (rad)
float32 phi_c # Commanded roll (rad)
uint8 alt_zone # Zone in the altitude state machine

uint8 ZONE_TAKE_OFF = 0
uint8 ZONE_CLIMB = 1
uint8 ZONE_DESEND = 2
uint8 ZONE_ALTITUDE_HOLD = 3
12 changes: 12 additions & 0 deletions rosplane_msgs/msg/ControllerInternals.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Internal controller commands output from the outer loops of the autopilot

# header
std_msgs/Header header
float32 theta_c # Commanded pitch (rad)
float32 phi_c # Commanded roll (rad)
uint8 alt_zone # Zone in the altitude state machine

uint8 ZONE_TAKE_OFF = 0
uint8 ZONE_CLIMB = 1
uint8 ZONE_DESEND = 2
uint8 ZONE_ALTITUDE_HOLD = 3
2 changes: 1 addition & 1 deletion rosplane_tuning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Signal generator is a ROS2 node that will generate step inputs, square waves, si

This is useful for tuning autopilots as we can give a clear and repeatable command to any portion of the autopilot and observe its response to that input. We can then tune gains, re-issue the same commands, and observe whether performance improved or worsened.

Signal generator works by publishing autopilot commands on the ROS network on the `controller_commands` and `tuning_debug` topics. Each control output (roll, pitch, altitude, course, airspeed) has a default values that is set by a ROS parameter. The signal generator will then add the generated signal to one of the control outputs with a set magnitude and frequency.
Signal generator works by publishing autopilot commands on the ROS network on the `controller_commands` topic. Each control output (roll, pitch, altitude, course, airspeed) has a default values that is set by a ROS parameter. The signal generator will then add the generated signal to one of the control outputs with a set magnitude and frequency.

### Signal Types
- Step: This is a non-continuous signal, where the generated signal will jump between the default value and the default+magnitude every time the `toggle_step_signal` service is called.
Expand Down

0 comments on commit 2127d00

Please sign in to comment.