37 int main(
int argc,
char** argv) {
39 ros::init(argc, argv,
"dronecan_communicator");
48 std::string node_id_param =
"uavcan_node_id";
49 if (ros_node.
getParam(node_id_param.c_str(), node_id)) {
50 std::cout <<
"Param " << node_id_param <<
": " << node_id << std::endl;
52 std::cout <<
"Param " << node_id_param <<
": is missing in your config file." << std::endl;
56 std::string uavcan_node_name;
57 std::string node_name_param =
"uavcan_node_name";
58 if (ros_node.
getParam(node_name_param.c_str(), uavcan_node_name)) {
59 std::cout <<
"Param " << node_name_param <<
": " << uavcan_node_name << std::endl;
61 std::cout <<
"Param " << node_name_param <<
": is missing in your config file." << std::endl;
66 const int self_node_id = node_id;
67 uavcan_node.setNodeID(self_node_id);
68 uavcan_node.setName(uavcan_node_name.c_str());
69 uavcan::protocol::SoftwareVersion sw_version;
71 uavcan_node.setSoftwareVersion(sw_version);
72 uavcan::protocol::HardwareVersion hw_version;
74 uavcan_node.setHardwareVersion(hw_version);
75 const int node_start_res = uavcan_node.start();
76 if (node_start_res < 0) {
77 throw std::runtime_error(
"ERROR: Uavcan_node: " + std::to_string(node_start_res));
82 std::vector<std::string> bridges;
83 std::vector<std::unique_ptr<Converter>> converters;
84 if (ros_node.
getParam(
"bridges", bridges)) {
85 if (bridges.size() == 0 || bridges.size() % 2 == 1) {
86 std::cout <<
"ERROR. Param problem: The size of `bridges` must be even." << std::endl;
89 for (
size_t idx = 0; idx < bridges.size(); idx += 2) {
90 auto bridge_name = bridges[idx];
91 auto topic_name = bridges[idx + 1].c_str();
93 std::cout << idx / 2 <<
". Creation of converter with name `" << bridge_name <<
"` "
94 <<
"and topic `" << topic_name <<
"` has been ";
95 if (converter.get() ==
nullptr) {
96 std::cout <<
"\033[1;31m" <<
"failed: wrong converter name. Exit." <<
"\033[0m" << std::endl;
99 converters.push_back(std::move(converter));
100 std::cout <<
"successful." << std::endl;
104 std::cout <<
"Param problem: you should specify bridges in your config file." << std::endl;
108 uavcan_node.setModeOperational();
109 uavcan_node.setHealthOk();
114 std::cerr <<
"Transient failure: " << res << std::endl;