Skip to content

Commit

Permalink
Merge branch 'main' of github.com:PegasusResearch/pegasus
Browse files Browse the repository at this point in the history
  • Loading branch information
jschpinto committed May 26, 2024
2 parents a8a5c44 + 6e5e481 commit 5a0701f
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 28 deletions.
11 changes: 10 additions & 1 deletion docs/source/console/terminal_console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@ Terminal console
.. image:: /_static/terminal_console/terminal_console.png
:width: 700px
:align: center
:alt: Terminal Console
:alt: Terminal Console

To execute the terminal console you need to run the following command:

.. code:: bash
ros2 run pegasus_console pegasus_console -i <vehicle_id> -n <namespace>
You should replace the ``<vehicle_id>`` with the vehicle id you want to connect to. If not option is provided, the console will attempt to connect to ID 1.
If you want to connect to a specific namespace, you should replace the ``<namespace>`` with the desired namespace. If no namespace is provided, the console will connect to the default namespace "drone".
10 changes: 5 additions & 5 deletions pegasus/launch/real/kopis.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate_launch_description():
# --------------------------------

# Set the default vehicle id (note: this is a trick due to the parameter reading limitation in ROS2)
default_vehicle_id = 1
default_vehicle_id = 7
vehicle_id = default_vehicle_id
for arg in sys.argv:
if arg.startswith('vehicle_id:='):
Expand All @@ -26,9 +26,9 @@ def generate_launch_description():
# ----------------------------------------

# Define the standard mavlink port to forward mavlink data (so that it can also be viewed internally by qgroundcontrol)
udp_local_forward_port = 14559 + vehicle_id
udp_local_forward_adress = "udp://127.0.0.1:" + str(udp_local_forward_port)
desktop_arena = "udp://192.168.1.100:15006"
#udp_local_forward_port = 14559 + vehicle_id + 10
#udp_local_forward_adress = "udp://127.0.0.1:" + str(udp_local_forward_port)
#desktop_arena = "udp://192.168.1.100:15006"
#mavlink_forward_addresses = "[" + udp_local_forward_adress + ',' + desktop_arena + "]"
mavlink_forward_addresses = "['']"

Expand All @@ -38,7 +38,7 @@ def generate_launch_description():
namespace_arg = DeclareLaunchArgument('vehicle_ns', default_value='drone', description='Namespace to append to every topic and node name')

# Define the drone MAVLINK IP and PORT
mav_connection_arg = DeclareLaunchArgument('connection', default_value='udp://:15007', description='The interface used to connect to the vehicle')
mav_connection_arg = DeclareLaunchArgument('connection', default_value='udp://:' + str(15000 + vehicle_id), description='The interface used to connect to the vehicle')

# Define the drone MAVLINK forward ips and ports
mavlink_forward_arg = DeclareLaunchArgument('mavlink_forward', default_value=mavlink_forward_addresses, description='A list of ips where to forward mavlink messages')
Expand Down
2 changes: 1 addition & 1 deletion pegasus/launch/real/pegasus.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def generate_launch_description():
# --------------------------------

