2016-10-10 21:22:17 -03:00
|
|
|
#pragma once
|
|
|
|
#include "ros/ros.h"
|
|
|
|
#include "sensor_msgs/NavSatFix.h"
|
|
|
|
#include "mavros_msgs/GlobalPositionTarget.h"
|
|
|
|
#include "mavros_msgs/CommandCode.h"
|
|
|
|
#include "mavros_msgs/CommandInt.h"
|
2016-11-18 15:05:31 -04:00
|
|
|
#include "mavros_msgs/ExtendedState.h"
|
2016-10-10 21:22:17 -03:00
|
|
|
#include "mavros_msgs/State.h"
|
|
|
|
#include "mavros_msgs/BatteryStatus.h"
|
|
|
|
#include "mavros_msgs/Mavlink.h"
|
|
|
|
#include "sensor_msgs/NavSatStatus.h"
|
|
|
|
#include <sstream>
|
|
|
|
#include <buzz/buzzasm.h>
|
|
|
|
#include "buzzuav_closures.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>
|
|
|
|
|
|
|
|
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;
|
|
|
|
int timer_step=0;
|
|
|
|
int robot_id=0;
|
|
|
|
int oldcmdID=0;
|
|
|
|
int rc_cmd;
|
2016-12-02 20:11:36 -04:00
|
|
|
int bzz_old_cmd=0;
|
2016-11-28 21:35:33 -04:00
|
|
|
std::string bzzfile_name, fcclient_name, rcservice_name,bcfname,dbgfname,out_payload,in_payload; //, rcclient;
|
2016-10-10 21:22:17 -03:00
|
|
|
bool rcclient;
|
|
|
|
ros::ServiceClient mav_client;
|
|
|
|
ros::Publisher payload_pub;
|
|
|
|
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;
|
2016-10-10 21:22:17 -03:00
|
|
|
/*Commands for flight controller*/
|
2016-11-28 21:53:56 -04:00
|
|
|
mavros_msgs::CommandInt cmd_srv;
|
2016-11-14 18:12:12 -04:00
|
|
|
|
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
|
|
|
|
|
|
|
/*Maintain neighbours position*/
|
2016-11-18 15:05:31 -04:00
|
|
|
void neighbours_pos_maintain(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);
|
|
|
|
/*convert from catresian to spherical coordinate system callback */
|
2016-11-18 15:05:31 -04:00
|
|
|
double* cvt_spherical_coordinates(double neighbours_pos_payload []);
|
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);
|
|
|
|
|
|
|
|
/*flight status callback*/
|
|
|
|
void flight_status_update(const mavros_msgs::ExtendedState::ConstPtr& msg);
|
|
|
|
|
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 */
|
2016-11-18 15:05:31 -04:00
|
|
|
bool rc_callback(mavros_msgs::CommandInt::Request &req,
|
2016-10-10 21:22:17 -03:00
|
|
|
mavros_msgs::CommandInt::Response &res);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|