beautified and style fixes

This commit is contained in:
dave 2018-12-04 10:34:07 -05:00
parent 5f83aa60f6
commit fbb0f108b1
11 changed files with 2239 additions and 2144 deletions

View File

@ -12,9 +12,9 @@
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*/
/*
* This code was originally written by Stephan Fortune in C code. I, Shane O'Sullivan,
* have since modified it, encapsulating it in a C++ class and, fixing memory leaks and
/*
* This code was originally written by Stephan Fortune in C code. I, Shane O'Sullivan,
* have since modified it, encapsulating it in a C++ class and, fixing memory leaks and
* adding accessors to the Voronoi Edges.
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
@ -36,7 +36,6 @@
#include <stdio.h>
#include <algorithm>
#ifndef NULL
#define NULL 0
#endif
@ -45,210 +44,195 @@
#define le 0
#define re 1
struct Freenode
struct Freenode
{
struct Freenode *nextfree;
struct Freenode* nextfree;
};
struct FreeNodeArrayList
{
struct Freenode* memory;
struct FreeNodeArrayList* next;
struct Freenode* memory;
struct FreeNodeArrayList* next;
};
struct Freelist
struct Freelist
{
struct Freenode *head;
int nodesize;
struct Freenode* head;
int nodesize;
};
struct Point
struct Point
{
float x,y;
Point(): x( 0.0 ), y( 0.0 ) { }
Point( float x, float y ): x( x ), y( y ) { }
float x, y;
Point() : x(0.0), y(0.0)
{
}
Point(float x, float y) : x(x), y(y)
{
}
};
// structure used both for sites and for vertices
struct Site
// structure used both for sites and for vertices
struct Site
{
struct Point coord;
int sitenbr;
int refcnt;
struct Point coord;
int sitenbr;
int refcnt;
};
struct Edge
struct Edge
{
float a,b,c;
struct Site *ep[2];
struct Site *reg[2];
int edgenbr;
int sites[2];
float a, b, c;
struct Site* ep[2];
struct Site* reg[2];
int edgenbr;
int sites[2];
};
struct GraphEdge
{
float x1,y1,x2,y2;
int sites[2];
struct GraphEdge* next;
float x1, y1, x2, y2;
int sites[2];
struct GraphEdge* next;
};
struct Halfedge
struct Halfedge
{
struct Halfedge *ELleft, *ELright;
struct Edge *ELedge;
int ELrefcnt;
char ELpm;
struct Site *vertex;
float ystar;
struct Halfedge *PQnext;
struct Halfedge *ELleft, *ELright;
struct Edge* ELedge;
int ELrefcnt;
char ELpm;
struct Site* vertex;
float ystar;
struct Halfedge* PQnext;
};
class VoronoiDiagramGenerator
{
public:
VoronoiDiagramGenerator();
~VoronoiDiagramGenerator();
VoronoiDiagramGenerator();
~VoronoiDiagramGenerator();
bool generateVoronoi(float *xValues, float *yValues, int numPoints, float minX, float maxX, float minY, float maxY, float minDist=0);
bool generateVoronoi(float* xValues, float* yValues, int numPoints, float minX, float maxX, float minY, float maxY,
float minDist = 0);
void resetIterator()
{
iteratorEdges = allEdges;
}
void resetIterator()
{
iteratorEdges = allEdges;
}
bool getNext(float& x1, float& y1, float& x2, float& y2, int *s)
{
if(iteratorEdges == 0)
return false;
x1 = iteratorEdges->x1;
x2 = iteratorEdges->x2;
y1 = iteratorEdges->y1;
y2 = iteratorEdges->y2;
std::copy(iteratorEdges->sites, iteratorEdges->sites+2, s);
bool getNext(float& x1, float& y1, float& x2, float& y2, int* s)
{
if (iteratorEdges == 0)
return false;
iteratorEdges = iteratorEdges->next;
x1 = iteratorEdges->x1;
x2 = iteratorEdges->x2;
y1 = iteratorEdges->y1;
y2 = iteratorEdges->y2;
std::copy(iteratorEdges->sites, iteratorEdges->sites + 2, s);
return true;
}
iteratorEdges = iteratorEdges->next;
return true;
}
private:
void cleanup();
void cleanupEdges();
char *getfree(struct Freelist *fl);
struct Halfedge *PQfind();
int PQempty();
void cleanup();
void cleanupEdges();
char* getfree(struct Freelist* fl);
struct Halfedge* PQfind();
int PQempty();
struct Halfedge** ELhash;
struct Halfedge *HEcreate(), *ELleft(), *ELright(), *ELleftbnd();
struct Halfedge* HEcreate(struct Edge* e, int pm);
struct Halfedge **ELhash;
struct Halfedge *HEcreate(), *ELleft(), *ELright(), *ELleftbnd();
struct Halfedge *HEcreate(struct Edge *e,int pm);
struct Point PQ_min();
struct Halfedge* PQextractmin();
void freeinit(struct Freelist* fl, int size);
void makefree(struct Freenode* curr, struct Freelist* fl);
void geominit();
void plotinit();
bool voronoi(int triangulate);
void ref(struct Site* v);
void deref(struct Site* v);
void endpoint(struct Edge* e, int lr, struct Site* s);
void ELdelete(struct Halfedge* he);
struct Halfedge* ELleftbnd(struct Point* p);
struct Halfedge* ELright(struct Halfedge* he);
void makevertex(struct Site* v);
void out_triple(struct Site* s1, struct Site* s2, struct Site* s3);
struct Point PQ_min();
struct Halfedge *PQextractmin();
void freeinit(struct Freelist *fl,int size);
void makefree(struct Freenode *curr,struct Freelist *fl);
void geominit();
void plotinit();
bool voronoi(int triangulate);
void ref(struct Site *v);
void deref(struct Site *v);
void endpoint(struct Edge *e,int lr,struct Site * s);
void PQinsert(struct Halfedge* he, struct Site* v, float offset);
void PQdelete(struct Halfedge* he);
bool ELinitialize();
void ELinsert(struct Halfedge* lb, struct Halfedge* newHe);
struct Halfedge* ELgethash(int b);
struct Halfedge* ELleft(struct Halfedge* he);
struct Site* leftreg(struct Halfedge* he);
void out_site(struct Site* s);
bool PQinitialize();
int PQbucket(struct Halfedge* he);
void clip_line(struct Edge* e);
char* myalloc(unsigned n);
int right_of(struct Halfedge* el, struct Point* p);
void ELdelete(struct Halfedge *he);
struct Halfedge *ELleftbnd(struct Point *p);
struct Halfedge *ELright(struct Halfedge *he);
void makevertex(struct Site *v);
void out_triple(struct Site *s1, struct Site *s2,struct Site * s3);
struct Site* rightreg(struct Halfedge* he);
struct Edge* bisect(struct Site* s1, struct Site* s2);
float dist(struct Site* s, struct Site* t);
struct Site* intersect(struct Halfedge* el1, struct Halfedge* el2, struct Point* p = 0);
void PQinsert(struct Halfedge *he,struct Site * v, float offset);
void PQdelete(struct Halfedge *he);
bool ELinitialize();
void ELinsert(struct Halfedge *lb, struct Halfedge *newHe);
struct Halfedge * ELgethash(int b);
struct Halfedge *ELleft(struct Halfedge *he);
struct Site *leftreg(struct Halfedge *he);
void out_site(struct Site *s);
bool PQinitialize();
int PQbucket(struct Halfedge *he);
void clip_line(struct Edge *e);
char *myalloc(unsigned n);
int right_of(struct Halfedge *el,struct Point *p);
void out_bisector(struct Edge* e);
void out_ep(struct Edge* e);
void out_vertex(struct Site* v);
struct Site* nextone();
struct Site *rightreg(struct Halfedge *he);
struct Edge *bisect(struct Site *s1,struct Site *s2);
float dist(struct Site *s,struct Site *t);
struct Site *intersect(struct Halfedge *el1, struct Halfedge *el2, struct Point *p=0);
void pushGraphEdge(float x1, float y1, float x2, float y2, int s[2]);
void out_bisector(struct Edge *e);
void out_ep(struct Edge *e);
void out_vertex(struct Site *v);
struct Site *nextone();
void openpl();
void line(float x1, float y1, float x2, float y2, int s[2]);
void circle(float x, float y, float radius);
void range(float minX, float minY, float maxX, float maxY);
void pushGraphEdge(float x1, float y1, float x2, float y2, int s[2]);
struct Freelist hfl;
struct Halfedge *ELleftend, *ELrightend;
int ELhashsize;
void openpl();
void line(float x1, float y1, float x2, float y2, int s[2]);
void circle(float x, float y, float radius);
void range(float minX, float minY, float maxX, float maxY);
int triangulate, sorted, plot, debug;
float xmin, xmax, ymin, ymax, deltax, deltay;
struct Freelist hfl;
struct Halfedge *ELleftend, *ELrightend;
int ELhashsize;
struct Site* sites;
int nsites;
int siteidx;
int sqrt_nsites;
int nvertices;
struct Freelist sfl;
struct Site* bottomsite;
int triangulate, sorted, plot, debug;
float xmin, xmax, ymin, ymax, deltax, deltay;
int nedges;
struct Freelist efl;
int PQhashsize;
struct Halfedge* PQhash;
int PQcount;
int PQmin;
struct Site *sites;
int nsites;
int siteidx;
int sqrt_nsites;
int nvertices;
struct Freelist sfl;
struct Site *bottomsite;
int ntry, totalsearch;
float pxmin, pxmax, pymin, pymax, cradius;
int total_alloc;
int nedges;
struct Freelist efl;
int PQhashsize;
struct Halfedge *PQhash;
int PQcount;
int PQmin;
float borderMinX, borderMaxX, borderMinY, borderMaxY;
int ntry, totalsearch;
float pxmin, pxmax, pymin, pymax, cradius;
int total_alloc;
FreeNodeArrayList* allMemoryList;
FreeNodeArrayList* currentMemoryBlock;
float borderMinX, borderMaxX, borderMinY, borderMaxY;
GraphEdge* allEdges;
GraphEdge* iteratorEdges;
FreeNodeArrayList* allMemoryList;
FreeNodeArrayList* currentMemoryBlock;
GraphEdge* allEdges;
GraphEdge* iteratorEdges;
float minDistanceBetweenSites;
float minDistanceBetweenSites;
};
int scomp(const void *p1,const void *p2);
int scomp(const void* p1, const void* p2);
#endif

View File

@ -23,149 +23,149 @@
} while (0)
namespace buzz_update
{
static const uint16_t CODE_REQUEST_PADDING = 250;
static const uint16_t MIN_UPDATE_PACKET = 251;
static const uint16_t UPDATE_CODE_HEADER_SIZE = 5;
static const uint16_t TIMEOUT_FOR_ROLLBACK = 50;
/*********************/
/* Updater states */
/********************/
static const uint16_t CODE_REQUEST_PADDING = 250;
static const uint16_t MIN_UPDATE_PACKET = 251;
static const uint16_t UPDATE_CODE_HEADER_SIZE = 5;
static const uint16_t TIMEOUT_FOR_ROLLBACK = 50;
/*********************/
/* Updater states */
/********************/
typedef enum {
CODE_RUNNING = 0, // Code executing
CODE_STANDBY, // Standing by for others to update
} code_states_e;
typedef enum {
CODE_RUNNING = 0, // Code executing
CODE_STANDBY, // Standing by for others to update
} code_states_e;
/*********************/
/*Message types */
/********************/
/*********************/
/*Message types */
/********************/
typedef enum {
SENT_CODE = 0, // Broadcast code
RESEND_CODE, // ReBroadcast request
} code_message_e;
typedef enum {
SENT_CODE = 0, // Broadcast code
RESEND_CODE, // ReBroadcast request
} code_message_e;
/*************************/
/*Updater message queue */
/*************************/
/*************************/
/*Updater message queue */
/*************************/
struct updater_msgqueue_s
{
uint8_t* queue;
uint8_t* size;
};
typedef struct updater_msgqueue_s* updater_msgqueue_t;
struct updater_msgqueue_s
{
uint8_t* queue;
uint8_t* size;
};
typedef struct updater_msgqueue_s* updater_msgqueue_t;
struct updater_code_s
{
uint8_t* bcode;
uint8_t* bcode_size;
};
typedef struct updater_code_s* updater_code_t;
struct updater_code_s
{
uint8_t* bcode;
uint8_t* bcode_size;
};
typedef struct updater_code_s* updater_code_t;
/**************************/
/*Updater data*/
/**************************/
/**************************/
/*Updater data*/
/**************************/
struct buzz_updater_elem_s
{
/* robot id */
// uint16_t robotid;
/*current Bytecode content */
uint8_t* bcode;
/*old Bytecode name */
const char* old_bcode;
/*current bcode size*/
size_t* bcode_size;
/*Update patch*/
uint8_t* patch;
/* Update patch size*/
size_t* patch_size;
/*current Bytecode content */
uint8_t* standby_bcode;
/*current bcode size*/
size_t* standby_bcode_size;
/*updater out msg queue */
updater_msgqueue_t outmsg_queue;
/*updater in msg queue*/
updater_msgqueue_t inmsg_queue;
/*Current state of the updater one in code_states_e ENUM*/
int* mode;
uint8_t* update_no;
};
typedef struct buzz_updater_elem_s* buzz_updater_elem_t;
struct buzz_updater_elem_s
{
/* robot id */
// uint16_t robotid;
/*current Bytecode content */
uint8_t* bcode;
/*old Bytecode name */
const char* old_bcode;
/*current bcode size*/
size_t* bcode_size;
/*Update patch*/
uint8_t* patch;
/* Update patch size*/
size_t* patch_size;
/*current Bytecode content */
uint8_t* standby_bcode;
/*current bcode size*/
size_t* standby_bcode_size;
/*updater out msg queue */
updater_msgqueue_t outmsg_queue;
/*updater in msg queue*/
updater_msgqueue_t inmsg_queue;
/*Current state of the updater one in code_states_e ENUM*/
int* mode;
uint8_t* update_no;
};
typedef struct buzz_updater_elem_s* buzz_updater_elem_t;
/**************************************************************************/
/*Updater routine from msg processing to file checks to be called from main*/
/**************************************************************************/
void update_routine();
/**************************************************************************/
/*Updater routine from msg processing to file checks to be called from main*/
/**************************************************************************/
void update_routine();
/************************************************/
/*Initalizes the updater */
/************************************************/
int init_update_monitor(const char* bo_filename, const char* stand_by_script, const char* dbgfname, int robot_id);
/************************************************/
/*Initalizes the updater */
/************************************************/
int init_update_monitor(const char* bo_filename, const char* stand_by_script, const char* dbgfname, int robot_id);
/*********************************************************/
/*Appends buffer of given size to in msg queue of updater*/
/*********************************************************/
/*********************************************************/
/*Appends buffer of given size to in msg queue of updater*/
/*********************************************************/
void code_message_inqueue_append(uint8_t* msg, uint16_t size);
void code_message_inqueue_append(uint8_t* msg, uint16_t size);
/*********************************************************/
/*Processes messages inside the queue of the updater*/
/*********************************************************/
/*********************************************************/
/*Processes messages inside the queue of the updater*/
/*********************************************************/
void code_message_inqueue_process();
void code_message_inqueue_process();
/*****************************************************/
/*Obtains messages from out msgs queue of the updater*/
/*******************************************************/
uint8_t* getupdater_out_msg();
/*****************************************************/
/*Obtains messages from out msgs queue of the updater*/
/*******************************************************/
uint8_t* getupdater_out_msg();
/******************************************************/
/*Obtains out msg queue size*/
/*****************************************************/
uint8_t* getupdate_out_msg_size();
/******************************************************/
/*Obtains out msg queue size*/
/*****************************************************/
uint8_t* getupdate_out_msg_size();
/**************************************************/
/*Destroys the out msg queue*/
/*************************************************/
void destroy_out_msg_queue();
/**************************************************/
/*Destroys the out msg queue*/
/*************************************************/
void destroy_out_msg_queue();
// buzz_updater_elem_t get_updater();
/***************************************************/
/*Sets bzz file name*/
/***************************************************/
void set_bzz_file(const char* in_bzz_file, bool dbg);
// buzz_updater_elem_t get_updater();
/***************************************************/
/*Sets bzz file name*/
/***************************************************/
void set_bzz_file(const char* in_bzz_file, bool dbg);
/****************************************************/
/*Tests the code from a buffer*/
/***************************************************/
/****************************************************/
/*Tests the code from a buffer*/
/***************************************************/
int test_set_code(uint8_t* BO_BUF, const char* dbgfname, size_t bcode_size);
int test_set_code(uint8_t* BO_BUF, const char* dbgfname, size_t bcode_size);
/****************************************************/
/*Destroys the updater*/
/***************************************************/
/****************************************************/
/*Destroys the updater*/
/***************************************************/
void destroy_updater();
void destroy_updater();
/****************************************************/
/*Checks for updater message*/
/***************************************************/
/****************************************************/
/*Checks for updater message*/
/***************************************************/
int is_msg_present();
int is_msg_present();
/****************************************************/
/*Compiles a bzz script to bo and bdbg*/
/***************************************************/
/****************************************************/
/*Compiles a bzz script to bo and bdbg*/
/***************************************************/
int compile_bzz(std::string bzz_file);
int compile_bzz(std::string bzz_file);
/****************************************************/
/*Set number of robots in the updater*/
/***************************************************/
/****************************************************/
/*Set number of robots in the updater*/
/***************************************************/
void updates_set_robots(int robots);
void updates_set_robots(int robots);
}
#endif

