-
Notifications
You must be signed in to change notification settings - Fork 0
Created estop #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Created estop #10
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
|
||
#include <chrono> | ||
#include <functional> | ||
#include <memory> | ||
#include "rclcpp/rclcpp.hpp" | ||
|
||
#include "px4_msgs/msg/vehicle_command.hpp" | ||
|
||
using namespace std::chrono_literals; | ||
|
||
class Estop : public rclcpp::Node { | ||
|
||
public: | ||
Estop() | ||
: Node("estop") | ||
{ | ||
for (int i=0; i < maxN; i++){ | ||
std::string topic_name = "/drone" + std::to_string(i) + "/fmu/vehicle_command/in"; | ||
drone_publishers_.push_back( | ||
this->create_publisher<px4_msgs::msg::VehicleCommand>(topic_name,10) | ||
); | ||
} | ||
|
||
for (int i=0; i < maxN; i++){ | ||
std::string topic_name = "/rover" + std::to_string(i) + "/fmu/vehicle_command/in"; | ||
rover_publishers_.push_back( | ||
this->create_publisher<px4_msgs::msg::VehicleCommand>(topic_name,10) | ||
); | ||
} | ||
|
||
timer_ = this->create_wall_timer( | ||
200ms, std::bind(&Estop::timer_callback, this)); | ||
} | ||
|
||
private: | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bool estop = false; |
||
const int maxN = 25; | ||
|
||
rclcpp::TimerBase::SharedPtr timer_; | ||
std::vector<rclcpp::Publisher<px4_msgs::msg::VehicleCommand>::SharedPtr> drone_publishers_; | ||
std::vector<rclcpp::Publisher<px4_msgs::msg::VehicleCommand>::SharedPtr> rover_publishers_; | ||
|
||
|
||
void timer_callback() { | ||
|
||
auto msg = px4_msgs::msg::VehicleCommand(); | ||
msg.timestamp = 0; | ||
msg.param1 = 0.0; | ||
msg.param2 = 21196; // force disarm | ||
msg.command = px4_msgs::msg::VehicleCommand::VEHICLE_CMD_COMPONENT_ARM_DISARM; | ||
msg.target_component = 1; | ||
msg.source_system = 1; | ||
msg.source_component = 1; | ||
msg.from_external = true; | ||
|
||
// drone stop command | ||
for (int i=0; i< maxN; i++){ | ||
msg.target_system = i; | ||
drone_publishers_[i]->publish(msg); | ||
} | ||
|
||
// rover stop command | ||
for (int i=0; i< maxN; i++){ | ||
msg.target_system = i; | ||
rover_publishers_[i]->publish(msg); | ||
} | ||
|
||
RCLCPP_WARN(this->get_logger(), "sending e stop to drones with id less than %d", maxN); | ||
} | ||
|
||
|
||
|
||
}; // class Estop | ||
|
||
|
||
int main(int argc, char* argv[]) { | ||
|
||
std::cout << "Sending ESTOP" << std::endl; | ||
setvbuf(stdout, NULL, _IONBF, BUFSIZ); | ||
|
||
rclcpp::init(argc, argv); | ||
|
||
rclcpp::spin(std::make_shared<Estop>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok good idea, ill make these changes, but we should wait only merge them after weve tested to see that it works. |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Block by
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok we can do something like this. are you sure the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think it should work. |
||
rclcpp::shutdown(); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void estop() {
this->estop = true;
}