Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of PsiSwarmV9 by
dances.cpp@8:6c92789d5f87, 2016-10-16 (annotated)
- Committer:
- jah128
- Date:
- Sun Oct 16 12:54:33 2016 +0000
- Revision:
- 8:6c92789d5f87
- Parent:
- 6:b340a527add9
- Child:
- 9:dde9e21030eb
Renamed to V8 [C++ version]; converted display, eprom and motor classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:d6269d17c8cf | 1 | /* University of York Robotics Laboratory PsiSwarm Library: Dances Source File |
jah128 | 6:b340a527add9 | 2 | * |
jah128 | 6:b340a527add9 | 3 | * Copyright 2016 University of York |
jah128 | 6:b340a527add9 | 4 | * |
jah128 | 6:b340a527add9 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. |
jah128 | 6:b340a527add9 | 6 | * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
jah128 | 6:b340a527add9 | 7 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS |
jah128 | 6:b340a527add9 | 8 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jah128 | 6:b340a527add9 | 9 | * See the License for the specific language governing permissions and limitations under the License. |
jah128 | 0:d6269d17c8cf | 10 | * |
jah128 | 0:d6269d17c8cf | 11 | * Library of simple predetermined movements |
jah128 | 0:d6269d17c8cf | 12 | * |
jah128 | 0:d6269d17c8cf | 13 | * File: dances.cpp |
jah128 | 0:d6269d17c8cf | 14 | * |
jah128 | 0:d6269d17c8cf | 15 | * (C) Dept. Electronics & Computer Science, University of York |
jah128 | 0:d6269d17c8cf | 16 | * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:d6269d17c8cf | 17 | * |
jah128 | 5:3cdd1a37cdd7 | 18 | * PsiSwarm Library Version: 0.7 |
jah128 | 0:d6269d17c8cf | 19 | * |
jah128 | 5:3cdd1a37cdd7 | 20 | * October 2016 |
jah128 | 0:d6269d17c8cf | 21 | * |
jah128 | 0:d6269d17c8cf | 22 | * |
jah128 | 0:d6269d17c8cf | 23 | */ |
jah128 | 0:d6269d17c8cf | 24 | |
jah128 | 0:d6269d17c8cf | 25 | |
jah128 | 0:d6269d17c8cf | 26 | #include "psiswarm.h" |
jah128 | 0:d6269d17c8cf | 27 | |
jah128 | 0:d6269d17c8cf | 28 | char vibrate_counter = 0; |
jah128 | 0:d6269d17c8cf | 29 | Timeout dances_timeout; |
jah128 | 0:d6269d17c8cf | 30 | |
jah128 | 0:d6269d17c8cf | 31 | ///Do a simple wiggle |
jah128 | 0:d6269d17c8cf | 32 | void vibrate(void) |
jah128 | 0:d6269d17c8cf | 33 | { |
jah128 | 0:d6269d17c8cf | 34 | if(vibrate_counter == 0)save_led_states(); |
jah128 | 0:d6269d17c8cf | 35 | if(vibrate_counter % 2 == 0) { |
jah128 | 0:d6269d17c8cf | 36 | set_leds(0xC7,0x00); |
jah128 | 8:6c92789d5f87 | 37 | motors.turn(1.0); |
jah128 | 0:d6269d17c8cf | 38 | } else { |
jah128 | 0:d6269d17c8cf | 39 | set_leds(0x00,0xC7); |
jah128 | 8:6c92789d5f87 | 40 | motors.turn(-1.0); |
jah128 | 0:d6269d17c8cf | 41 | } |
jah128 | 0:d6269d17c8cf | 42 | vibrate_counter++; |
jah128 | 0:d6269d17c8cf | 43 | |
jah128 | 0:d6269d17c8cf | 44 | if(vibrate_counter < 14) { |
jah128 | 0:d6269d17c8cf | 45 | float wiggle_timeout_period = 0.06; |
jah128 | 0:d6269d17c8cf | 46 | //Move less on first 'wiggle' so that we stay in roughly the same place! |
jah128 | 0:d6269d17c8cf | 47 | if(vibrate_counter == 0) wiggle_timeout_period = 0.03; |
jah128 | 0:d6269d17c8cf | 48 | dances_timeout.attach(vibrate, wiggle_timeout_period); |
jah128 | 0:d6269d17c8cf | 49 | } else { |
jah128 | 0:d6269d17c8cf | 50 | vibrate_counter = 0; |
jah128 | 8:6c92789d5f87 | 51 | motors.brake(); |
jah128 | 0:d6269d17c8cf | 52 | restore_led_states(); |
jah128 | 0:d6269d17c8cf | 53 | } |
jah128 | 0:d6269d17c8cf | 54 | } |