Skip to content

Commit 6fc9305

Browse files
authored
Merge pull request buzz-lang#16 from ulrichdah/master
New behaviors for the paper experiments (crazyflies)
2 parents 0015fa9 + bdb4ea3 commit 6fc9305

12 files changed

Lines changed: 470 additions & 4 deletions

File tree

src/cmake/Crazyflie.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ set(PROCESSOR "-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16")
159159

160160
set(DEFS "-DCRAZYFLIE_FW -DARM_MATH_CM4 -D__FPU_PRESENT=1 -D__TARGET_FPU_VFP -DSTM32F4XX -DSTM32F40_41xxx -DHSE_VALUE=8000000 -DUSE_STDPERIPH_DRIVER -DUSE_RADIOLINK_CRTP -DENABLE_UART -DBOARD_REV_${REV} -DESTIMATOR_NAME=${ESTIMATOR}Estimator -DCONTROLLER_NAME=ControllerType${CONTROLLER} -DPOWER_DISTRIBUTION_TYPE_${POWER_DISTRIBUTION}")
161161

162-
set(SENSOR_CONFIG "-DSENSORS_IGNORE_BAROMETER_FAIL -DSENSOR_INCLUDED_MPU9250_LPS25H -DSENSORS_FORCE=SensorImplementation_mpu9250_lps25h -DSENSOR_INCLUDED_BMI088_BMP388")
162+
set(SENSOR_CONFIG "-DSENSORS_IGNORE_BAROMETER_FAIL -DSENSOR_INCLUDED_MPU9250_LPS25H -DSENSOR_INCLUDED_BMI088_BMP388")
163163
#-DSENSOR_INCLUDED_BMI088_BMP388 -DSENSOR_INCLUDED_MPU9250_LPS25H
164164

165165
#set(FORCEDEVICE "-DDEVICE_TYPE_STRING_FORCE=CF20 -DDECK_FORCE=bcDWM1000")

