![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Bluetooth communication for flocking.
Fork of BeautifulMemeProject by
PsiSwarm/dances.cpp@27:7eb032772bc2, 2016-01-31 (annotated)
- Committer:
- alanmillard
- Date:
- Sun Jan 31 15:14:54 2016 +0000
- Revision:
- 27:7eb032772bc2
- Parent:
- 10:1b09d4bb847b
Flocking seems to work better now, however the robot controller sometimes "crashes" (unsure why).
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 10:1b09d4bb847b | 1 | /* University of York Robotics Laboratory PsiSwarm Library: Dances Source File |
jah128 | 10:1b09d4bb847b | 2 | * |
jah128 | 10:1b09d4bb847b | 3 | * Library of simple predetermined movements |
jah128 | 10:1b09d4bb847b | 4 | * |
jah128 | 10:1b09d4bb847b | 5 | * File: dances.cpp |
jah128 | 10:1b09d4bb847b | 6 | * |
jah128 | 10:1b09d4bb847b | 7 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 10:1b09d4bb847b | 8 | * James Hilder, Alan Millard, Homero Elizondo, Jon Timmis |
jah128 | 10:1b09d4bb847b | 9 | * |
jah128 | 10:1b09d4bb847b | 10 | * PsiSwarm Library Version: 0.3 |
jah128 | 10:1b09d4bb847b | 11 | * |
jah128 | 10:1b09d4bb847b | 12 | * October 2015 |
jah128 | 10:1b09d4bb847b | 13 | * |
jah128 | 10:1b09d4bb847b | 14 | */ |
jah128 | 10:1b09d4bb847b | 15 | |
jah128 | 10:1b09d4bb847b | 16 | |
jah128 | 10:1b09d4bb847b | 17 | #include "psiswarm.h" |
jah128 | 10:1b09d4bb847b | 18 | |
jah128 | 10:1b09d4bb847b | 19 | char vibrate_counter = 0; |
jah128 | 10:1b09d4bb847b | 20 | Timeout dances_timeout; |
jah128 | 10:1b09d4bb847b | 21 | |
jah128 | 10:1b09d4bb847b | 22 | ///Do a simple wiggle |
jah128 | 10:1b09d4bb847b | 23 | void vibrate(void) |
jah128 | 10:1b09d4bb847b | 24 | { |
jah128 | 10:1b09d4bb847b | 25 | if(vibrate_counter == 0)save_led_states(); |
jah128 | 10:1b09d4bb847b | 26 | if(vibrate_counter % 2 == 0) { |
jah128 | 10:1b09d4bb847b | 27 | set_leds(0xC7,0x00); |
jah128 | 10:1b09d4bb847b | 28 | turn(1.0); |
jah128 | 10:1b09d4bb847b | 29 | } else { |
jah128 | 10:1b09d4bb847b | 30 | set_leds(0x00,0xC7); |
jah128 | 10:1b09d4bb847b | 31 | turn(-1.0); |
jah128 | 10:1b09d4bb847b | 32 | } |
jah128 | 10:1b09d4bb847b | 33 | vibrate_counter++; |
jah128 | 10:1b09d4bb847b | 34 | |
jah128 | 10:1b09d4bb847b | 35 | if(vibrate_counter < 14) { |
jah128 | 10:1b09d4bb847b | 36 | float wiggle_timeout_period = 0.06; |
jah128 | 10:1b09d4bb847b | 37 | //Move less on first 'wiggle' so that we stay in roughly the same place! |
jah128 | 10:1b09d4bb847b | 38 | if(vibrate_counter == 0) wiggle_timeout_period = 0.03; |
jah128 | 10:1b09d4bb847b | 39 | dances_timeout.attach(vibrate, wiggle_timeout_period); |
jah128 | 10:1b09d4bb847b | 40 | } else { |
jah128 | 10:1b09d4bb847b | 41 | vibrate_counter = 0; |
jah128 | 10:1b09d4bb847b | 42 | brake(); |
jah128 | 10:1b09d4bb847b | 43 | restore_led_states(); |
jah128 | 10:1b09d4bb847b | 44 | } |
jah128 | 10:1b09d4bb847b | 45 | } |