2018-10-18 23:18:12 -03:00
|
|
|
# listens to commands from the remote control (web, commandline, rcclient node, etc)
|
|
|
|
function rc_cmd_listen() {
|
2018-11-11 16:11:41 -04:00
|
|
|
if(BVMSTATE=="TURNEDOFF") {
|
|
|
|
if(flight.rc_cmd==400) { #ARM
|
|
|
|
flight.rc_cmd=0
|
|
|
|
arm()
|
|
|
|
neighbors.broadcast("cmd", 400)
|
|
|
|
} else if (flight.rc_cmd==401){ #DISARM
|
|
|
|
flight.rc_cmd=0
|
|
|
|
disarm()
|
|
|
|
neighbors.broadcast("cmd", 401)
|
|
|
|
} else if(flight.rc_cmd==22) { #TAKEOFF\LAUNCH
|
|
|
|
flight.rc_cmd=0
|
|
|
|
BVMSTATE = "LAUNCH"
|
|
|
|
neighbors.broadcast("cmd", 22)
|
|
|
|
} else if (flight.rc_cmd==777){ #SYNC
|
|
|
|
flight.rc_cmd=0
|
|
|
|
reinit_time_sync()
|
|
|
|
neighbors.broadcast("cmd", 777)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(flight.rc_cmd==21) {
|
|
|
|
flight.rc_cmd=0
|
|
|
|
BVMSTATE = "STOP"
|
|
|
|
neighbors.broadcast("cmd", 21)
|
|
|
|
} else if(BVMSTATE!="BARRIERWAIT" and BVMSTATE!="LAUNCH") {
|
2018-11-20 06:26:14 -04:00
|
|
|
if(flight.rc_cmd==20) {
|
|
|
|
flight.rc_cmd=0
|
|
|
|
destroyGraph()
|
|
|
|
check_rc_wp()
|
|
|
|
AUTO_LAUNCH_STATE = "IDLE"
|
|
|
|
barrier_set(ROBOTS, "GOHOME", BVMSTATE, 20)
|
|
|
|
barrier_ready(20)
|
|
|
|
neighbors.broadcast("cmd", 20)
|
|
|
|
} else if (flight.rc_cmd==666){
|
2018-11-11 16:11:41 -04:00
|
|
|
flight.rc_cmd=0
|
|
|
|
stattab_send()
|
|
|
|
} else if (flight.rc_cmd==900){
|
|
|
|
flight.rc_cmd=0
|
|
|
|
barrier_set(ROBOTS, "TASK_ALLOCATE", BVMSTATE, 900)
|
|
|
|
barrier_ready(900)
|
|
|
|
neighbors.broadcast("cmd", 900)
|
|
|
|
} else if (flight.rc_cmd==901){
|
|
|
|
flight.rc_cmd=0
|
|
|
|
destroyGraph()
|
2018-11-16 13:00:36 -04:00
|
|
|
check_rc_wp()
|
2018-11-11 16:11:41 -04:00
|
|
|
barrier_set(ROBOTS, "DEPLOY", BVMSTATE, 901)
|
|
|
|
barrier_ready(901)
|
|
|
|
neighbors.broadcast("cmd", 901)
|
|
|
|
} else if (flight.rc_cmd==902){
|
|
|
|
flight.rc_cmd=0
|
|
|
|
destroyGraph()
|
2018-11-16 13:00:36 -04:00
|
|
|
check_rc_wp()
|
2018-11-11 16:11:41 -04:00
|
|
|
barrier_set(ROBOTS, "WAYPOINT", BVMSTATE, 902)
|
|
|
|
barrier_ready(902)
|
|
|
|
neighbors.broadcast("cmd", 902)
|
|
|
|
} else if (flight.rc_cmd==903){
|
|
|
|
flight.rc_cmd=0
|
|
|
|
destroyGraph()
|
|
|
|
resetWP()
|
2018-11-16 13:00:36 -04:00
|
|
|
check_rc_wp()
|
2019-04-10 15:14:19 -03:00
|
|
|
barrier_set(ROBOTS, "PURSUIT", BVMSTATE, 903)
|
2018-11-11 16:11:41 -04:00
|
|
|
barrier_ready(903)
|
|
|
|
neighbors.broadcast("cmd", 903)
|
|
|
|
} else if (flight.rc_cmd==904){
|
|
|
|
flight.rc_cmd=0
|
|
|
|
destroyGraph()
|
2018-11-16 13:00:36 -04:00
|
|
|
resetWP()
|
2018-11-11 16:11:41 -04:00
|
|
|
barrier_set(ROBOTS, "IDLE", BVMSTATE, 904)
|
|
|
|
barrier_ready(904)
|
|
|
|
neighbors.broadcast("cmd", 904)
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 23:18:12 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# listens to neighbors broadcasting commands
|
|
|
|
function nei_cmd_listen() {
|
|
|
|
neighbors.listen("cmd",
|
|
|
|
function(vid, value, rid) {
|
|
|
|
print("Got (", vid, ",", value, ") #", rid, "(", BVMSTATE, ")")
|
2018-11-11 16:11:41 -04:00
|
|
|
if(BVMSTATE=="TURNEDOFF") {
|
|
|
|
if(value==22) {
|
2018-10-18 23:18:12 -03:00
|
|
|
BVMSTATE = "LAUNCH"
|
2018-11-11 16:11:41 -04:00
|
|
|
} else if(value==400) {
|
2018-10-18 23:18:12 -03:00
|
|
|
arm()
|
2018-11-11 16:11:41 -04:00
|
|
|
} else if(value==401){
|
2018-10-18 23:18:12 -03:00
|
|
|
disarm()
|
2018-11-11 16:11:41 -04:00
|
|
|
} else if(value==777){
|
2018-10-18 23:18:12 -03:00
|
|
|
reinit_time_sync()
|
2018-11-11 16:11:41 -04:00
|
|
|
}
|
|
|
|
} else {
|
2018-11-20 06:26:14 -04:00
|
|
|
if(value==21 ) {
|
2018-11-11 16:11:41 -04:00
|
|
|
BVMSTATE = "STOP"
|
2018-10-18 23:18:12 -03:00
|
|
|
#neighbors.broadcast("cmd", 777)
|
2018-11-11 16:11:41 -04:00
|
|
|
}else if(BVMSTATE!="BARRIERWAIT" and BVMSTATE!="LAUNCH") {
|
2018-11-20 06:26:14 -04:00
|
|
|
if(value==20 and BVMSTATE!="GOHOME") {
|
|
|
|
AUTO_LAUNCH_STATE = "IDLE"
|
|
|
|
resetWP()
|
|
|
|
if(BVMSTATE!=AUTO_LAUNCH_STATE)
|
|
|
|
barrier_set(ROBOTS, "GOHOME", BVMSTATE, 20)
|
|
|
|
#barrier_ready(20)
|
2019-04-10 15:14:19 -03:00
|
|
|
} else if(value==900 and BVMSTATE!="TASK_ALLOCATE"){ # Shapes
|
2018-11-11 16:11:41 -04:00
|
|
|
barrier_set(ROBOTS, "TASK_ALLOCATE", BVMSTATE, 900)
|
|
|
|
#barrier_ready(900)
|
|
|
|
#neighbors.broadcast("cmd", 900)
|
2019-04-10 15:14:19 -03:00
|
|
|
} else if(value==901 and BVMSTATE!="DEPLOY" ){ # Voronoi
|
2018-11-11 16:11:41 -04:00
|
|
|
destroyGraph()
|
|
|
|
barrier_set(ROBOTS, "DEPLOY", BVMSTATE, 901)
|
|
|
|
#barrier_ready(901)
|
|
|
|
#neighbors.broadcast("cmd", 901)
|
|
|
|
} else if(value==902 and BVMSTATE!="WAYPOINT" and BVMSTATE!="TURNEDOFF"){ # Waypoint
|
|
|
|
destroyGraph()
|
|
|
|
barrier_set(ROBOTS, "WAYPOINT", BVMSTATE, 902)
|
|
|
|
#barrier_ready(902)
|
|
|
|
#neighbors.broadcast("cmd", 902)
|
2019-04-10 15:14:19 -03:00
|
|
|
} else if(value==903 and BVMSTATE!="PURSUIT" and BVMSTATE!="TURNEDOFF"){ # Pursuit
|
2018-11-11 16:11:41 -04:00
|
|
|
destroyGraph()
|
2019-04-10 15:14:19 -03:00
|
|
|
barrier_set(ROBOTS, "PURSUIT", BVMSTATE, 903)
|
2018-11-11 16:11:41 -04:00
|
|
|
#barrier_ready(903)
|
|
|
|
#neighbors.broadcast("cmd", 903)
|
|
|
|
} else if(value==904 and BVMSTATE!="IDLE" and BVMSTATE!="TURNEDOFF"){ # idle
|
|
|
|
destroyGraph()
|
|
|
|
resetWP()
|
|
|
|
barrier_set(ROBOTS, "IDLE", BVMSTATE, 904)
|
|
|
|
#barrier_ready(904)
|
|
|
|
#neighbors.broadcast("cmd", 904)
|
|
|
|
}
|
2019-01-08 15:26:38 -04:00
|
|
|
else if(value==555 and BVMSTATE=="YOLO_DEMO"){
|
|
|
|
YOLO_NEI_TARGET = 1
|
|
|
|
} else if(value==556 and BVMSTATE=="YOLO_DEMO"){
|
|
|
|
YOLO_NEI_TARGET = 2
|
|
|
|
}
|
2018-10-18 23:18:12 -03:00
|
|
|
}
|
2018-11-11 16:11:41 -04:00
|
|
|
}
|
2018-10-18 23:18:12 -03:00
|
|
|
})
|
|
|
|
}
|
2018-11-06 05:01:16 -04:00
|
|
|
|
|
|
|
firsttimeinwp = 1
|
2018-11-12 22:07:54 -04:00
|
|
|
WPtab_id = 10
|
2018-11-06 05:01:16 -04:00
|
|
|
function check_rc_wp() {
|
|
|
|
if(firsttimeinwp) {
|
|
|
|
v_wp = stigmergy.create(WP_STIG)
|
|
|
|
storegoal(pose.position.latitude, pose.position.longitude, pose.position.altitude)
|
|
|
|
firsttimeinwp = 0
|
|
|
|
}
|
|
|
|
if(rc_goto.id != -1) {
|
|
|
|
if(rc_goto.id == id) {
|
|
|
|
wpreached = 0
|
|
|
|
storegoal(rc_goto.latitude, rc_goto.longitude, pose.position.altitude)
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
var ls = packWP2i(rc_goto.latitude, rc_goto.longitude, 0)
|
2018-11-12 22:07:54 -04:00
|
|
|
if(rc_goto.id>49) { # Attractor/repulsor table
|
|
|
|
WPtab = v_wp.get(WPtab_id)
|
|
|
|
if(WPtab!=nil)
|
|
|
|
WPtab[rc_goto.id]=ls
|
|
|
|
else {
|
|
|
|
WPtab={}
|
|
|
|
WPtab[rc_goto.id]=ls
|
|
|
|
}
|
|
|
|
v_wp.put(WPtab_id,WPtab)
|
2018-11-16 13:00:36 -04:00
|
|
|
} else # Individual waypoint
|
2018-11-12 22:07:54 -04:00
|
|
|
v_wp.put(rc_goto.id,ls)
|
2018-11-06 05:01:16 -04:00
|
|
|
reset_rc()
|
|
|
|
}
|
2018-11-11 16:11:41 -04:00
|
|
|
} else
|
|
|
|
v_wp.get(0)
|
2018-11-06 05:01:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function resetWP() {
|
|
|
|
firsttimeinwp = 1
|
|
|
|
if(v_wp!=nil)
|
|
|
|
v_wp.foreach(function(key, value, robot){v_wp[key]=nil})
|
|
|
|
}
|