View File

@ -53,8 +53,12 @@ struct neitime
double relative_rate;
int age;
neitime(uint64_t nht, uint64_t nlt, uint64_t mht, uint64_t mlt, double nr, double mr)
: nei_hardware_time(nht), nei_logical_time(nlt), node_hardware_time(mht), node_logical_time(mlt),
nei_rate(nr), relative_rate(mr) {};
: nei_hardware_time(nht)
, nei_logical_time(nlt)
, node_hardware_time(mht)
, node_logical_time(mlt)
, nei_rate(nr)
, relative_rate(mr){};
neitime()
{
}
@ -101,5 +105,4 @@ int get_inmsg_size();
std::vector<uint8_t*> get_inmsg_vector();
std::string get_bvmstate();
}

View File

@ -22,7 +22,7 @@ namespace buzzuav_closures
int buzzros_print(buzzvm_t vm);
void setWPlist(std::string file);
void setVorlog(std::string path);
void check_targets_sim(double lat, double lon, double *res);
void check_targets_sim(double lat, double lon, double* res);
/*
* closure to move following a vector
@ -98,7 +98,7 @@ double* getgoto();
/*
* returns the current grid
*/
std::map<int, std::map<int,int>> getgrid();
std::map<int, std::map<int, int>> getgrid();
int voronoi_center(buzzvm_t vm);
/*

View File

@ -42,14 +42,14 @@
* ROSBuzz message types
*/
typedef enum {
ROS_BUZZ_MSG_NIL = 0, // dummy msg
UPDATER_MESSAGE, // Update msg
BUZZ_MESSAGE, // Broadcast message
BUZZ_MESSAGE_TIME, // Broadcast message with time info
ROS_BUZZ_MSG_NIL = 0, // dummy msg
UPDATER_MESSAGE, // Update msg
BUZZ_MESSAGE, // Broadcast message
BUZZ_MESSAGE_TIME, // Broadcast message with time info
} rosbuzz_msgtype;
// Time sync algo. constants
#define COM_DELAY 100000000 // in nano seconds i.e 100 ms
#define COM_DELAY 100000000 // in nano seconds i.e 100 ms
#define TIME_SYNC_JUMP_THR 500000000
#define MOVING_AVERAGE_ALPHA 0.1
#define MAX_NUMBER_OF_ROBOTS 10
@ -107,8 +107,8 @@ private:
uint16_t size;
uint64_t sent_time;
uint64_t received_time;
MsgData(int mi, uint16_t ni, uint16_t s, uint64_t st, uint64_t rt):
msgid(mi), nid(ni), size(s),sent_time(st), received_time(rt){};
MsgData(int mi, uint16_t ni, uint16_t s, uint64_t st, uint64_t rt)
: msgid(mi), nid(ni), size(s), sent_time(st), received_time(rt){};
MsgData(){};
};
typedef struct MsgData msg_data;

View File