src/crazyflie/behaviors/buzz_scripts/lostPackets.bst

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# EXPECTED BEHAVIOR :
2+
#
3+
#
4+
5+
experiment = 2
6+
counter = 0
7+
received_packets = 0
8+
NB_STEPS = 20
9+
10+
function init() {
11+
neighbors.listen("toto",
12+
function(vid, value, rid) {
13+
received_packets = received_packets + 1
14+
}
15+
)
16+
neighbors.listen("rina",
17+
function(vid, value, rid) {
18+
received_packets = received_packets + 1
19+
}
20+
)
21+
}
22+
23+
function step() {
24+
if (counter < NB_STEPS and id == 0) {
25+
counter = counter + 1
26+
if (counter % 2 == 0) {
27+
neighbors.broadcast("rina", counter)
28+
} else {
29+
neighbors.broadcast("toto", counter)
30+
}
31+
if (experiment == 0){
32+
delay(1000)
33+
} else if (experiment == 1) {
34+
delay(500)
35+
} else {
36+
37+
}
38+
} else {
39+
show(received_packets)
40+
}
41+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
delay
2+
takeoff
3+
land
4+
spin
5+
hover
6+
goTo
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# EXPECTED BEHAVIOR :
2+
#
3+
# Crazyflies with id:
4+
# > 0: Takeoff on start and hover at 300 mm (with obstacles avoidance) until it receives a landing message
5+
# = 0: Takeoff on start, spin 5 times (with obstacles avoidance), broadcats a landing message and land itself.
6+
#
7+
# To work properly, the crazyflies need to be equiped with a flow deck and a multiranger (necessary for the obstacles avoidance)
8+
9+
offset_x = 0
10+
offset_y = 0
11+
stop = 0
12+
done = 0
13+
HEIGHT = 600
14+
s_hover = swarm.create(0)
15+
s_explore = swarm.create(1)
16+
17+
function init() {
18+
neighbors.listen("pos",
19+
function(vid, value, rid) {
20+
stop = 0
21+
neighbors.foreach(function(r_id, data) {
22+
if (neighbors.get(rid).distance < 500) {
23+
HEIGHT = HEIGHT + 200
24+
}
25+
})
26+
}
27+
)
28+
neighbors.listen("land",
29+
function(vid, value, rid) {
30+
land(HEIGHT, 10)
31+
done = 1
32+
}
33+
)
34+
s_explore.select(id >= 10)
35+
s_hover.select(id < 10)
36+
if (id >= 10) {
37+
neighbors.ignore("land")
38+
stop = 1
39+
} else {
40+
neighbors.ignore("pos")
41+
}
42+
takeoff(HEIGHT, 10)
43+
}
44+
45+
function step() {
46+
if (done == 0) {
47+
s_hover.exec(hover_behavior)
48+
s_explore.exec(move_behavior)
49+
}
50+
}
51+
52+
# ========================================
53+
# = CLOSURE DEFINITIONS =
54+
# ========================================
55+
56+
function hover_behavior() {
57+
hover(HEIGHT)
58+
neighbors.broadcast("pos", 1)
59+
}
60+
61+
function move_behavior() {
62+
if (stop == 0) {
63+
goTo(3000 + 100 * offset_x, 2000 + 200 * offset_y, HEIGHT)
64+
offset_x = offset_x + 1
65+
if (offset_x % 2 == 0) {
66+
offset_y = offset_y + 1
67+
}
68+
if (offset_x == 7) {
69+
neighbors.broadcast("land", 1)
70+
land(HEIGHT, 10)
71+
stop = 1
72+
done = 1
73+
}
74+
} else {
75+
hover(HEIGHT)
76+
}
77+
}

src/crazyflie/behaviors/buzz_scripts/stigmergyTime.bst

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# EXPECTED BEHAVIOR :
2+
#
3+
#
4+
5+
experiment = 1
6+
counter = 0
7+
NB_STEPS = 10
8+
9+
function init() {
10+
stig = stigmergy.create(0)
11+
if (id == 0) {
12+
stig.put("a", 40)
13+
stig.put("a", 42)
14+
} else if (experiment == 1) {
15+
stig.put("a", 20)
16+
}
17+
}
18+
19+
function step() {
20+
if (counter < NB_STEPS) {
21+
val = stig.get("a")
22+
counter = counter + 1
23+
if (val == 42) {
24+
show(42)
25+
} else if (val == 20) {
26+
show(20)
27+
} else {
28+
show(0)
29+
}
30+
} else {
31+
show(90)
32+
}
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <bbzsymbols.h>
2+
#include <bittybuzz/bbzutil.h>
3+
#include <bittybuzz/util/bbzstring.h>
4+
#include <bittybuzz/bbzvm.h>
5+
#include <bbzcrazyflie.h>
6+
#include "led.h"
7+
#include "FreeRTOS.h"
8+
#include "task.h"
9+
#include "FreeRTOSConfig.h"
10+
#include "debug.h"
11+
12+
void bbz_led() {
13+
bbzvm_assert_lnum(2);
14+
#ifndef DEBUG
15+
uint8_t color = (uint8_t)bbzheap_obj_at(bbzvm_locals_at(1))->i.value;
16+
uint8_t value = (uint8_t)bbzheap_obj_at(bbzvm_locals_at(2))->i.value;
17+
ledSet(color?LINK_LED:LINK_DOWN_LED, value);
18+
#endif
19+
bbzvm_ret0();
20+
}
21+
22+
void bbz_delay() {
23+
bbzvm_assert_lnum(1);
24+
#ifndef DEBUG
25+
uint16_t d = (uint16_t)bbzheap_obj_at(bbzvm_locals_at(1))->i.value;
26+
vTaskDelay(M2T(d));
27+
#endif
28+
bbzvm_ret0();
29+
}
30+
31+
void bbz_print() {
32+
bbzvm_assert_lnum(1);
33+
#ifndef DEBUG
34+
uint16_t d = (uint16_t)bbzheap_obj_at(bbzvm_locals_at(1))->i.value;
35+
DEBUG_PRINT("PRINT: %d\n", d);
36+
#endif
37+
bbzvm_ret0();
38+
}
39+
40+
void setup() {
41+
// bbzvm_function_register(BBZSTRING_ID(led), bbz_led);
42+
bbzvm_function_register(BBZSTRING_ID(delay), bbz_delay);
43+
bbzvm_function_register(BBZSTRING_ID(show), bbz_print);
44+
}
45+
46+
int main() {
47+
bbz_init(setup);
48+
49+
return 0;
50+
}

0 commit comments

Comments
 (0)