# Set the default vehicle id (note: this is a trick due to the parameter reading limitation in ROS2)
default_vehicle_id = 1
default_vehicle_id = 8
vehicle_id = default_vehicle_id
for arg in sys.argv:
if arg.startswith('vehicle_id:='):
Expand Down
5 changes: 4 additions & 1 deletion pegasus_console/include/pegasus_console/console_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ConsoleNode : public rclcpp::Node {

public:

ConsoleNode();
ConsoleNode(const std::string vehicle_namespace, const unsigned int vehicle_id);
~ConsoleNode();

void initialize_subscribers();
Expand Down Expand Up @@ -126,6 +126,9 @@ class ConsoleNode : public rclcpp::Node {
void status_callback(const pegasus_msgs::msg::Status::ConstSharedPtr msg);
void autopilot_status_callback(const pegasus_msgs::msg::AutopilotStatus::ConstSharedPtr msg);

// Auxiliar variable to setup the vehicle namespace when launching the node as a normal c++ program
std::string vehicle_namespace_;

// Configuration for the console UI
ConsoleUI::Config config_;

Expand Down
41 changes: 22 additions & 19 deletions pegasus_console/src/console_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
#include "console_node.hpp"
#include "pegasus_utils/rotations.hpp"

ConsoleNode::ConsoleNode() : rclcpp::Node("pegasus_console") {
ConsoleNode::ConsoleNode(const std::string vehicle_namespace, const unsigned int vehicle_id=1) : rclcpp::Node("pegasus_console") {

// Initialize the vehicle namespace
vehicle_namespace_ = std::string(vehicle_namespace + std::to_string(vehicle_id));

// Initialize the subscribers, services and publishers
initialize_publishers();
Expand Down Expand Up @@ -91,9 +94,9 @@ ConsoleNode::~ConsoleNode() {}

void ConsoleNode::initialize_subscribers() {

this->declare_parameter<std::string>("console.subscribers.onboard.status", "/drone1/fmu/status");
this->declare_parameter<std::string>("console.subscribers.onboard.state", "/drone1/fmu/filter/state");
this->declare_parameter<std::string>("console.subscribers.autopilot.status", "/drone1/autopilot/status");
this->declare_parameter<std::string>("console.subscribers.onboard.status", vehicle_namespace_ + std::string("/fmu/status"));
this->declare_parameter<std::string>("console.subscribers.onboard.state", vehicle_namespace_ + std::string("/fmu/filter/state"));
this->declare_parameter<std::string>("console.subscribers.autopilot.status", vehicle_namespace_ + std::string("/autopilot/status"));

// Status of the vehicle
status_sub_ = this->create_subscription<pegasus_msgs::msg::Status>(
Expand All @@ -113,8 +116,8 @@ void ConsoleNode::initialize_subscribers() {

void ConsoleNode::initialize_publishers() {

this->declare_parameter<std::string>("console.publishers.onboard.attitude_rate", "/drone1/fmu/in/throtle/attitude_rate");
this->declare_parameter<std::string>("console.publishers.onboard.position", "/drone1/fmu/in/position");
this->declare_parameter<std::string>("console.publishers.onboard.attitude_rate", vehicle_namespace_ + std::string("/fmu/in/throtle/attitude_rate"));
this->declare_parameter<std::string>("console.publishers.onboard.position", vehicle_namespace_ + std::string("/fmu/in/position"));

// Publish the attitude setpoints to the vehicle for thrust curve control
attitude_rate_pub_ = this->create_publisher<pegasus_msgs::msg::ControlAttitude>(
Expand All @@ -129,19 +132,19 @@ void ConsoleNode::initialize_publishers() {

void ConsoleNode::initialize_services() {

this->declare_parameter<std::string>("console.services.onboard.arm_disarm", "/drone1/fmu/arm");
this->declare_parameter<std::string>("console.services.onboard.land", "/drone1/fmu/land");
this->declare_parameter<std::string>("console.services.onboard.kill_switch", "/drone1/fmu/kill_switch");
this->declare_parameter<std::string>("console.services.onboard.position_hold", "/drone1/fmu/hold");
this->declare_parameter<std::string>("console.services.onboard.offboard", "/drone1/fmu/offboard");

this->declare_parameter<std::string>("console.services.autopilot.set_mode", "/drone1/autopilot/change_mode");
this->declare_parameter<std::string>("console.services.autopilot.set_waypoint", "/drone1/autopilot/set_waypoint");
this->declare_parameter<std::string>("console.services.autopilot.add_arc", "/drone1/autopilot/trajectory/add_arc");
this->declare_parameter<std::string>("console.services.autopilot.add_line", "/drone1/autopilot/trajectory/add_line");
this->declare_parameter<std::string>("console.services.autopilot.add_circle", "/drone1/autopilot/trajectory/add_circle");
this->declare_parameter<std::string>("console.services.autopilot.add_lemniscate", "/drone1/autopilot/trajectory/add_lemniscate");
this->declare_parameter<std::string>("console.services.autopilot.reset_path", "/drone1/autopilot/trajectory/reset");
this->declare_parameter<std::string>("console.services.onboard.arm_disarm", vehicle_namespace_ + std::string("/fmu/arm"));
this->declare_parameter<std::string>("console.services.onboard.land", vehicle_namespace_ + std::string("/fmu/land"));
this->declare_parameter<std::string>("console.services.onboard.kill_switch", vehicle_namespace_ + std::string("/fmu/kill_switch"));
this->declare_parameter<std::string>("console.services.onboard.position_hold", vehicle_namespace_ + std::string("/fmu/hold"));
this->declare_parameter<std::string>("console.services.onboard.offboard", vehicle_namespace_ + std::string("/fmu/offboard"));

this->declare_parameter<std::string>("console.services.autopilot.set_mode", vehicle_namespace_ + std::string("/autopilot/change_mode"));
this->declare_parameter<std::string>("console.services.autopilot.set_waypoint", vehicle_namespace_ + std::string("/autopilot/set_waypoint"));
this->declare_parameter<std::string>("console.services.autopilot.add_arc", vehicle_namespace_ + std::string("/autopilot/trajectory/add_arc"));
this->declare_parameter<std::string>("console.services.autopilot.add_line", vehicle_namespace_ + std::string("/autopilot/trajectory/add_line"));
this->declare_parameter<std::string>("console.services.autopilot.add_circle", vehicle_namespace_ + std::string("/autopilot/trajectory/add_circle"));
this->declare_parameter<std::string>("console.services.autopilot.add_lemniscate", vehicle_namespace_ + std::string("/autopilot/trajectory/add_lemniscate"));
this->declare_parameter<std::string>("console.services.autopilot.reset_path", vehicle_namespace_ + std::string("/autopilot/trajectory/reset"));

// Create the service clients
arm_disarm_client_ = this->create_client<pegasus_msgs::srv::Arm>(this->get_parameter("console.services.onboard.arm_disarm").as_string());
Expand Down
34 changes: 33 additions & 1 deletion pegasus_console/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,43 @@
#include "console_node.hpp"

int main(int argc, char * argv[]) {

// --------------------------------------------------------------------------
// ---- Parse the parameters from getopt to get the ID of the vehicle -------
// --------------------------------------------------------------------------

// Default vehicle id
int ch;
unsigned int vehicle_id = 1;
std::string vehicle_namespace = "/drone";

while((ch = getopt(argc, argv, "i:n:")) != -1) {
switch(ch) {
case 'i':
try {
// Check if the ID is a number
vehicle_id = std::stoi(optarg);
} catch (std::invalid_argument& e) {
std::cerr << "The ID of the vehicle must be a number" << std::endl;
return 0;
}
break;
case 'n':
vehicle_namespace = std::string("/") + std::string(optarg);
break;
default:
return 0;
}
}

// --------------------------------------------------------------------------
// ---- Initialize the ROS2 node --------------------------------------------
// --------------------------------------------------------------------------

rclcpp::init(argc, argv);

// Create the ConsoleNode
auto console_node = std::make_shared<ConsoleNode>();
auto console_node = std::make_shared<ConsoleNode>(vehicle_namespace, vehicle_id);
console_node->start();

rclcpp::shutdown();
Expand Down

0 comments on commit 5a0701f

Please sign in to comment.