2016-10-10 21:22:17 -03:00
|
|
|
#pragma once
|
2017-02-10 15:18:44 -04:00
|
|
|
#include <ros/ros.h>
|
|
|
|
#include <sensor_msgs/NavSatFix.h>
|
2017-02-20 00:30:45 -04:00
|
|
|
#include <std_msgs/UInt8.h>
|
2016-10-10 21:22:17 -03:00
|
|
|
#include "mavros_msgs/GlobalPositionTarget.h"
|
|
|
|
#include "mavros_msgs/CommandCode.h"
|
2017-02-16 21:58:21 -04:00
|
|
|
#include "mavros_msgs/CommandLong.h"
|
2017-02-17 17:35:08 -04:00
|
|
|
#include "mavros_msgs/CommandBool.h"
|
2016-11-18 15:05:31 -04:00
|
|
|
#include "mavros_msgs/ExtendedState.h"
|
2017-02-17 17:35:08 -04:00
|
|
|
#include "mavros_msgs/SetMode.h"
|
2016-10-10 21:22:17 -03:00
|
|
|
#include "mavros_msgs/State.h"
|
|
|
|
#include "mavros_msgs/BatteryStatus.h"
|
|
|
|
#include "mavros_msgs/Mavlink.h"
|
2017-03-13 19:11:01 -03:00
|
|
|
#include "mavros_msgs/PositionTarget.h"
|
2016-10-10 21:22:17 -03:00
|
|
|
#include "sensor_msgs/NavSatStatus.h"
|
2017-02-10 15:18:44 -04:00
|
|
|
#include <sensor_msgs/LaserScan.h>
|
2017-01-09 18:15:33 -04:00
|
|
|
#include <rosbuzz/neigh_pos.h>
|
2016-10-10 21:22:17 -03:00
|
|
|
#include <sstream>
|
|
|
|
#include <buzz/buzzasm.h>
|
|
|
|
#include "buzz_utility.h"
|
|
|
|
#include "uav_utility.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <ostream>
|
|
|
|
#include <map>
|
2016-12-24 21:59:00 -04:00
|
|
|
#include "buzzuav_closures.h"
|
2016-10-10 21:22:17 -03:00
|
|
|
|
2017-01-27 23:00:11 -04:00
|
|
|
#define UPDATER_MESSAGE_CONSTANT 987654321
|
2017-01-29 04:03:29 -04:00
|
|
|
#define XBEE_MESSAGE_CONSTANT 586782343
|
|
|
|
#define XBEE_STOP_TRANSMISSION 4355356352
|
2017-01-27 23:00:11 -04:00
|
|
|
|
2016-10-10 21:22:17 -03:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace rosbzz_node{
|
2016-11-28 21:35:33 -04:00
|
|
|
|
2016-10-10 21:22:17 -03:00
|
|
|
class roscontroller{
|
|
|
|
|
|
|
|
public:
|
2016-11-28 21:35:33 -04:00
|
|
|
roscontroller(ros::NodeHandle n_c);
|
2016-10-10 21:22:17 -03:00
|
|
|
~roscontroller();
|
|
|
|
//void RosControllerInit();
|
|
|
|
void RosControllerRun();
|
2016-11-14 18:12:12 -04:00
|
|
|
|
2016-10-10 21:22:17 -03:00
|
|
|
private:
|
|
|
|
|
|
|
|
double cur_pos[3];
|
|
|
|
uint64_t payload;
|
|
|
|
std::map< int, buzz_utility::Pos_struct> neighbours_pos_map;
|
2017-01-11 14:14:05 -04:00
|
|
|
std::map< int, buzz_utility::Pos_struct> raw_neighbours_pos_map;
|
2017-01-13 16:03:21 -04:00
|
|
|
//std::map< int, buzz_utility::Pos_struct> pub_neigh_pos;
|
2016-10-10 21:22:17 -03:00
|
|
|
int timer_step=0;
|
|
|
|
int robot_id=0;
|
2016-12-24 21:59:00 -04:00
|
|
|
//int oldcmdID=0;
|
2016-10-10 21:22:17 -03:00
|
|
|
int rc_cmd;
|
2017-02-23 12:49:10 -04:00
|
|
|
int armstate;
|
2017-01-08 14:17:13 -04:00
|
|
|
int barrier;
|
2017-02-19 20:22:47 -04:00
|
|
|
int message_number=0;
|
2017-02-17 23:00:50 -04:00
|
|
|
std::string bzzfile_name, fcclient_name, armclient, modeclient, rcservice_name,bcfname,dbgfname,out_payload,in_payload,stand_by;
|
2016-10-10 21:22:17 -03:00
|
|
|
bool rcclient;
|
2017-01-29 04:03:29 -04:00
|
|
|
bool multi_msg;
|
2016-10-10 21:22:17 -03:00
|
|
|
ros::ServiceClient mav_client;
|
|
|
|
ros::Publisher payload_pub;
|
2017-01-09 18:15:33 -04:00
|
|
|
ros::Publisher neigh_pos_pub;
|
2017-03-13 19:11:01 -03:00
|
|
|
ros::Publisher localsetpoint_pub;
|
2016-10-10 21:22:17 -03:00
|
|
|
ros::ServiceServer service;
|
|
|
|
ros::Subscriber current_position_sub;
|
|
|
|
ros::Subscriber battery_sub;
|
|
|
|
ros::Subscriber payload_sub;
|
2016-11-18 15:05:31 -04:00
|
|
|
ros::Subscriber flight_status_sub;
|
2017-02-10 15:18:44 -04:00
|
|
|
ros::Subscriber obstacle_sub;
|
2017-02-20 00:30:45 -04:00
|
|
|
ros::Subscriber Robot_id_sub;
|
2016-10-10 21:22:17 -03:00
|
|
|
/*Commands for flight controller*/
|
2017-02-16 21:58:21 -04:00
|
|
|
//mavros_msgs::CommandInt cmd_srv;
|
|
|
|
mavros_msgs::CommandLong cmd_srv;
|
|
|
|
|
2017-02-15 19:08:41 -04:00
|
|
|
std::vector<std::string> m_sMySubscriptions;
|
|
|
|
std::map<std::string, std::string> m_smTopic_infos;
|
|
|
|
|
2017-02-17 17:35:08 -04:00
|
|
|
mavros_msgs::CommandBool m_cmdBool;
|
|
|
|
ros::ServiceClient arm_client;
|
|
|
|
|
|
|
|
mavros_msgs::SetMode m_cmdSetMode;
|
|
|
|
ros::ServiceClient mode_client;
|
2016-10-10 21:22:17 -03:00
|
|
|
|
2016-11-28 21:35:33 -04:00
|
|
|
void Initialize_pub_sub(ros::NodeHandle n_c);
|
2016-10-10 21:22:17 -03:00
|
|
|
|
|
|
|
/*Obtain data from ros parameter server*/
|
2016-11-28 21:35:33 -04:00
|
|
|
void Rosparameters_get(ros::NodeHandle n_c);
|
2016-10-10 21:22:17 -03:00
|
|
|
|
2016-11-18 15:05:31 -04:00
|
|
|
/*compiles buzz script from the specified .bzz file*/
|
2016-10-10 21:22:17 -03:00
|
|
|
void Compile_bzz();
|
|
|
|
|
|
|
|
/*Prepare messages and publish*/
|
2016-11-18 15:05:31 -04:00
|
|
|
void prepare_msg_and_publish();
|
2016-10-10 21:22:17 -03:00
|
|
|
|
|
|
|
|
|
|
|
/*Refresh neighbours Position for every ten step*/
|
2016-11-18 15:05:31 -04:00
|
|
|
void maintain_pos(int tim_step);
|
2016-10-10 21:22:17 -03:00
|
|
|
|
2017-01-11 14:14:05 -04:00
|
|
|
/*Puts neighbours position inside neigbours_pos_map*/
|
|
|
|
void neighbours_pos_put(int id, buzz_utility::Pos_struct pos_arr );
|
|
|
|
|
|
|
|
/*Puts raw neighbours position in lat.,long.,alt. inside raw_neigbours_pos_map*/
|
|
|
|
void raw_neighbours_pos_put(int id, buzz_utility::Pos_struct pos_arr );
|
2016-10-10 21:22:17 -03:00
|
|
|
|
|
|
|
/*Set the current position of the robot callback*/
|
2016-11-18 15:05:31 -04:00
|
|
|
void set_cur_pos(double latitude,
|
2016-10-10 21:22:17 -03:00
|
|
|
double longitude,
|
|
|
|
double altitude);
|
2017-01-27 00:19:16 -04:00
|
|
|
/*convert from spherical to cartesian coordinate system callback */
|
2017-01-30 22:58:48 -04:00
|
|
|
void cvt_rangebearing_coordinates(double neighbours_pos_payload [], double out[], double pos[]);
|
|
|
|
|
2016-10-10 21:22:17 -03:00
|
|
|
/*battery status callback*/
|
2016-11-18 15:05:31 -04:00
|
|
|
void battery(const mavros_msgs::BatteryStatus::ConstPtr& msg);
|
|
|
|
|
2017-02-15 19:08:41 -04:00
|
|
|
/*flight extended status callback*/
|
|
|
|
void flight_extended_status_update(const mavros_msgs::ExtendedState::ConstPtr& msg);
|
|
|
|
|
2016-11-18 15:05:31 -04:00
|
|
|
/*flight status callback*/
|
2017-02-15 19:08:41 -04:00
|
|
|
void flight_status_update(const mavros_msgs::State::ConstPtr& msg);
|
2016-11-18 15:05:31 -04:00
|
|
|
|
2016-10-10 21:22:17 -03:00
|
|
|
/*current position callback*/
|
2016-11-18 15:05:31 -04:00
|
|
|
void current_pos(const sensor_msgs::NavSatFix::ConstPtr& msg);
|
2016-10-10 21:22:17 -03:00
|
|
|
|
|
|
|
/*payload callback callback*/
|
2016-11-18 15:05:31 -04:00
|
|
|
void payload_obt(const mavros_msgs::Mavlink::ConstPtr& msg);
|
2016-10-10 21:22:17 -03:00
|
|
|
|
|
|
|
/* RC commands service */
|
2017-02-16 21:58:21 -04:00
|
|
|
bool rc_callback(mavros_msgs::CommandLong::Request &req, mavros_msgs::CommandLong::Response &res);
|
2016-10-10 21:22:17 -03:00
|
|
|
|
2017-02-20 00:30:45 -04:00
|
|
|
/*robot id sub callback*/
|
|
|
|
void set_robot_id(const std_msgs::UInt8::ConstPtr& msg);
|
|
|
|
|
2017-02-10 15:18:44 -04:00
|
|
|
void obstacle_dist(const sensor_msgs::LaserScan::ConstPtr& msg);
|
2016-10-10 21:22:17 -03:00
|
|
|
|
2017-02-15 19:08:41 -04:00
|
|
|
void GetSubscriptionParameters(ros::NodeHandle node_handle);
|
|
|
|
|
2017-02-17 17:35:08 -04:00
|
|
|
void Arm();
|
|
|
|
|
|
|
|
void SetMode();
|
|
|
|
|
2017-02-15 19:08:41 -04:00
|
|
|
void Subscribe(ros::NodeHandle n_c);
|
2016-10-10 21:22:17 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|