@ -1,62 +1,43 @@
ROS Implemenation of Buzz
ROSBuzz
=========================
What is Buzz?
=============
Buzz is a novel programming language for heterogeneous robots swarms.
Buzz advocates a compositional approach, by offering primitives to define swarm behaviors both in a bottom-up and in a top-down fashion.
Bottom-up primitives include robot-wise commands and manipulation of neighborhood data through mapping/reducing/filtering operations.
Top-down primitives allow for the dynamic management of robot teams, and for sharing information globally across the swarm.
Self-organization results from the fact that the Buzz run-time platform is purely distributed.
The language can be extended to add new primitives (thus supporting heterogeneous robot swarms) and can be laid on top of other frameworks, such as ROS.
More information is available at http://the.swarming.buzz/wiki/doku.php?id=start.
Description:
============
Rosbuzz package is the ROS version of Buzz. The package contains a node called “rosbuzz_node”, which implements buzz virtual machine (BVM) as a node in ROS.
ROSBuzz is a ROS node encompassing Buzz Virtual Machine (BVM) and interfacing with ROS ecosystem for mobile robots. The only node of the package is `rosbuzz_node`. It can be used in simulation-in-the-loop using Gazebo and was tested over many platforms (Clearpath Husky, DJI M100, Intel Aero, 3DR Solos, Pleidis Spiris, etc.). More information about ROSBuzz peripheral nodes is available in [1].
What is Buzz?
=============
Downloading ROS Package
=======================
$ git clone https://github.com/MISTLab/ROSBuzz.git rosbuzz
Buzz is a novel programming language for heterogeneous robots swarms. Buzz advocates a compositional approach, by offering primitives to define swarm behaviors both in a bottom-up and in a top-down fashion. Its official documentation and code are available [Buzz](https://github.com/MISTLab/Buzz).
Requirements
============
* Buzz :
* Buzz:
You can download the development sources through git:
Follow the required steps in [Buzz](https://github.com/MISTLab/ROSBuzz).
$ git clone https://github.com/MISTLab/Buzz.git buzz
* ROS **base** binary distribution (Indigo or higher):
* ROS binary distribution (Indigo or higher) with catkin (could be used with older versions of ROS with catkin but not tested)
Follow the required steps in [ROS Kinetic](https://wiki.ros.org/kinetic/Installation/Ubuntu). Note that the guidance and camera node of DJI for the M100 require to use the Indigo distribution.
* ROS additionnal dependencies:
You need the following package:
* mavros_msgs :
You can install using apt-get:
$ sudo apt-get install ros-<distro>-mavros ros-<distro>-mavros-extras
```
$ sudo apt-get install ros-<distro>-mavros ros-<distro>-mavros-extras
```
Compilation
===========
To compile the ros package, execute the following:
$ cd catkin_ws
$ catkin_make
$ source devel/setup.bash
```
mkdir -p ROS_WS/src
cd ROS_WS/src
git clone https://github.com/MISTLab/ROSBuzz rosbuzz
cd ..
catkin_make
```
Run
===
@ -64,42 +45,50 @@ To run the ROSBuzz package using the launch file, execute the following:
$ roslaunch rosbuzz rosbuzz.launch
Note : Before launching the ROSBuzz node, verify all the parameters in the launch file. A launch file using gdb is available also (rosbuzzd.launch).
Have a look at the launch file to understand what parameters are available to suit your usage. All topics and services names are listed in `launch_config/topics.yaml`. Note : Before launching the ROSBuzz node, verify all the parameters in the launch file. A launch file using gdb is available too (rosbuzzd.launch).
* Buzz scripts: Several behavioral scripts are included in the "buzz_Scripts" folder, such as "graphformGPS.bzz" uses in the ICRA publication below and the "testaloneWP.bzz" to control a single drone with a ".csv" list of waypoints. The script "empty.bzz" is a template script.
* Buzz scripts: Several behavioral scripts are included in the "buzz_Scripts" folder, such as "graphformGPS.bzz" uses in [1] and the "testaloneWP.bzz" to control a single drone with a ".csv" list of waypoints. The script "empty.bzz" is a template script.
Publisher
=========
Publishers
-----------
* Messages from Buzz (BVM):
The package publishes mavros_msgs/Mavlink message "outMavlink".
The node publishes `mavros_msgs/Mavlink` message "outMavlink".
* Command to the flight controller:
The package publishes geometry_msgs/PoseStamped message "setpoint_position/local".
The node publishes `geometry_msgs/PoseStamped message` "setpoint_position/local".
* Other information from the swarw:
The node publishes:
- "bvmstate" (`std_msgs/String`)
- "neighbours_pos" (`rosbuzz_msgs/neigh_pos`)
- "fleet_status" (`mavros_msgs/Mavlink`)
Subscribers
-----------
* Current position of the Robot:
The package subscribes to sensor_msgs/NavSatFix message "global_position/global", to a std_msgs/Float64 message "global_position/rel_alt" and to a geometry_msgs/PoseStamped message "local_position/pose".
* Information from the Robot controller (mavros compliant):
The node subscribes to:
- "global_position/global" (`sensor_msgs/NavSatFix message`)
- "global_position/rel_alt" (`std_msgs/Float64`)
- "local_position/pose" (`geometry_msgs/PoseStamped`)
- "battery" (`sensor_msgs/BatteryState`)
- either "extended_state" (`mavros_msgs/ExtendedState`) or "state" (`mavros_msgs/State`)
* Messages to Buzz (BVM):
The package subscribes to mavros_msgs/Mavlink message with a topic name of "inMavlink".
The node subscribes to `mavros_msgs/Mavlink` incoming message with name "inMavlink".
* Status:
The package subscribes to mavros_msgs/BatteryStatus message "battery" and to either a mavros_msgs/ExtendedState message "extended_state" or a mavros_msgs/State message "state".
Service
Services
-------
* Remote Controller:
The package offers a mavros_msgs/CommandLong service "buzzcmd" to control its state. In the "misc" folder a bash script shows how to control the Buzz states from the command line.
The package offers a service "buzzcmd" (`mavros_msgs/CommandLong`) to control it. In the "misc" folder, a bash script shows how to control the swarm state from the command line.
References
------
* ROS and Buzz : consensus-based behaviors for heterogeneous teams. St-Onge, D., Shankar Varadharajan, V., Li, G., Svogor, I. and Beltrame, G. arXiv : https://arxiv.org/abs/1710.08843
* [1] ROS and Buzz : consensus-based behaviors for heterogeneous teams. St-Onge, D., Shankar Varadharajan, V., Li, G., Svogor, I. and Beltrame, G. arXiv : https://arxiv.org/abs/1710.08843
* Over-The-Air Updates for Robotic Swarms. Submitted to IEEE Software (August 2017). 8pgs. Shankar Varadharajan, V., St-Onge, D., Guß, C. and Beltrame, G.
* [2] Over-The-Air Updates for Robotic Swarms. Submitted to IEEE Software (August 2017). 8pgs. Shankar Varadharajan, V., St-Onge, D., Guß, C. and Beltrame, G.
Visual Studio Code
--------------------

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,7 @@ static buzzvm_t VM = 0;
static char* BO_FNAME = 0;
static uint8_t* BO_BUF = 0;
static buzzdebug_t DBG_INFO = 0;
static uint32_t MAX_MSG_SIZE = 190;//250; // Maximum Msg size for sending update packets
static uint32_t MAX_MSG_SIZE = 190; // 250; // Maximum Msg size for sending update packets
static uint8_t Robot_id = 0;
static std::vector<uint8_t*> IN_MSG;
std::map<int, Pos_struct> users_map;
@ -572,7 +572,8 @@ int get_inmsg_size()
return IN_MSG.size();
}
std::vector<uint8_t*> get_inmsg_vector(){
std::vector<uint8_t*> get_inmsg_vector()
{
return IN_MSG;
}
@ -590,11 +591,12 @@ string get_bvmstate()
---------------------------------------*/
{
std::string uav_state = "Unknown";
if(VM && VM->strings){
if (VM && VM->strings)
{
buzzvm_pushs(VM, buzzvm_string_register(VM, "BVMSTATE", 1));
buzzvm_gload(VM);
buzzobj_t obj = buzzvm_stack_at(VM, 1);
if(obj->o.type == BUZZTYPE_STRING)
if (obj->o.type == BUZZTYPE_STRING)
uav_state = string(obj->s.value.str);
else
uav_state = "Not Available";
@ -603,8 +605,8 @@ string get_bvmstate()
return uav_state;
}
int get_swarmsize() {
int get_swarmsize()
{
return (int)buzzdict_size(VM->swarmmembers) + 1;
}
}

View File

@ -42,11 +42,15 @@ static bool logVoronoi = false;
std::ofstream voronoicsv;
struct Point
{
float x;
float y;
Point(): x( 0.0 ), y( 0.0 ) { }
Point( float x, float y ): x( x ), y( y ) { }
{
float x;
float y;
Point() : x(0.0), y(0.0)
{
}
Point(float x, float y) : x(x), y(y)
{
}
};
string WPlistname = "";
@ -54,7 +58,7 @@ std::map<int, buzz_utility::RB_struct> targets_map;
std::map<int, buzz_utility::RB_struct> wplist_map;
std::map<int, buzz_utility::Pos_struct> neighbors_map;
std::map<int, buzz_utility::neighbors_status> neighbors_status_map;
std::map<int, std::map<int,int>> grid;
std::map<int, std::map<int, int>> grid;
/****************************************/
/****************************************/
@ -123,7 +127,8 @@ void setVorlog(string path)
/ set the absolute path for a csv list of waypoints
----------------------------------------------------------- */
{
voronoicsv.open(path + "/log/voronoi_"+std::to_string(buzz_utility::get_robotid())+".csv", std::ios_base::trunc | std::ios_base::out);
voronoicsv.open(path + "/log/voronoi_" + std::to_string(buzz_utility::get_robotid()) + ".csv",
std::ios_base::trunc | std::ios_base::out);
logVoronoi = true;
}
@ -152,15 +157,18 @@ void rb_from_gps(double nei[], double out[], double cur[])
out[2] = 0.0;
}
void gps_from_vec(double vec[], double gps[]) {
void gps_from_vec(double vec[], double gps[])
{
double Vrange = sqrt(vec[0] * vec[0] + vec[1] * vec[1]);
double Vbearing = constrainAngle(atan2(vec[1], vec[0]));
double latR = cur_pos[0]*M_PI/180.0;
double lonR = cur_pos[1]*M_PI/180.0;
double target_lat = asin(sin(latR) * cos(Vrange/EARTH_RADIUS) + cos(latR) * sin(Vrange/EARTH_RADIUS) * cos(Vbearing));
double target_lon = lonR + atan2(sin(Vbearing) * sin(Vrange/EARTH_RADIUS) * cos(latR), cos(Vrange/EARTH_RADIUS) - sin(latR) * sin(target_lat));
gps[0] = target_lat*180.0/M_PI;
gps[1] = target_lon*180.0/M_PI;
double latR = cur_pos[0] * M_PI / 180.0;
double lonR = cur_pos[1] * M_PI / 180.0;
double target_lat =
asin(sin(latR) * cos(Vrange / EARTH_RADIUS) + cos(latR) * sin(Vrange / EARTH_RADIUS) * cos(Vbearing));
double target_lon = lonR + atan2(sin(Vbearing) * sin(Vrange / EARTH_RADIUS) * cos(latR),
cos(Vrange / EARTH_RADIUS) - sin(latR) * sin(target_lat));
gps[0] = target_lat * 180.0 / M_PI;
gps[1] = target_lon * 180.0 / M_PI;
gps[2] = cur_pos[2];
}
@ -215,7 +223,7 @@ void parse_gpslist()
fin.close();
}
void check_targets_sim(double lat, double lon, double *res)
void check_targets_sim(double lat, double lon, double* res)
/*
/ check if a listed target is close
----------------------------------------------------------- */
@ -225,16 +233,19 @@ void check_targets_sim(double lat, double lon, double *res)
for (it = wplist_map.begin(); it != wplist_map.end(); ++it)
{
double rb[3];
double ref[2]={lat, lon};
double tar[2]={it->second.latitude, it->second.longitude};
double ref[2] = { lat, lon };
double tar[2] = { it->second.latitude, it->second.longitude };
rb_from_gps(tar, rb, ref);
if(rb[0] < visibility_radius && (buzz_utility::get_bvmstate()=="WAYPOINT" && it->second.r==0)){
if (rb[0] < visibility_radius && (buzz_utility::get_bvmstate() == "WAYPOINT" && it->second.r == 0))
{
ROS_WARN("FOUND A TARGET IN WAYPOINT!!! [%i]", it->first);
res[0] = it->first;
res[1] = it->second.latitude;
res[2] = it->second.longitude;
res[3] = it->second.altitude;
} else if(rb[0] < visibility_radius && (buzz_utility::get_bvmstate()=="DEPLOY" && it->second.r==1)){
}
else if (rb[0] < visibility_radius && (buzz_utility::get_bvmstate() == "DEPLOY" && it->second.r == 1))
{
ROS_WARN("FOUND A TARGET IN WAYPOINT!!! [%i]", it->first);
res[0] = it->first;
res[1] = it->second.latitude;
@ -253,21 +264,23 @@ int buzz_exportmap(buzzvm_t vm)
buzzvm_lnum_assert(vm, 1);
// Get the parameter
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); // dictionary
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); // dictionary
buzzobj_t t = buzzvm_stack_at(vm, 1);
for(int32_t i = 1; i <= buzzdict_size(t->t.value); ++i) {
for (int32_t i = 1; i <= buzzdict_size(t->t.value); ++i)
{
buzzvm_dup(vm);
buzzvm_pushi(vm, i);
buzzvm_tget(vm);
std::map<int, int> row;
for(int32_t j = 1; j <= buzzdict_size(buzzvm_stack_at(vm, 1)->t.value); ++j) {
for (int32_t j = 1; j <= buzzdict_size(buzzvm_stack_at(vm, 1)->t.value); ++j)
{
buzzvm_dup(vm);
buzzvm_pushi(vm, j);
buzzvm_tget(vm);
row.insert(std::pair<int,int>(j, 100.0 - round(buzzvm_stack_at(vm, 1)->f.value*100.0)));
row.insert(std::pair<int, int>(j, 100.0 - round(buzzvm_stack_at(vm, 1)->f.value * 100.0)));
buzzvm_pop(vm);
}
grid.insert(std::pair<int,std::map<int, int>>(i,row));
grid.insert(std::pair<int, std::map<int, int>>(i, row));
buzzvm_pop(vm);
}
// DEBUG
@ -277,252 +290,279 @@ int buzz_exportmap(buzzvm_t vm)
/*
* Geofence(): test for a point in a polygon
* TAKEN from https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
* TAKEN from https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
*/
// Given three colinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
bool onSegment(Point p, Point q, Point r)
{
if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) &&
q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y))
return true;
return false;
}
// To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
int orientation(Point p, Point q, Point r)
{
int val =round((q.y - p.y) * (r.x - q.x)*100 -
(q.x - p.x) * (r.y - q.y)*100);
if (val == 0) return 0; // colinear
return (val > 0)? 1: 2; // clock or counterclock wise
}
// The function that returns true if line segment 'p1q1'
// and 'p2q2' intersect.
bool doIntersect(Point p1, Point q1, Point p2, Point q2)
{
// Find the four orientations needed for general and
// special cases
int o1 = orientation(p1, q1, p2);
int o2 = orientation(p1, q1, q2);
int o3 = orientation(p2, q2, p1);
int o4 = orientation(p2, q2, q1);
//ROS_WARN("(%f,%f)->(%f,%f), 1:%d,2:%d,3:%d,4:%d",p1.x,p1.y,q1.x,q1.y,o1,o2,o3,o4);
// General case
if (o1 != o2 && o3 != o4)
return true;
// Special Cases
// p1, q1 and p2 are colinear and p2 lies on segment p1q1
if (o1 == 0 && onSegment(p1, p2, q1)) return true;
// p1, q1 and p2 are colinear and q2 lies on segment p1q1
if (o2 == 0 && onSegment(p1, q2, q1)) return true;
// p2, q2 and p1 are colinear and p1 lies on segment p2q2
if (o3 == 0 && onSegment(p2, p1, q2)) return true;
// p2, q2 and q1 are colinear and q1 lies on segment p2q2
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
return false; // Doesn't fall in any of the above cases
}
float clockwise_angle_of( const Point& p )
// Given three colinear points p, q, r, the function checks if
// point q lies on line segment 'pr'
bool onSegment(Point p, Point q, Point r)
{
return atan2(p.y,p.x);
if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) && q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y))
return true;
return false;
}
bool clockwise_compare_points( const Point& a, const Point& b )
// To find orientation of ordered triplet (p, q, r).
// The function returns following values
// 0 --> p, q and r are colinear
// 1 --> Clockwise
// 2 --> Counterclockwise
int orientation(Point p, Point q, Point r)
{
return clockwise_angle_of( a ) < clockwise_angle_of( b );
int val = round((q.y - p.y) * (r.x - q.x) * 100 - (q.x - p.x) * (r.y - q.y) * 100);
if (val == 0)
return 0; // colinear
return (val > 0) ? 1 : 2; // clock or counterclock wise
}
// The function that returns true if line segment 'p1q1'
// and 'p2q2' intersect.
bool doIntersect(Point p1, Point q1, Point p2, Point q2)
{
// Find the four orientations needed for general and
// special cases
int o1 = orientation(p1, q1, p2);
int o2 = orientation(p1, q1, q2);
int o3 = orientation(p2, q2, p1);
int o4 = orientation(p2, q2, q1);
// ROS_WARN("(%f,%f)->(%f,%f), 1:%d,2:%d,3:%d,4:%d",p1.x,p1.y,q1.x,q1.y,o1,o2,o3,o4);
// General case
if (o1 != o2 && o3 != o4)
return true;
// Special Cases
// p1, q1 and p2 are colinear and p2 lies on segment p1q1
if (o1 == 0 && onSegment(p1, p2, q1))
return true;
// p1, q1 and p2 are colinear and q2 lies on segment p1q1
if (o2 == 0 && onSegment(p1, q2, q1))
return true;
// p2, q2 and p1 are colinear and p1 lies on segment p2q2
if (o3 == 0 && onSegment(p2, p1, q2))
return true;
// p2, q2 and q1 are colinear and q1 lies on segment p2q2
if (o4 == 0 && onSegment(p2, q1, q2))
return true;
return false; // Doesn't fall in any of the above cases
}
void sortclose_polygon(vector <Point> *P){
std::sort( P->begin(), P->end(), clockwise_compare_points );
float clockwise_angle_of(const Point& p)
{
return atan2(p.y, p.x);
}
bool clockwise_compare_points(const Point& a, const Point& b)
{
return clockwise_angle_of(a) < clockwise_angle_of(b);
}
void sortclose_polygon(vector<Point>* P)
{
std::sort(P->begin(), P->end(), clockwise_compare_points);
P->push_back((*P)[0]);
}
float pol_area(vector <Point> vert) {
float pol_area(vector<Point> vert)
{
float a = 0.0;
//ROS_INFO("Polygone %d edges area.",vert.size());
vector <Point>::iterator it;
vector <Point>::iterator next;
for (it = vert.begin(); it != vert.end()-1; ++it){
next = it+1;
// ROS_INFO("Polygone %d edges area.",vert.size());
vector<Point>::iterator it;
vector<Point>::iterator next;
for (it = vert.begin(); it != vert.end() - 1; ++it)
{
next = it + 1;
a += it->x * next->y - next->x * it->y;
}
a *= 0.5;
//ROS_INFO("Polygon area: %f",a);
// ROS_INFO("Polygon area: %f",a);
return a;
}
double* polygone_center(vector <Point> vert, double *c) {
double* polygone_center(vector<Point> vert, double* c)
{
float A = pol_area(vert);
int i1 = 1;
vector <Point>::iterator it;
vector <Point>::iterator next;
for (it = vert.begin(); it != vert.end()-1; ++it){
next = it+1;
float t = it->x*next->y - next->x*it->y;
c[0] += (it->x+next->x) * t;
c[1] += (it->y+next->y) * t;
vector<Point>::iterator it;
vector<Point>::iterator next;
for (it = vert.begin(); it != vert.end() - 1; ++it)
{
next = it + 1;
float t = it->x * next->y - next->x * it->y;
c[0] += (it->x + next->x) * t;
c[1] += (it->y + next->y) * t;
}
c[0] = c[0] / (6.0 * A);
c[1] = c[1] / (6.0 * A);
return c;
}
double numerator ( Point A, Point C, Point E, Point F ) { return (A.y - C.y) * (F.x - E.x) - (A.x - C.x) * (F.y - E.y); }
double denominator( Point A, Point B, Point C, Point D ) { return (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x); }
double numerator(Point A, Point C, Point E, Point F)
{
return (A.y - C.y) * (F.x - E.x) - (A.x - C.x) * (F.y - E.y);
}
double denominator(Point A, Point B, Point C, Point D)
{
return (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
}
void getintersection(Point S, Point D, std::vector <Point> Poly, Point *I) {
//printf("Points for intersection 1(%f,%f->%f,%f) and 2(%f,%f->%f,%f)\n",q1.x,q1.y,p1.x,p1.y,q2.x,q2.y,p2.x,p2.y);
void getintersection(Point S, Point D, std::vector<Point> Poly, Point* I)
{
// printf("Points for intersection 1(%f,%f->%f,%f) and 2(%f,%f->%f,%f)\n",q1.x,q1.y,p1.x,p1.y,q2.x,q2.y,p2.x,p2.y);
bool parallel = false;
bool collinear = false;
std::vector <Point>::iterator itc;
std::vector <Point>::iterator next;
for (itc = Poly.begin(); itc != Poly.end()-1; ++itc) {
next = itc+1;
if (doIntersect((*itc), (*next), S, D))
std::vector<Point>::iterator itc;
std::vector<Point>::iterator next;
for (itc = Poly.begin(); itc != Poly.end() - 1; ++itc)
{
next = itc + 1;
if (doIntersect((*itc), (*next), S, D))
{
// Uses the determinant of the two lines. For more information, refer to one of the following:
// https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Given_two_points_on_each_line
// http://www.faqs.org/faqs/graphics/algorithms-faq/ (Subject 1.03)
double d = denominator( S, D, (*itc), (*next) );
if (std::abs( d ) < 0.000000001)
double d = denominator(S, D, (*itc), (*next));
if (std::abs(d) < 0.000000001)
{
parallel = true;
collinear = abs(numerator( S, D, (*itc), (*next) )) < 0.000000001;
parallel = true;
collinear = abs(numerator(S, D, (*itc), (*next))) < 0.000000001;
return;
}
double r = numerator( S, (*itc), (*itc), (*next) ) / d;
double s = numerator( S, (*itc), S, D ) / d;
//ROS_INFO("-- (%f,%f)",S.x + r * (D.x - S.x), S.y + r * (D.y - S.y));
(*I)=Point(S.x + r * (D.x - S.x), S.y + r * (D.y - S.y));
double r = numerator(S, (*itc), (*itc), (*next)) / d;
double s = numerator(S, (*itc), S, D) / d;
// ROS_INFO("-- (%f,%f)",S.x + r * (D.x - S.x), S.y + r * (D.y - S.y));
(*I) = Point(S.x + r * (D.x - S.x), S.y + r * (D.y - S.y));
}
}
if(parallel || collinear)
ROS_WARN("Lines are Collinear (%d) or Parallels (%d)",collinear,parallel);
if (parallel || collinear)
ROS_WARN("Lines are Collinear (%d) or Parallels (%d)", collinear, parallel);
}
bool isSiteout(Point S, std::vector <Point> Poly) {
bool isSiteout(Point S, std::vector<Point> Poly)
{
bool onedge = false;
// Create a point for line segment from p to infinite
Point extreme = {10000, S.y};
// Create a point for line segment from p to infinite
Point extreme = { 10000, S.y };
// Count intersections of the above line with sides of polygon
int count = 0;
std::vector <Point>::iterator itc;
std::vector <Point>::iterator next;
for (itc = Poly.begin(); itc != Poly.end()-1; ++itc) {
next = itc+1;
// Count intersections of the above line with sides of polygon
int count = 0;
std::vector<Point>::iterator itc;
std::vector<Point>::iterator next;
for (itc = Poly.begin(); itc != Poly.end() - 1; ++itc)
{
next = itc + 1;
// Check if the line segment from 'p' to 'extreme' intersects
// with the line segment from 'polygon[i]' to 'polygon[next]'
if (doIntersect((*itc), (*next), S, extreme))
{
// If the point 'p' is colinear with line segment 'i-next',
// then check if it lies on segment. If it lies, return true,
// otherwise false
if (orientation((*itc), S, (*next)) == 0) {
onedge = onSegment((*itc), S, (*next));
if(onedge)
break;
}
count++;
// Check if the line segment from 'p' to 'extreme' intersects
// with the line segment from 'polygon[i]' to 'polygon[next]'
if (doIntersect((*itc), (*next), S, extreme))
{
// If the point 'p' is colinear with line segment 'i-next',
// then check if it lies on segment. If it lies, return true,
// otherwise false
if (orientation((*itc), S, (*next)) == 0)
{
onedge = onSegment((*itc), S, (*next));
if (onedge)
break;
}
count++;
}
}
return ((count%2 == 0) && !onedge);
return ((count % 2 == 0) && !onedge);
}
int buzzuav_geofence(buzzvm_t vm)
{
Point P;
buzzvm_lnum_assert(vm, 1);
// Get the parameter
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); // dictionary
buzzobj_t t = buzzvm_stack_at(vm, 1);
Point P;
buzzvm_lnum_assert(vm, 1);
// Get the parameter
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); // dictionary
buzzobj_t t = buzzvm_stack_at(vm, 1);
if(buzzdict_size(t->t.value) < 5) {
ROS_ERROR("Wrong Geofence input size (%i).", buzzdict_size(t->t.value));
return buzzvm_ret0(vm);
if (buzzdict_size(t->t.value) < 5)
{
ROS_ERROR("Wrong Geofence input size (%i).", buzzdict_size(t->t.value));
return buzzvm_ret0(vm);
}
std::vector<Point> polygon_bound;
for (int32_t i = 0; i < buzzdict_size(t->t.value); ++i)
{
Point tmp;
buzzvm_dup(vm);
buzzvm_pushi(vm, i);
buzzvm_tget(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "x", 1));
buzzvm_tget(vm);
if (i == 0)
{
P.x = buzzvm_stack_at(vm, 1)->f.value;
// printf("px=%f\n",P.x);
}
std::vector <Point> polygon_bound;
for(int32_t i = 0; i < buzzdict_size(t->t.value); ++i) {
Point tmp;
buzzvm_dup(vm);
buzzvm_pushi(vm, i);
buzzvm_tget(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "x", 1));
buzzvm_tget(vm);
if(i==0){
P.x = buzzvm_stack_at(vm, 1)->f.value;
//printf("px=%f\n",P.x);
}else{
tmp.x = buzzvm_stack_at(vm, 1)->f.value;
//printf("c%dx=%f\n",i,tmp.x);
}
buzzvm_pop(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "y", 1));
buzzvm_tget(vm);
//ROS_INFO("[%i]---y-->%i",buzz_utility::get_robotid(), tmp);
if(i==0){
P.y = buzzvm_stack_at(vm, 1)->f.value;
//printf("py=%f\n",P.y);
}else{
tmp.y = buzzvm_stack_at(vm, 1)->f.value;
//printf("c%dy=%f\n",i,tmp.y);
}
buzzvm_pop(vm);
if(i!=0)
polygon_bound.push_back(tmp);
buzzvm_pop(vm);
else
{
tmp.x = buzzvm_stack_at(vm, 1)->f.value;
// printf("c%dx=%f\n",i,tmp.x);
}
sortclose_polygon(&polygon_bound);
// Check if we are in the zone
if(isSiteout(P, polygon_bound)){
Point Intersection;
getintersection(Point(0.0, 0.0) , P, polygon_bound, &Intersection);
double gps[3];
double d[2]={Intersection.x,Intersection.y};
gps_from_vec(d, gps);
set_gpsgoal(gps);
ROS_WARN("Geofencing trigered, not going any further (%f,%f)!",d[0],d[1]);
buzzvm_pop(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "y", 1));
buzzvm_tget(vm);
// ROS_INFO("[%i]---y-->%i",buzz_utility::get_robotid(), tmp);
if (i == 0)
{
P.y = buzzvm_stack_at(vm, 1)->f.value;
// printf("py=%f\n",P.y);
}
else
{
tmp.y = buzzvm_stack_at(vm, 1)->f.value;
// printf("c%dy=%f\n",i,tmp.y);
}
buzzvm_pop(vm);
if (i != 0)
polygon_bound.push_back(tmp);
buzzvm_pop(vm);
}
sortclose_polygon(&polygon_bound);
// Check if we are in the zone
if (isSiteout(P, polygon_bound))
{
Point Intersection;
getintersection(Point(0.0, 0.0), P, polygon_bound, &Intersection);
double gps[3];
double d[2] = { Intersection.x, Intersection.y };
gps_from_vec(d, gps);
set_gpsgoal(gps);
ROS_WARN("Geofencing trigered, not going any further (%f,%f)!", d[0], d[1]);
}
return buzzvm_ret0(vm);
}
int voronoi_center(buzzvm_t vm) {
int voronoi_center(buzzvm_t vm)
{
float dist_max = 300;
buzzvm_lnum_assert(vm, 1);
buzzvm_lnum_assert(vm, 1);
// Get the parameter
buzzvm_lload(vm, 1);
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); // dictionary
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE); // dictionary
buzzobj_t t = buzzvm_stack_at(vm, 1);
buzzvm_dup(vm);
@ -531,161 +571,191 @@ int voronoi_center(buzzvm_t vm) {
int Poly_vert = buzzvm_stack_at(vm, 1)->i.value;
buzzvm_pop(vm);
std::vector <Point> polygon_bound;
for(int32_t i = 0; i < Poly_vert; ++i) {
std::vector<Point> polygon_bound;
for (int32_t i = 0; i < Poly_vert; ++i)
{
buzzvm_dup(vm);
buzzvm_pushi(vm, i);
buzzvm_tget(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "x", 1));
buzzvm_tget(vm);
//ROS_INFO("---x-->%f",buzzvm_stack_at(vm, 1)->f.value);
// ROS_INFO("---x-->%f",buzzvm_stack_at(vm, 1)->f.value);
float tmpx = buzzvm_stack_at(vm, 1)->f.value;
buzzvm_pop(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "y", 1));
buzzvm_tget(vm);
//ROS_INFO("---y-->%f",buzzvm_stack_at(vm, 1)->f.value);
// ROS_INFO("---y-->%f",buzzvm_stack_at(vm, 1)->f.value);
float tmpy = buzzvm_stack_at(vm, 1)->f.value;
buzzvm_pop(vm);
polygon_bound.push_back(Point(tmpx, tmpy));
//ROS_INFO("[%i] Polygon vertex: %f, %f", buzz_utility::get_robotid(),tmpx,tmpy);
// ROS_INFO("[%i] Polygon vertex: %f, %f", buzz_utility::get_robotid(),tmpx,tmpy);
buzzvm_pop(vm);
}
sortclose_polygon(&polygon_bound);
int count = buzzdict_size(t->t.value)-(Poly_vert+1);
ROS_WARN("NP: %d, Sites: %d", Poly_vert, count);
float *xValues = new float[count];
float *yValues = new float[count];
for(int32_t i = 0; i < count; ++i) {
int index = i + Poly_vert;
buzzvm_dup(vm);
buzzvm_pushi(vm, index);
buzzvm_tget(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "x", 1));
buzzvm_tget(vm);
//ROS_INFO("---x-->%f",buzzvm_stack_at(vm, 1)->f.value);
xValues[i] = buzzvm_stack_at(vm, 1)->f.value;
buzzvm_pop(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "y", 1));
buzzvm_tget(vm);
//ROS_INFO("---y-->%f",buzzvm_stack_at(vm, 1)->f.value);
yValues[i] = buzzvm_stack_at(vm, 1)->f.value;
buzzvm_pop(vm);
buzzvm_pop(vm);
}
int count = buzzdict_size(t->t.value) - (Poly_vert + 1);
// Check if we are in the zone
if(isSiteout(Point(0,0), polygon_bound) || count < 3) {
//ROS_WARN("Not in the Zone!!!");
if (isSiteout(Point(0, 0), polygon_bound) || count < 3)
{
// ROS_WARN("Not in the Zone!!!");
double goal_tmp[2];
do{
goal_tmp[0] = polygon_bound[0].x + (rand()%100)/100.0*(polygon_bound[2].x- polygon_bound[0].x);
goal_tmp[1] = polygon_bound[0].y + (rand()%100)/100.0*(polygon_bound[2].y- polygon_bound[0].y);
//ROS_WARN(" in the Zone (%f,%f)!",goal_tmp[0],goal_tmp[1]);
} while(isSiteout(Point(goal_tmp[0],goal_tmp[1]), polygon_bound));
ROS_WARN("Sending at a random location in the Zone (%f,%f)!",goal_tmp[0],goal_tmp[1]);
do
{
goal_tmp[0] = polygon_bound[0].x + (rand() % 100) / 100.0 * (polygon_bound[2].x - polygon_bound[0].x);
goal_tmp[1] = polygon_bound[0].y + (rand() % 100) / 100.0 * (polygon_bound[2].y - polygon_bound[0].y);
// ROS_WARN(" in the Zone (%f,%f)!",goal_tmp[0],goal_tmp[1]);
} while (isSiteout(Point(goal_tmp[0], goal_tmp[1]), polygon_bound));
ROS_WARN("Sending at a random location in the Zone (%f,%f)!", goal_tmp[0], goal_tmp[1]);
double gps[3];
gps_from_vec(goal_tmp, gps);
set_gpsgoal(gps);
return buzzvm_ret0(vm);
}
VoronoiDiagramGenerator vdg;
ROS_WARN("[%i] Voronoi Bounded tessellation starting with %i sites...", buzz_utility::get_robotid(),count);
vdg.generateVoronoi(xValues, yValues, count, -dist_max, dist_max, -dist_max, dist_max, 3.0);
if(logVoronoi) voronoicsv << ros::Time::now().toNSec() << ",";
vdg.resetIterator();
//ROS_WARN("[%i] Voronoi Bounded tessellation done!", buzz_utility::get_robotid());
std::vector <Point>::iterator itc, next;
for (itc = polygon_bound.begin(); itc != polygon_bound.end()-1; ++itc) {
next = itc+1;
if(logVoronoi) voronoicsv << itc->x << "," << itc->y << "," << next->x << "," << next->y << "," << 0 << "," << 0 << ",";
ROS_WARN("NP: %d, Sites: %d", Poly_vert, count);
float* xValues = new float[count];
float* yValues = new float[count];
for (int32_t i = 0; i < count; ++i)
{
int index = i + Poly_vert;
buzzvm_dup(vm);
buzzvm_pushi(vm, index);
buzzvm_tget(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "x", 1));
buzzvm_tget(vm);
// ROS_INFO("---x-->%f",buzzvm_stack_at(vm, 1)->f.value);
xValues[i] = buzzvm_stack_at(vm, 1)->f.value;
buzzvm_pop(vm);
buzzvm_dup(vm);
buzzvm_pushs(vm, buzzvm_string_register(vm, "y", 1));
buzzvm_tget(vm);
// ROS_INFO("---y-->%f",buzzvm_stack_at(vm, 1)->f.value);
yValues[i] = buzzvm_stack_at(vm, 1)->f.value;
buzzvm_pop(vm);
buzzvm_pop(vm);
}
float x1,y1,x2,y2;
VoronoiDiagramGenerator vdg;
ROS_WARN("[%i] Voronoi Bounded tessellation starting with %i sites...", buzz_utility::get_robotid(), count);
vdg.generateVoronoi(xValues, yValues, count, -dist_max, dist_max, -dist_max, dist_max, 3.0);
if (logVoronoi)
voronoicsv << ros::Time::now().toNSec() << ",";
vdg.resetIterator();
// ROS_WARN("[%i] Voronoi Bounded tessellation done!", buzz_utility::get_robotid());
std::vector<Point>::iterator itc, next;
for (itc = polygon_bound.begin(); itc != polygon_bound.end() - 1; ++itc)
{
next = itc + 1;
if (logVoronoi)
voronoicsv << itc->x << "," << itc->y << "," << next->x << "," << next->y << "," << 0 << "," << 0 << ",";
}
float x1, y1, x2, y2;
int s[2];
vector <Point> cell_vert;
vector<Point> cell_vert;
Point Intersection;
int i=0;
while(vdg.getNext(x1,y1,x2,y2,s))
{
//ROS_INFO("GOT Line (%f,%f)->(%f,%f) between sites %d,%d",x1,y1,x2,y2,s[0],s[1]);
if(sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1))<0.1)
int i = 0;
while (vdg.getNext(x1, y1, x2, y2, s))
{
// ROS_INFO("GOT Line (%f,%f)->(%f,%f) between sites %d,%d",x1,y1,x2,y2,s[0],s[1]);
if (sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) < 0.1)
continue;
bool isout1 = isSiteout(Point(x1,y1), polygon_bound);
bool isout2 = isSiteout(Point(x2,y2), polygon_bound);
if(isout1 && isout2){
//ROS_INFO("Line out of area!");
bool isout1 = isSiteout(Point(x1, y1), polygon_bound);
bool isout2 = isSiteout(Point(x2, y2), polygon_bound);
if (isout1 && isout2)
{
// ROS_INFO("Line out of area!");
continue;
}else if(isout1) {
getintersection(Point(x2,y2), Point(x1,y1), polygon_bound, &Intersection);
}
else if (isout1)
{
getintersection(Point(x2, y2), Point(x1, y1), polygon_bound, &Intersection);
x1 = Intersection.x;
y1 = Intersection.y;
//ROS_INFO("Site out 1 -> (%f,%f)", x1, y1);
}else if(isout2) {
getintersection(Point(x1,y1), Point(x2,y2), polygon_bound, &Intersection);
// ROS_INFO("Site out 1 -> (%f,%f)", x1, y1);
}
else if (isout2)
{
getintersection(Point(x1, y1), Point(x2, y2), polygon_bound, &Intersection);
x2 = Intersection.x;
y2 = Intersection.y;
//ROS_INFO("Site out 2 -> (%f,%f)", x2, y2);
// ROS_INFO("Site out 2 -> (%f,%f)", x2, y2);
}
if(logVoronoi) voronoicsv << x1 << "," << y1 << "," << x2 << "," << y2 << "," << s[0] << "," << s[1] << ",";
if (logVoronoi)
voronoicsv << x1 << "," << y1 << "," << x2 << "," << y2 << "," << s[0] << "," << s[1] << ",";
i++;
if((s[0]==0 || s[1]==0)) {
if(cell_vert.empty()){
cell_vert.push_back(Point(x1,y1));
cell_vert.push_back(Point(x2,y2));
} else {
if ((s[0] == 0 || s[1] == 0))
{
if (cell_vert.empty())
{
cell_vert.push_back(Point(x1, y1));
cell_vert.push_back(Point(x2, y2));
}
else
{
bool alreadyin = false;
vector <Point>::iterator itc;
for (itc = cell_vert.begin(); itc != cell_vert.end(); ++itc) {
vector<Point>::iterator itc;
for (itc = cell_vert.begin(); itc != cell_vert.end(); ++itc)
{
double dist = sqrt((itc->x - x1) * (itc->x - x1) + (itc->y - y1) * (itc->y - y1));
if(dist < 0.1) {
if (dist < 0.1)
{
alreadyin = true;
break;
}
}
if(!alreadyin)
if (!alreadyin)
cell_vert.push_back(Point(x1, y1));
alreadyin = false;
for (itc = cell_vert.begin(); itc != cell_vert.end(); ++itc) {
for (itc = cell_vert.begin(); itc != cell_vert.end(); ++itc)
{
double dist = sqrt((itc->x - x2) * (itc->x - x2) + (itc->y - y2) * (itc->y - y2));
if(dist < 0.1) {
if (dist < 0.1)
{
alreadyin = true;
break;
}
}
if(!alreadyin)
if (!alreadyin)
cell_vert.push_back(Point(x2, y2));
}
}
}
if(cell_vert.size()<3){
ROS_WARN("[%i] Voronoi Bounded tessellation failed (%d)!", buzz_utility::get_robotid(),cell_vert.size());
}
if (cell_vert.size() < 3)
{
ROS_WARN("[%i] Voronoi Bounded tessellation failed (%d)!", buzz_utility::get_robotid(), cell_vert.size());
delete xValues;
delete yValues;
return buzzvm_ret0(vm);
}
std::sort( cell_vert.begin(), cell_vert.end(), clockwise_compare_points );
std::sort(cell_vert.begin(), cell_vert.end(), clockwise_compare_points);
cell_vert.push_back(cell_vert[0]);
double center_dist[2] = {0.0, 0.0};
double center_dist[2] = { 0.0, 0.0 };
polygone_center(cell_vert, center_dist);
if(logVoronoi) voronoicsv << center_dist[0] << "," << center_dist[1] << std::endl;
center_dist[0]/=2;
center_dist[1]/=2;
if (logVoronoi)
voronoicsv << center_dist[0] << "," << center_dist[1] << std::endl;
center_dist[0] /= 2;
center_dist[1] /= 2;
double gps[3];
gps_from_vec(center_dist, gps);
//ROS_INFO("[%i] Voronoi cell center: %f, %f, %f, %f", buzz_utility::get_robotid(), center_dist[0], center_dist[1], gps[0], gps[1]);
// ROS_INFO("[%i] Voronoi cell center: %f, %f, %f, %f", buzz_utility::get_robotid(), center_dist[0], center_dist[1],
// gps[0], gps[1]);
set_gpsgoal(gps);
delete xValues;
delete yValues;
return buzzvm_ret0(vm);
}
@ -769,7 +839,8 @@ int buzzuav_addNeiStatus(buzzvm_t vm)
buzzvm_lload(vm, 1); // state table
buzzvm_type_assert(vm, 1, BUZZTYPE_TABLE);
buzzobj_t t = buzzvm_stack_at(vm, 1);
if(buzzdict_size(t->t.value) != 5) {
if (buzzdict_size(t->t.value) != 5)
{
ROS_ERROR("Wrong neighbor status size.");
return buzzvm_ret0(vm);
}
@ -800,7 +871,7 @@ int buzzuav_addNeiStatus(buzzvm_t vm)
buzzvm_tget(vm);
newRS.flight_status = buzzvm_stack_at(vm, 1)->i.value;
buzzvm_pop(vm);
map<int, buzz_utility::neighbors_status>::iterator it = neighbors_status_map.find(id);
if (it != neighbors_status_map.end())
neighbors_status_map.erase(it);
@ -911,12 +982,17 @@ void set_gpsgoal(double goal[3])
{
double rb[3];
rb_from_gps(goal, rb, cur_pos);
if (fabs(rb[0]) < 250.0) {
goto_gpsgoal[0] = goal[0];goto_gpsgoal[1] = goal[1];goto_gpsgoal[2] = goal[2];
ROS_INFO("[%i] Set GPS GOAL TO ---- %f %f %f (%f %f, %f %f)", buzz_utility::get_robotid(), goal[0], goal[1], goal[2], cur_pos[0], cur_pos[1], rb[0], rb[1]);
} else
ROS_WARN("[%i] GPS GOAL TOO FAR !!-- %f %f %f (%f %f, %f %f)", buzz_utility::get_robotid(), goal[0], goal[1], goal[2], cur_pos[0], cur_pos[1], rb[0], rb[1]);
if (fabs(rb[0]) < 250.0)
{
goto_gpsgoal[0] = goal[0];
goto_gpsgoal[1] = goal[1];
goto_gpsgoal[2] = goal[2];
ROS_INFO("[%i] Set GPS GOAL TO ---- %f %f %f (%f %f, %f %f)", buzz_utility::get_robotid(), goal[0], goal[1],
goal[2], cur_pos[0], cur_pos[1], rb[0], rb[1]);
}
else
ROS_WARN("[%i] GPS GOAL TOO FAR !!-- %f %f %f (%f %f, %f %f)", buzz_utility::get_robotid(), goal[0], goal[1],
goal[2], cur_pos[0], cur_pos[1], rb[0], rb[1]);
}
int buzzuav_arm(buzzvm_t vm)
@ -987,7 +1063,7 @@ double* getgoto()
return goto_pos;
}
std::map<int, std::map<int,int>> getgrid()
std::map<int, std::map<int, int>> getgrid()
/*
/ return the grid
/-------------------------------------------------------------*/
@ -1199,7 +1275,8 @@ void update_neighbors(buzzvm_t vm)
}
// Clear neighbours pos
void clear_neighbours_pos(){
void clear_neighbours_pos()
{
neighbors_map.clear();
}

View File

@ -12,8 +12,8 @@ namespace rosbuzz_node
{
const string roscontroller::CAPTURE_SRV_DEFAULT_NAME = "/image_sender/capture_image";
roscontroller::roscontroller(ros::NodeHandle& n_c, ros::NodeHandle& n_c_priv):
logical_clock(ros::Time()), previous_step_time(ros::Time())
roscontroller::roscontroller(ros::NodeHandle& n_c, ros::NodeHandle& n_c_priv)
: logical_clock(ros::Time()), previous_step_time(ros::Time())
/*
/ roscontroller class Constructor
---------------*/
@ -26,7 +26,7 @@ logical_clock(ros::Time()), previous_step_time(ros::Time())
cur_pos.longitude = 0;
cur_pos.latitude = 0;
cur_pos.altitude = 0;
// Obtain parameters from ros parameter server
Rosparameters_get(n_c_priv);
// Initialize publishers, subscribers and client
@ -35,9 +35,9 @@ logical_clock(ros::Time()), previous_step_time(ros::Time())
std::string fname = Compile_bzz(bzzfile_name);
bcfname = fname + ".bo";
dbgfname = fname + ".bdb";
buzz_update::set_bzz_file(bzzfile_name.c_str(),debug);
buzz_update::set_bzz_file(bzzfile_name.c_str(), debug);
// Initialize variables
if(setmode)
if (setmode)
SetMode("LOITER", 0);
goto_pos = buzzuav_closures::getgoto();
@ -67,7 +67,7 @@ logical_clock(ros::Time()), previous_step_time(ros::Time())
logical_clock.fromSec(0);
logical_time_rate = 0;
time_sync_jumped = false;
out_msg_time=0;
out_msg_time = 0;
// Create log dir and open log file
initcsvlog();
buzzuav_closures::setWPlist(WPfile);
@ -126,7 +126,7 @@ void roscontroller::RosControllerRun()
// set ROS loop rate
ros::Rate loop_rate(BUZZRATE);
// check for BVMSTATE variable
if(buzz_utility::get_bvmstate()=="Not Available")
if (buzz_utility::get_bvmstate() == "Not Available")
ROS_ERROR("BVMSTATE undeclared in .bzz file, please set BVMSTATE.");
// DEBUG
// ROS_WARN("[%i] -----------------------STARTING MAIN LOOP!", robot_id);
@ -138,7 +138,8 @@ void roscontroller::RosControllerRun()
grid_publisher();
send_MPpayload();
// Check updater state and step code
if(update) buzz_update::update_routine();
if (update)
buzz_update::update_routine();
if (time_step == BUZZRATE)
{
time_step = 0;
@ -159,26 +160,29 @@ void roscontroller::RosControllerRun()
// log data
logtocsv();
// Call Step from buzz script
buzz_utility::buzz_script_step();
// Force a refresh on neighbors array once in a while
if (timer_step >= 20*BUZZRATE){
if (timer_step >= 20 * BUZZRATE)
{
clear_pos();
timer_step = 0;
} else
}
else
timer_step++;
// Prepare messages and publish them
prepare_msg_and_publish();
// Call the flight controler service
flight_controller_service_call();
// Broadcast local position to FCU
if(BClpose && !setmode)
SetLocalPosition(goto_pos[0], goto_pos[1], goto_pos[2], goto_pos[3]);
if (BClpose && !setmode)
SetLocalPosition(goto_pos[0], goto_pos[1], goto_pos[2], goto_pos[3]);
// Set ROBOTS variable (swarm size)
get_number_of_robots();
buzz_utility::set_robot_var(no_of_robots);
if(update) buzz_update::updates_set_robots(no_of_robots);
if (update)
buzz_update::updates_set_robots(no_of_robots);
// get_xbee_status(); // commented out because it may slow down the node too much, to be tested
ros::spinOnce();
@ -203,19 +207,19 @@ void roscontroller::initcsvlog()
/ Create the CSV log file
/-------------------------------------------------------*/
{
std::string path =
bzzfile_name.substr(0, bzzfile_name.find_last_of("\\/")) + "/";
path = path.substr(0, bzzfile_name.find_last_of("\\/"))+"/log/";
std::string folder_check="mkdir -p "+path;
std::string path = bzzfile_name.substr(0, bzzfile_name.find_last_of("\\/")) + "/";
path = path.substr(0, bzzfile_name.find_last_of("\\/")) + "/log/";
std::string folder_check = "mkdir -p " + path;
system(folder_check.c_str());
for(int i=5;i>0;i--){
rename((path +"logger_"+ std::to_string((uint8_t)robot_id)+"_"+std::to_string(i-1)+".log").c_str(),
(path +"logger_"+ std::to_string((uint8_t)robot_id)+"_"+std::to_string(i)+".log").c_str());
for (int i = 5; i > 0; i--)
{
rename((path + "logger_" + std::to_string((uint8_t)robot_id) + "_" + std::to_string(i - 1) + ".log").c_str(),
(path + "logger_" + std::to_string((uint8_t)robot_id) + "_" + std::to_string(i) + ".log").c_str());
}
path += "logger_"+std::to_string(robot_id)+"_0.log";
path += "logger_" + std::to_string(robot_id) + "_0.log";
log.open(path.c_str(), std::ios_base::trunc | std::ios_base::out);
// set log data double precision
log <<std::setprecision(15) << std::fixed;
// set log data double precision
log << std::setprecision(15) << std::fixed;
}
void roscontroller::logtocsv()
@ -225,28 +229,25 @@ void roscontroller::logtocsv()
{
// hardware time now
log << ros::Time::now().toNSec() << ",";
log << cur_pos.latitude << "," << cur_pos.longitude << ","
<< cur_pos.altitude << ",";
log << cur_pos.latitude << "," << cur_pos.longitude << "," << cur_pos.altitude << ",";
log << (int)no_of_robots << ",";
log << neighbours_pos_map.size() << ",";
log << (int)inmsgdata.size() << "," << message_number << ",";
log << out_msg_time <<",";
log << out_msg_size<<",";
log << out_msg_time << ",";
log << out_msg_size << ",";
log << buzz_utility::get_bvmstate();
map<int, buzz_utility::Pos_struct>::iterator it =
neighbours_pos_map.begin();
map<int, buzz_utility::Pos_struct>::iterator it = neighbours_pos_map.begin();
for (; it != neighbours_pos_map.end(); ++it)
{
log << "," << it->first << ",";
log << (double)it->second.x << "," << (double)it->second.y
<< "," << (double)it->second.z;
log << "," << it->first << ",";
log << (double)it->second.x << "," << (double)it->second.y << "," << (double)it->second.z;
}
for (std::vector<msg_data>::iterator it = inmsgdata.begin() ; it != inmsgdata.end(); ++it)
for (std::vector<msg_data>::iterator it = inmsgdata.begin(); it != inmsgdata.end(); ++it)
{
log << "," << (int)it->nid << "," << (int)it->msgid << "," << (int)it->size << "," <<
it->sent_time << ","<< it->received_time;
log << "," << (int)it->nid << "," << (int)it->msgid << "," << (int)it->size << "," << it->sent_time << ","
<< it->received_time;
}
inmsgdata.clear();
log << std::endl;
@ -395,7 +396,7 @@ void roscontroller::PubandServ(ros::NodeHandle& n_c, ros::NodeHandle& node_handl
}
if (node_handle.getParam("services/modeclient", topic))
{
if(setmode)
if (setmode)
mode_client = n_c.serviceClient<mavros_msgs::SetMode>(topic);
}
else
@ -480,11 +481,10 @@ void roscontroller::Initialize_pub_sub(ros::NodeHandle& n_c, ros::NodeHandle& n_
// Publishers and service Clients
PubandServ(n_c, n_c_priv);
ROS_INFO("Ready to receive Mav Commands from RC client");
capture_srv = n_c.serviceClient<mavros_msgs::CommandBool>(capture_srv_name);
multi_msg = true;
}
@ -583,11 +583,12 @@ void roscontroller::neighbours_pos_publisher()
// cout<<"iterator it val: "<< it-> first << " After convertion: "
// <<(uint8_t) buzz_utility::get_rid_uint8compac(it->first)<<endl;
// std::cout<<"long obt"<<neigh_tmp.longitude<<endl;
// Check if any simulated target are in range
double tf[4] = {-1, 0, 0, 0};
double tf[4] = { -1, 0, 0, 0 };
buzzuav_closures::check_targets_sim((it->second).x, (it->second).y, tf);
if(tf[0]!=-1){
if (tf[0] != -1)
{
buzz_utility::Pos_struct pos_tmp;
pos_tmp.x = tf[1];
pos_tmp.y = tf[2];
@ -641,24 +642,25 @@ void roscontroller::grid_publisher()
/ Publish current Grid from Buzz script
/----------------------------------------------------*/
{
std::map<int, std::map<int,int>> grid = buzzuav_closures::getgrid();
std::map<int, std::map<int,int>>::iterator itr = grid.begin();
std::map<int, std::map<int, int>> grid = buzzuav_closures::getgrid();
std::map<int, std::map<int, int>>::iterator itr = grid.begin();
int g_w = itr->second.size();
int g_h = grid.size();
if(g_w!=0 && g_h!=0) {
if (g_w != 0 && g_h != 0)
{
// DEBUG
//ROS_INFO("------> Publishing a grid of %i x %i", g_h, g_w);
// ROS_INFO("------> Publishing a grid of %i x %i", g_h, g_w);
auto current_time = ros::Time::now();
nav_msgs::OccupancyGrid grid_msg;
grid_msg.header.frame_id = "/world";
grid_msg.header.stamp = current_time;
grid_msg.info.map_load_time = current_time; // Same as header stamp as we do not load the map.
grid_msg.info.resolution = 0.01;//gridMap.getResolution();
grid_msg.info.resolution = 0.01; // gridMap.getResolution();
grid_msg.info.width = g_w;
grid_msg.info.height = g_h;
grid_msg.info.origin.position.x = round(g_w/2.0) * grid_msg.info.resolution;
grid_msg.info.origin.position.y = round(g_h/2.0) * grid_msg.info.resolution;
grid_msg.info.origin.position.x = round(g_w / 2.0) * grid_msg.info.resolution;
grid_msg.info.origin.position.y = round(g_h / 2.0) * grid_msg.info.resolution;
grid_msg.info.origin.position.z = 0.0;
grid_msg.info.origin.orientation.x = 0.0;
grid_msg.info.origin.orientation.y = 0.0;
@ -666,19 +668,21 @@ void roscontroller::grid_publisher()
grid_msg.info.origin.orientation.w = 1.0;
grid_msg.data.resize(g_w * g_h);
for (itr=grid.begin(); itr!=grid.end(); ++itr) {
std::map<int,int>::iterator itc = itr->second.begin();
for (itc=itr->second.begin(); itc!=itr->second.end(); ++itc) {
grid_msg.data[(itr->first-1)*g_w+itc->first] = itc->second;
for (itr = grid.begin(); itr != grid.end(); ++itr)
{
std::map<int, int>::iterator itc = itr->second.begin();
for (itc = itr->second.begin(); itc != itr->second.end(); ++itc)
{
grid_msg.data[(itr->first - 1) * g_w + itc->first] = itc->second;
// DEBUG
//ROS_INFO("--------------> index: %i (%i,%i): %i", (itr->first-1)*g_w+itc->first, itr->first, itc->first, grid_msg.data[(itr->first-1)*g_w+itc->first]);
// ROS_INFO("--------------> index: %i (%i,%i): %i", (itr->first-1)*g_w+itc->first, itr->first, itc->first,
// grid_msg.data[(itr->first-1)*g_w+itc->first]);
}
}
grid_pub.publish(grid_msg);
}
}
void roscontroller::Arm()
/*
/ Functions handling the local MAV ROS flight controller
@ -729,13 +733,13 @@ with size......... | /
else
message_number++;
//header variables
// header variables
uint16_t tmphead[4];
tmphead[1] = (uint16_t)message_number;
//uint32_t stime = (uint32_t)(ros::Time::now().toSec()); //(uint32_t)(logical_clock.toSec() * 100000);
memcpy((void*)(tmphead+2),(void*)&stime,sizeof(uint32_t));
// uint32_t stime = (uint32_t)(ros::Time::now().toSec()); //(uint32_t)(logical_clock.toSec() * 100000);
memcpy((void*)(tmphead + 2), (void*)&stime, sizeof(uint32_t));
uint64_t rheader[1];
rheader[0]=0;
rheader[0] = 0;
payload_out.sysid = (uint8_t)robot_id;
payload_out.msgid = (uint32_t)message_number;
@ -755,7 +759,7 @@ with size......... | /
{
payload_out.payload64.push_back(payload_out_ptr[i]);
}
//Store out msg time
// Store out msg time
out_msg_time = ros::Time::now().toNSec();
out_msg_size = out[0];
// publish prepared messages in respective topic
@ -825,7 +829,8 @@ script
cmd_srv.request.command = buzzuav_closures::getcmd();
if (!armstate)
{
if(setmode){
if (setmode)
{
SetMode("LOITER", 0);
ros::Duration(0.5).sleep();
}
@ -834,13 +839,13 @@ script
// Registering HOME POINT.
home = cur_pos;
// Initialize GPS goal for safety.
double gpspgoal[3] = {cur_pos.latitude,cur_pos.longitude,cur_pos.altitude};
double gpspgoal[3] = { cur_pos.latitude, cur_pos.longitude, cur_pos.altitude };
buzzuav_closures::set_gpsgoal(gpspgoal);
BClpose = true;
BClpose = true;
}
if (current_mode != "GUIDED" && setmode)
SetMode("GUIDED", 3000); // added for compatibility with 3DR Solo
if(setmode)
if (setmode)
{
if (mav_client.call(cmd_srv))
{
@ -862,7 +867,7 @@ script
armstate = 0;
Arm();
}
else if(cur_pos.altitude < 0.4) //disarm only when close to ground
else if (cur_pos.altitude < 0.4) // disarm only when close to ground
{
armstate = 0;
Arm();
@ -894,17 +899,17 @@ script
case COMPONENT_ARM_DISARM:
if (!armstate)
{
if(setmode)
if (setmode)
SetMode("LOITER", 0);
armstate = 1;
Arm();
}
break;
case COMPONENT_ARM_DISARM+1:
case COMPONENT_ARM_DISARM + 1:
if (armstate)
{
if(setmode)
if (setmode)
SetMode("LOITER", 0);
armstate = 0;
Arm();
@ -913,7 +918,7 @@ script
case NAV_SPLINE_WAYPOINT:
goto_pos = buzzuav_closures::getgoto();
if(setmode)
if (setmode)
SetLocalPosition(goto_pos[0], goto_pos[1], goto_pos[2], goto_pos[3]);
break;
@ -950,12 +955,11 @@ void roscontroller::clear_pos()
/Refresh neighbours Position for every ten step
/---------------------------------------------*/
{
neighbours_pos_map.clear();
raw_neighbours_pos_map.clear();
buzzuav_closures::clear_neighbours_pos();
// raw_neighbours_pos_map.clear(); // TODO: currently not a problem, but
// have to clear !
neighbours_pos_map.clear();
raw_neighbours_pos_map.clear();
buzzuav_closures::clear_neighbours_pos();
// raw_neighbours_pos_map.clear(); // TODO: currently not a problem, but
// have to clear !
}
void roscontroller::neighbours_pos_put(int id, buzz_utility::Pos_struct pos_arr)
@ -1088,21 +1092,17 @@ void roscontroller::local_pos_callback(const geometry_msgs::PoseStamped::ConstPt
cur_pos.x = msg->pose.position.x;
cur_pos.y = msg->pose.position.y;
if(!BClpose)
if (!BClpose)
{
goto_pos[0]=cur_pos.x;
goto_pos[1]=cur_pos.y;
goto_pos[2]=0.0;
BClpose = true;
goto_pos[0] = cur_pos.x;
goto_pos[1] = cur_pos.y;
goto_pos[2] = 0.0;
BClpose = true;
}
buzzuav_closures::set_currentNEDpos(msg->pose.position.y,msg->pose.position.x);
buzzuav_closures::set_currentNEDpos(msg->pose.position.y, msg->pose.position.x);
// cur_pos.z = pose->pose.position.z; // Using relative altitude topic instead
tf::Quaternion q(
msg->pose.orientation.x,
msg->pose.orientation.y,
msg->pose.orientation.z,
msg->pose.orientation.w);
tf::Quaternion q(msg->pose.orientation.x, msg->pose.orientation.y, msg->pose.orientation.z, msg->pose.orientation.w);
tf::Matrix3x3 m(q);
double roll, pitch, yaw;
m.getRPY(roll, pitch, yaw);
@ -1157,8 +1157,8 @@ void roscontroller::SetLocalPosition(float x, float y, float z, float yaw)
moveMsg.pose.orientation.w = q[3];
// To prevent drifting from stable position, uncomment
//if(fabs(x)>0.005 || fabs(y)>0.005) {
localsetpoint_nonraw_pub.publish(moveMsg);
// if(fabs(x)>0.005 || fabs(y)>0.005) {
localsetpoint_nonraw_pub.publish(moveMsg);
//}
}
@ -1197,15 +1197,15 @@ void roscontroller::SetStreamRate(int id, int rate, int on_off)
message.request.stream_id = id;
message.request.message_rate = rate;
message.request.on_off = on_off;
int timeout = 20; // 2sec at 10Hz
int timeout = 20; // 2sec at 10Hz
while (!stream_client.call(message) && timeout>0)
while (!stream_client.call(message) && timeout > 0)
{
ROS_INFO("Set stream rate call failed!, trying again...");
ros::Duration(0.1).sleep();
timeout--;
}
if(timeout<1)
if (timeout < 1)
ROS_ERROR("Set stream rate timed out!");
else
ROS_WARN("Set stream rate call successful");
@ -1228,12 +1228,12 @@ void roscontroller::payload_obt(const mavros_msgs::Mavlink::ConstPtr& msg)
// decode msg header
uint64_t rhead = msg->payload64[0];
uint16_t r16head[4];
memcpy(r16head,&rhead, sizeof(uint64_t));
memcpy(r16head, &rhead, sizeof(uint64_t));
uint16_t mtype = r16head[0];
uint16_t mid = r16head[1];
uint32_t temptime=0;
memcpy(&temptime, r16head+2, sizeof(uint32_t));
//float stime = (float)temptime/(float)100000;
uint32_t temptime = 0;
memcpy(&temptime, r16head + 2, sizeof(uint32_t));
// float stime = (float)temptime/(float)100000;
// if(debug) ROS_INFO("Received Msg: sent time %f for id %u",stime, mid);
// Check for Updater message, if updater message push it into updater FIFO
if ((uint64_t)msg->payload64[0] == (uint64_t)UPDATER_MESSAGE)
@ -1284,7 +1284,7 @@ void roscontroller::payload_obt(const mavros_msgs::Mavlink::ConstPtr& msg)
// Extract robot id of the neighbour
uint16_t* out = buzz_utility::u64_cvt_u16((uint64_t) * (message_obt + index));
// store in msg data for data log
msg_data inm(mid,out[1],out[0]*sizeof(uint64_t),stime,ros::Time::now().toNSec());
msg_data inm(mid, out[1], out[0] * sizeof(uint64_t), stime, ros::Time::now().toNSec());
inmsgdata.push_back(inm);
if (debug)