added popup on waypoint, batt level yellow color, fix gps location for pangeae and enhanced robustness to packet lost
This commit is contained in:
parent
fd7490b6c9
commit
4fbdb07ce4
|
@ -22,17 +22,18 @@ function barrier_create() {
|
||||||
timeW = 1
|
timeW = 1
|
||||||
# create barrier vstig
|
# create barrier vstig
|
||||||
#log("---> Prev. br. ", barrier, " ", BARRIER_VSTIG)
|
#log("---> Prev. br. ", barrier, " ", BARRIER_VSTIG)
|
||||||
if(barrier!=nil) {
|
#if(barrier!=nil) {
|
||||||
barrier=nil
|
# barrier=nil
|
||||||
if(hvs) {
|
#if(hvs) {
|
||||||
BARRIER_VSTIG = BARRIER_VSTIG -1
|
# BARRIER_VSTIG = BARRIER_VSTIG -1
|
||||||
hvs = 0
|
# hvs = 0
|
||||||
}else{
|
#}else{
|
||||||
BARRIER_VSTIG = BARRIER_VSTIG +1
|
# BARRIER_VSTIG = BARRIER_VSTIG +1
|
||||||
hvs = 1
|
# hvs = 1
|
||||||
}
|
#}
|
||||||
}
|
#}
|
||||||
#log("---> New. br. ", barrier, " ", BARRIER_VSTIG)
|
#log("---> New. br. ", barrier, " ", BARRIER_VSTIG)
|
||||||
|
if(barrier==nil)
|
||||||
barrier = stigmergy.create(BARRIER_VSTIG)
|
barrier = stigmergy.create(BARRIER_VSTIG)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ function barrier_ready(bc) {
|
||||||
#log("BARRIER READY -------")
|
#log("BARRIER READY -------")
|
||||||
barrier.put(id, bc)
|
barrier.put(id, bc)
|
||||||
barrier.put("d", 0)
|
barrier.put("d", 0)
|
||||||
|
barrier.put("n", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -61,22 +63,33 @@ function barrier_wait(threshold, transf, resumef, bc) {
|
||||||
barrier_create()
|
barrier_create()
|
||||||
|
|
||||||
barrier.put(id, bc)
|
barrier.put(id, bc)
|
||||||
log("--->BS: ", barrier.size(), " / ", threshold, " (", BARRIER_VSTIG, " - ", barrier.get("d"), ") t= ", timeW)
|
if(barrier.get("n")<threshold)
|
||||||
#if(barrier.size()-1 >= threshold or barrier.get("d") == 1) {
|
barrier.put("n", threshold)
|
||||||
|
if(threshold>1) {
|
||||||
|
neighbors.foreach(function (nei,data){
|
||||||
|
barrier.get(nei)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
# Not to miss any RC inputs, for waypoints, potential and deploy states
|
||||||
|
check_rc_wp()
|
||||||
|
|
||||||
|
#log("--->BS: ", barrier.size(), " / ", threshold, " (", BARRIER_VSTIG, " - ", barrier.get("d"), ") t= ", timeW)
|
||||||
|
if(barrier.size()-2 >= barrier.get("n")) {
|
||||||
if(barrier_allgood(barrier,bc)) {
|
if(barrier_allgood(barrier,bc)) {
|
||||||
barrier.put("d", 1)
|
barrier.put("d", 1)
|
||||||
timeW = 0
|
timeW = 0
|
||||||
BVMSTATE = transf
|
BVMSTATE = transf
|
||||||
} else
|
} else
|
||||||
barrier.put("d", 0)
|
barrier.put("d", 0)
|
||||||
#}
|
}
|
||||||
|
|
||||||
if(timeW >= BARRIER_TIMEOUT) {
|
if(timeW >= BARRIER_TIMEOUT) {
|
||||||
log("------> Barrier Timeout !!!!")
|
log("------> Barrier Timeout !!!!")
|
||||||
barrier = nil
|
#barrier = nil
|
||||||
timeW = 0
|
timeW = 0
|
||||||
BVMSTATE = resumef
|
BVMSTATE = resumef
|
||||||
} else if(timeW % 100 == 0 and bc > 0)
|
} else if(timeW % 10 == 0 and bc > 0)
|
||||||
neighbors.broadcast("cmd", bc)
|
neighbors.broadcast("cmd", bc)
|
||||||
|
|
||||||
timeW = timeW+1
|
timeW = timeW+1
|
||||||
|
@ -86,11 +99,12 @@ function barrier_wait(threshold, transf, resumef, bc) {
|
||||||
function barrier_allgood(barrier, bc) {
|
function barrier_allgood(barrier, bc) {
|
||||||
barriergood = 1
|
barriergood = 1
|
||||||
barrier.foreach(function(key, value, robot){
|
barrier.foreach(function(key, value, robot){
|
||||||
|
barrier.get(key)
|
||||||
#log("VS entry : ", key, " ", value, " ", robot)
|
#log("VS entry : ", key, " ", value, " ", robot)
|
||||||
if(key == "d"){
|
if(key == "d"){
|
||||||
if(value == 1)
|
if(value == 1)
|
||||||
return 1
|
return 1
|
||||||
} else if(value != bc)
|
} else if(key!="n" and value != bc)
|
||||||
barriergood = 0
|
barriergood = 0
|
||||||
})
|
})
|
||||||
return barriergood
|
return barriergood
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
GOTO_MAXVEL = 1.5 # m/steps
|
GOTO_MAXVEL = 1.5 # m/steps
|
||||||
GOTO_MAXDIST = 150 # m.
|
GOTO_MAXDIST = 250 # m.
|
||||||
GOTODIST_TOL = 0.4 # m.
|
GOTODIST_TOL = 0.4 # m.
|
||||||
GOTOANG_TOL = 0.1 # rad.
|
GOTOANG_TOL = 0.1 # rad.
|
||||||
GPSlimit = {.1={.lat=45.510400, .lng=-73.610421},
|
GPSlimit_CEPSUM = {.1={.lat=45.510400, .lng=-73.610421},
|
||||||
.2={.lat=45.510896, .lng=-73.608731},
|
.2={.lat=45.510896, .lng=-73.608731},
|
||||||
.3={.lat=45.510355, .lng=-73.608404},
|
.3={.lat=45.510355, .lng=-73.608404},
|
||||||
.4={.lat=45.509840, .lng=-73.610072}}
|
.4={.lat=45.509840, .lng=-73.610072}}
|
||||||
|
|
||||||
|
GPSlimit_PANGEAE = {.1={.lat=29.020871, .lng=-13.712477},
|
||||||
|
.2={.lat=29.019850, .lng=-13.712378},
|
||||||
|
.3={.lat=29.019875, .lng=-13.710096},
|
||||||
|
.4={.lat=29.021245, .lng=-13.710184}}
|
||||||
|
|
||||||
# Core naviguation function to travel to a GPS target location.
|
# Core naviguation function to travel to a GPS target location.
|
||||||
function goto_gps(transf) {
|
function goto_gps(transf) {
|
||||||
m_navigation = vec_from_gps(cur_goal.latitude, cur_goal.longitude, 0)
|
m_navigation = vec_from_gps(cur_goal.latitude, cur_goal.longitude, 0)
|
||||||
|
@ -17,7 +22,7 @@ function goto_gps(transf) {
|
||||||
transf()
|
transf()
|
||||||
} else {
|
} else {
|
||||||
m_navigation = LimitSpeed(m_navigation, 1.0)
|
m_navigation = LimitSpeed(m_navigation, 1.0)
|
||||||
gf = {.0=m_navigation, .1=vec_from_gps(GPSlimit[1].lat, GPSlimit[1].lng, 0), .2=vec_from_gps(GPSlimit[2].lat, GPSlimit[2].lng, 0), .3=vec_from_gps(GPSlimit[3].lat, GPSlimit[3].lng, 0), .4=vec_from_gps(GPSlimit[4].lat, GPSlimit[4].lng, 0)}
|
gf = {.0=m_navigation, .1=vec_from_gps(GPSlimit_PANGEAE[1].lat, GPSlimit_PANGEAE[1].lng, 0), .2=vec_from_gps(GPSlimit_PANGEAE[2].lat, GPSlimit_PANGEAE[2].lng, 0), .3=vec_from_gps(GPSlimit_PANGEAE[3].lat, GPSlimit_PANGEAE[3].lng, 0), .4=vec_from_gps(GPSlimit_PANGEAE[4].lat, GPSlimit_PANGEAE[4].lng, 0)}
|
||||||
geofence(gf)
|
geofence(gf)
|
||||||
#m_navigation = LCA(m_navigation)
|
#m_navigation = LCA(m_navigation)
|
||||||
goto_abs(m_navigation.x, m_navigation.y, cur_goal.altitude - pose.position.altitude, 0.0)
|
goto_abs(m_navigation.x, m_navigation.y, cur_goal.altitude - pose.position.altitude, 0.0)
|
||||||
|
|
|
@ -43,14 +43,14 @@ function rc_cmd_listen() {
|
||||||
} else if (flight.rc_cmd==901){
|
} else if (flight.rc_cmd==901){
|
||||||
flight.rc_cmd=0
|
flight.rc_cmd=0
|
||||||
destroyGraph()
|
destroyGraph()
|
||||||
resetWP()
|
check_rc_wp()
|
||||||
barrier_set(ROBOTS, "DEPLOY", BVMSTATE, 901)
|
barrier_set(ROBOTS, "DEPLOY", BVMSTATE, 901)
|
||||||
barrier_ready(901)
|
barrier_ready(901)
|
||||||
neighbors.broadcast("cmd", 901)
|
neighbors.broadcast("cmd", 901)
|
||||||
} else if (flight.rc_cmd==902){
|
} else if (flight.rc_cmd==902){
|
||||||
flight.rc_cmd=0
|
flight.rc_cmd=0
|
||||||
destroyGraph()
|
destroyGraph()
|
||||||
resetWP()
|
check_rc_wp()
|
||||||
barrier_set(ROBOTS, "WAYPOINT", BVMSTATE, 902)
|
barrier_set(ROBOTS, "WAYPOINT", BVMSTATE, 902)
|
||||||
barrier_ready(902)
|
barrier_ready(902)
|
||||||
neighbors.broadcast("cmd", 902)
|
neighbors.broadcast("cmd", 902)
|
||||||
|
@ -58,12 +58,14 @@ function rc_cmd_listen() {
|
||||||
flight.rc_cmd=0
|
flight.rc_cmd=0
|
||||||
destroyGraph()
|
destroyGraph()
|
||||||
resetWP()
|
resetWP()
|
||||||
|
check_rc_wp()
|
||||||
barrier_set(ROBOTS, "POTENTIAL", BVMSTATE, 903)
|
barrier_set(ROBOTS, "POTENTIAL", BVMSTATE, 903)
|
||||||
barrier_ready(903)
|
barrier_ready(903)
|
||||||
neighbors.broadcast("cmd", 903)
|
neighbors.broadcast("cmd", 903)
|
||||||
} else if (flight.rc_cmd==904){
|
} else if (flight.rc_cmd==904){
|
||||||
flight.rc_cmd=0
|
flight.rc_cmd=0
|
||||||
destroyGraph()
|
destroyGraph()
|
||||||
|
resetWP()
|
||||||
barrier_set(ROBOTS, "IDLE", BVMSTATE, 904)
|
barrier_set(ROBOTS, "IDLE", BVMSTATE, 904)
|
||||||
barrier_ready(904)
|
barrier_ready(904)
|
||||||
neighbors.broadcast("cmd", 904)
|
neighbors.broadcast("cmd", 904)
|
||||||
|
@ -90,7 +92,8 @@ function nei_cmd_listen() {
|
||||||
} else {
|
} else {
|
||||||
if(value==20) {
|
if(value==20) {
|
||||||
AUTO_LAUNCH_STATE = "IDLE"
|
AUTO_LAUNCH_STATE = "IDLE"
|
||||||
BVMSTATE = "GOHOME"
|
barrier_set(ROBOTS, "GOHOME", BVMSTATE, 20)
|
||||||
|
barrier_ready(20)
|
||||||
} else if(value==21 ) {
|
} else if(value==21 ) {
|
||||||
BVMSTATE = "STOP"
|
BVMSTATE = "STOP"
|
||||||
#neighbors.broadcast("cmd", 777)
|
#neighbors.broadcast("cmd", 777)
|
||||||
|
@ -150,7 +153,7 @@ function check_rc_wp() {
|
||||||
WPtab[rc_goto.id]=ls
|
WPtab[rc_goto.id]=ls
|
||||||
}
|
}
|
||||||
v_wp.put(WPtab_id,WPtab)
|
v_wp.put(WPtab_id,WPtab)
|
||||||
} else
|
} else # Individual waypoint
|
||||||
v_wp.put(rc_goto.id,ls)
|
v_wp.put(rc_goto.id,ls)
|
||||||
reset_rc()
|
reset_rc()
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ function idle() {
|
||||||
# Core state function to launch the robot: takeoff and wait for others, or stop (land)
|
# Core state function to launch the robot: takeoff and wait for others, or stop (land)
|
||||||
function launch() {
|
function launch() {
|
||||||
BVMSTATE = "LAUNCH"
|
BVMSTATE = "LAUNCH"
|
||||||
|
neighbors.broadcast("cmd", 22)
|
||||||
log("AUTO_LAUNCH_STATE: ", AUTO_LAUNCH_STATE)
|
log("AUTO_LAUNCH_STATE: ", AUTO_LAUNCH_STATE)
|
||||||
if(V_TYPE == 0 or V_TYPE == 1) { # flying vehicle so TAKE_OFF
|
if(V_TYPE == 0 or V_TYPE == 1) { # flying vehicle so TAKE_OFF
|
||||||
homegps = {.lat=pose.position.latitude, .lng=pose.position.longitude}
|
homegps = {.lat=pose.position.latitude, .lng=pose.position.longitude}
|
||||||
|
@ -43,7 +44,6 @@ function launch() {
|
||||||
barrier_ready(22)
|
barrier_ready(22)
|
||||||
} else {
|
} else {
|
||||||
log("Altitude: ", pose.position.altitude)
|
log("Altitude: ", pose.position.altitude)
|
||||||
neighbors.broadcast("cmd", 22)
|
|
||||||
uav_takeoff(TARGET_ALTITUDE)
|
uav_takeoff(TARGET_ALTITUDE)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -85,14 +85,15 @@ function goinghome() {
|
||||||
#m_navigation = LCA(m_navigation)
|
#m_navigation = LCA(m_navigation)
|
||||||
goto_abs(m_navigation.x, m_navigation.y, cur_goal.altitude - pose.position.altitude, 0.0)
|
goto_abs(m_navigation.x, m_navigation.y, cur_goal.altitude - pose.position.altitude, 0.0)
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
|
BVMSTATE = AUTO_LAUNCH_STATE
|
||||||
}
|
}
|
||||||
|
|
||||||
# Core state function to stop and land.
|
# Core state function to stop and land.
|
||||||
function stop() {
|
function stop() {
|
||||||
BVMSTATE = "STOP"
|
BVMSTATE = "STOP"
|
||||||
if(V_TYPE == 0 or V_TYPE == 1) { # flying vehicle so LAND
|
|
||||||
neighbors.broadcast("cmd", 21)
|
neighbors.broadcast("cmd", 21)
|
||||||
|
if(V_TYPE == 0 or V_TYPE == 1) { # flying vehicle so LAND
|
||||||
uav_land()
|
uav_land()
|
||||||
if(pose.position.altitude <= 0.2) {
|
if(pose.position.altitude <= 0.2) {
|
||||||
BVMSTATE = "STOP"
|
BVMSTATE = "STOP"
|
||||||
|
@ -118,8 +119,8 @@ function indiWP() {
|
||||||
wp = unpackWP2i(wpi)
|
wp = unpackWP2i(wpi)
|
||||||
if(wp.pro == 0) {
|
if(wp.pro == 0) {
|
||||||
wpreached = 0
|
wpreached = 0
|
||||||
storegoal(wp.lat, wp.lon, pose.position.altitude)
|
storegoal(wp.lat, wp.lng, pose.position.altitude)
|
||||||
var ls = packWP2i(wp.lat, wp.lon, 1)
|
var ls = packWP2i(wp.lat, wp.lng, 1)
|
||||||
v_wp.put(id,ls)
|
v_wp.put(id,ls)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -257,11 +258,13 @@ function voronoicentroid() {
|
||||||
BVMSTATE="DEPLOY"
|
BVMSTATE="DEPLOY"
|
||||||
check_rc_wp()
|
check_rc_wp()
|
||||||
wptab = v_wp.get(WPtab_id)
|
wptab = v_wp.get(WPtab_id)
|
||||||
if(wptab==nil or V_TYPE == 2)
|
if(wptab==nil)
|
||||||
return
|
return
|
||||||
else if(not(size(wptab) > 0))
|
else if(not(size(wptab) > 0))
|
||||||
return
|
return
|
||||||
log("WP table size:", size(wptab))
|
log("WP table size:", size(wptab))
|
||||||
|
if(V_TYPE == 2)
|
||||||
|
return
|
||||||
it_pts = 0
|
it_pts = 0
|
||||||
att = {}
|
att = {}
|
||||||
foreach(wptab, function(key, value){
|
foreach(wptab, function(key, value){
|
||||||
|
@ -269,7 +272,7 @@ function voronoicentroid() {
|
||||||
if(key > 99)
|
if(key > 99)
|
||||||
log("Nothing planed for the repulsors yet....")
|
log("Nothing planed for the repulsors yet....")
|
||||||
else if(key > 49)
|
else if(key > 49)
|
||||||
att[it_pts]=vec_from_gps(wp.lat, wp.lon, 0)
|
att[it_pts]=vec_from_gps(wp.lat, wp.lng, 0)
|
||||||
it_pts = it_pts + 1
|
it_pts = it_pts + 1
|
||||||
})
|
})
|
||||||
# Boundaries from Geofence
|
# Boundaries from Geofence
|
||||||
|
|
|
@ -62,16 +62,17 @@ function gps_from_vec(vec) {
|
||||||
return Lgoal
|
return Lgoal
|
||||||
}
|
}
|
||||||
|
|
||||||
GPSoffset = {.lat=45.50, .lon=-73.61}
|
GPSoffset = {.lat=45.50, .lng=-73.61}
|
||||||
|
GPSoffsetL = {.lat=29.01, .lng=-13.70}
|
||||||
|
|
||||||
function packWP2i(in_lat, in_long, processed) {
|
function packWP2i(in_lat, in_long, processed) {
|
||||||
var dlat = math.round((in_lat - GPSoffset.lat)*1000000)
|
var dlat = math.round((in_lat - GPSoffsetL.lat)*1000000)
|
||||||
var dlon = math.round((in_long - GPSoffset.lon)*1000000)
|
var dlon = math.round((in_long - GPSoffsetL.lng)*1000000)
|
||||||
return {.dla=dlat, .dlo=dlon*10+processed}
|
return {.dla=dlat, .dlo=dlon*10+processed}
|
||||||
}
|
}
|
||||||
|
|
||||||
function unpackWP2i(wp_int){
|
function unpackWP2i(wp_int){
|
||||||
var dlon = (wp_int.dlo-wp_int.dlo%10)/10.0
|
var dlon = (wp_int.dlo-wp_int.dlo%10)/10.0
|
||||||
var pro = wp_int.dlo-dlon*10
|
var pro = wp_int.dlo-dlon*10
|
||||||
return {.lat=wp_int.dla/1000000.0+GPSoffset.lat, .lon=dlon/1000000.0+GPSoffset.lon, .pro=pro}
|
return {.lat=wp_int.dla/1000000.0+GPSoffsetL.lat, .lng=dlon/1000000.0+GPSoffsetL.lng, .pro=pro}
|
||||||
}
|
}
|
|
@ -289,8 +289,8 @@ bool onSegment(Point p, Point q, Point r)
|
||||||
// 2 --> Counterclockwise
|
// 2 --> Counterclockwise
|
||||||
int orientation(Point p, Point q, Point r)
|
int orientation(Point p, Point q, Point r)
|
||||||
{
|
{
|
||||||
int val = (q.y - p.y) * (r.x - q.x) -
|
int val =round((q.y - p.y) * (r.x - q.x)*100 -
|
||||||
(q.x - p.x) * (r.y - q.y);
|
(q.x - p.x) * (r.y - q.y)*100);
|
||||||
|
|
||||||
if (val == 0) return 0; // colinear
|
if (val == 0) return 0; // colinear
|
||||||
return (val > 0)? 1: 2; // clock or counterclock wise
|
return (val > 0)? 1: 2; // clock or counterclock wise
|
||||||
|
@ -306,6 +306,8 @@ bool doIntersect(Point p1, Point q1, Point p2, Point q2)
|
||||||
int o3 = orientation(p2, q2, p1);
|
int o3 = orientation(p2, q2, p1);
|
||||||
int o4 = orientation(p2, q2, q1);
|
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
|
// General case
|
||||||
if (o1 != o2 && o3 != o4)
|
if (o1 != o2 && o3 != o4)
|
||||||
return true;
|
return true;
|
||||||
|
@ -341,92 +343,6 @@ void sortclose_polygon(vector <Point> *P){
|
||||||
P->push_back((*P)[0]);
|
P->push_back((*P)[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
int buzzuav_geofence(buzzvm_t vm)
|
|
||||||
{
|
|
||||||
bool onedge = false;
|
|
||||||
Point P;
|
|
||||||
Point V[4];
|
|
||||||
int tmp;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
for(int32_t i = 0; i < buzzdict_size(t->t.value); ++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);
|
|
||||||
tmp = buzzvm_stack_at(vm, 1)->f.value;
|
|
||||||
//ROS_INFO("[%i]---x-->%i",buzz_utility::get_robotid(), tmp);
|
|
||||||
if(i==0)
|
|
||||||
P.x = tmp;
|
|
||||||
else
|
|
||||||
V[i-1].x = tmp;
|
|
||||||
buzzvm_pop(vm);
|
|
||||||
buzzvm_dup(vm);
|
|
||||||
buzzvm_pushs(vm, buzzvm_string_register(vm, "y", 1));
|
|
||||||
buzzvm_tget(vm);
|
|
||||||
tmp = buzzvm_stack_at(vm, 1)->f.value;
|
|
||||||
//ROS_INFO("[%i]---y-->%i",buzz_utility::get_robotid(), tmp);
|
|
||||||
if(i==0)
|
|
||||||
P.y = tmp;
|
|
||||||
else
|
|
||||||
V[i-1].y = tmp;
|
|
||||||
buzzvm_pop(vm);
|
|
||||||
|
|
||||||
buzzvm_pop(vm);
|
|
||||||
}
|
|
||||||
// TODO: use vector
|
|
||||||
//sortclose_polygon(&V);
|
|
||||||
|
|
||||||
// simple polygon: rectangle, 4 points
|
|
||||||
int n = 4;
|
|
||||||
// Create a point for line segment from p to infinite
|
|
||||||
Point extreme = {10000, P.y};
|
|
||||||
|
|
||||||
// Count intersections of the above line with sides of polygon
|
|
||||||
int count = 0, i = 0;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
int next = (i+1)%n;
|
|
||||||
|
|
||||||
// Check if the line segment from 'p' to 'extreme' intersects
|
|
||||||
// with the line segment from 'polygon[i]' to 'polygon[next]'
|
|
||||||
if (doIntersect(V[i], V[next], P, 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(V[i], P, V[next]) == 0) {
|
|
||||||
onedge = onSegment(V[i], P, V[next]);
|
|
||||||
if(onedge)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
i = next;
|
|
||||||
} while (i != 0);
|
|
||||||
|
|
||||||
//ROS_INFO("[%i] Geofence: %i, %i",buzz_utility::get_robotid(),count, onedge);
|
|
||||||
|
|
||||||
if((count%2 == 0) || onedge) {
|
|
||||||
goto_gpsgoal[0] = cur_pos[0];
|
|
||||||
goto_gpsgoal[1] = cur_pos[1];
|
|
||||||
ROS_WARN("Geofencing trigered, not going any further!");
|
|
||||||
}
|
|
||||||
|
|
||||||
return buzzvm_ret0(vm);
|
|
||||||
}
|
|
||||||
|
|
||||||
float pol_area(vector <Point> vert) {
|
float pol_area(vector <Point> vert) {
|
||||||
float a = 0.0;
|
float a = 0.0;
|
||||||
|
@ -487,9 +403,12 @@ void getintersection(Point S, Point D, std::vector <Point> Poly, Point *I) {
|
||||||
double r = numerator( S, (*itc), (*itc), (*next) ) / d;
|
double r = numerator( S, (*itc), (*itc), (*next) ) / d;
|
||||||
double s = numerator( S, (*itc), S, D ) / 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));
|
(*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);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isSiteout(Point S, std::vector <Point> Poly) {
|
bool isSiteout(Point S, std::vector <Point> Poly) {
|
||||||
|
@ -524,6 +443,71 @@ bool isSiteout(Point S, std::vector <Point> Poly) {
|
||||||
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}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);
|
||||||
|
}
|
||||||
|
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;
|
float dist_max = 300;
|
||||||
|
@ -565,22 +549,6 @@ int voronoi_center(buzzvm_t vm) {
|
||||||
buzzvm_pop(vm);
|
buzzvm_pop(vm);
|
||||||
}
|
}
|
||||||
sortclose_polygon(&polygon_bound);
|
sortclose_polygon(&polygon_bound);
|
||||||
// Check if we are in the zone
|
|
||||||
if(isSiteout(Point(0,0), polygon_bound)){
|
|
||||||
//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]);
|
|
||||||
double gps[3];
|
|
||||||
gps_from_vec(goal_tmp, gps);
|
|
||||||
set_gpsgoal(gps);
|
|
||||||
return buzzvm_ret0(vm);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int count = buzzdict_size(t->t.value)-(Poly_vert+1);
|
int count = buzzdict_size(t->t.value)-(Poly_vert+1);
|
||||||
ROS_WARN("NP: %d, Sites: %d", Poly_vert, count);
|
ROS_WARN("NP: %d, Sites: %d", Poly_vert, count);
|
||||||
|
@ -608,6 +576,22 @@ int voronoi_center(buzzvm_t vm) {
|
||||||
buzzvm_pop(vm);
|
buzzvm_pop(vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if we are 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]);
|
||||||
|
double gps[3];
|
||||||
|
gps_from_vec(goal_tmp, gps);
|
||||||
|
set_gpsgoal(gps);
|
||||||
|
return buzzvm_ret0(vm);
|
||||||
|
}
|
||||||
|
|
||||||
VoronoiDiagramGenerator vdg;
|
VoronoiDiagramGenerator vdg;
|
||||||
ROS_WARN("[%i] Voronoi Bounded tessellation starting with %i sites...", buzz_utility::get_robotid(),count);
|
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);
|
vdg.generateVoronoi(xValues, yValues, count, -dist_max, dist_max, -dist_max, dist_max, 3.0);
|
||||||
|
@ -920,7 +904,7 @@ void set_gpsgoal(double goal[3])
|
||||||
{
|
{
|
||||||
double rb[3];
|
double rb[3];
|
||||||
rb_from_gps(goal, rb, cur_pos);
|
rb_from_gps(goal, rb, cur_pos);
|
||||||
if (fabs(rb[0]) < 150.0) {
|
if (fabs(rb[0]) < 250.0) {
|
||||||
goto_gpsgoal[0] = goal[0];goto_gpsgoal[1] = goal[1];goto_gpsgoal[2] = goal[2];
|
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]);
|
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
|
} else
|
||||||
|
|
Loading…
Reference in New Issue