Psi Swarm robot library version 0.9

Dependents:   PsiSwarm_V9_Blank

Fork of PsiSwarmV9 by James Hilder

Committer:
jah128
Date:
Tue May 30 21:03:18 2017 +0000
Revision:
14:2f1ad77d281e
Parent:
12:878c6e9d9e60
Child:
19:3e3b03d80ea3
Initial version (fork of version 0.8)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jah128 12:878c6e9d9e60 1 /* University of York Robotics Laboratory PsiSwarm Library: Animations Source File
jah128 6:b340a527add9 2 *
jah128 14:2f1ad77d281e 3 * Copyright 2017 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 12:878c6e9d9e60 11 * Library of simple predetermined movements and LED animations
jah128 0:d6269d17c8cf 12 *
jah128 12:878c6e9d9e60 13 * File: animations.cpp
jah128 12:878c6e9d9e60 14 * [Was dances.cpp in version 0.7]
jah128 0:d6269d17c8cf 15 *
jah128 0:d6269d17c8cf 16 * (C) Dept. Electronics & Computer Science, University of York
jah128 0:d6269d17c8cf 17 * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis
jah128 0:d6269d17c8cf 18 *
jah128 14:2f1ad77d281e 19 * PsiSwarm Library Version: 0.9
jah128 0:d6269d17c8cf 20 *
jah128 14:2f1ad77d281e 21 * June 2017
jah128 0:d6269d17c8cf 22 *
jah128 0:d6269d17c8cf 23 *
jah128 0:d6269d17c8cf 24 */
jah128 0:d6269d17c8cf 25
jah128 0:d6269d17c8cf 26
jah128 0:d6269d17c8cf 27 #include "psiswarm.h"
jah128 0:d6269d17c8cf 28
jah128 12:878c6e9d9e60 29 char hold_colour = 1;
jah128 12:878c6e9d9e60 30 //
jah128 12:878c6e9d9e60 31 void Animations::set_colour(char colour)
jah128 12:878c6e9d9e60 32 {
jah128 12:878c6e9d9e60 33 hold_colour = colour;
jah128 12:878c6e9d9e60 34 }
jah128 12:878c6e9d9e60 35
jah128 12:878c6e9d9e60 36 void Animations::led_run1()
jah128 12:878c6e9d9e60 37 {
jah128 12:878c6e9d9e60 38 if(animation_counter == 0)led.save_led_states();
jah128 12:878c6e9d9e60 39 char led_pattern = 0x0;
jah128 12:878c6e9d9e60 40 if(animation_counter < 16){
jah128 12:878c6e9d9e60 41 switch(animation_counter % 4){
jah128 12:878c6e9d9e60 42 case 0:
jah128 12:878c6e9d9e60 43 led_pattern = 0x10;
jah128 12:878c6e9d9e60 44 break;
jah128 12:878c6e9d9e60 45 case 1:
jah128 12:878c6e9d9e60 46 led_pattern = 0x28;
jah128 12:878c6e9d9e60 47 break;
jah128 12:878c6e9d9e60 48 case 2:
jah128 12:878c6e9d9e60 49 led_pattern = 0x44;
jah128 12:878c6e9d9e60 50 break;
jah128 12:878c6e9d9e60 51 case 3:
jah128 12:878c6e9d9e60 52 led_pattern = 0x83;
jah128 12:878c6e9d9e60 53 break;
jah128 12:878c6e9d9e60 54 }
jah128 12:878c6e9d9e60 55 }
jah128 12:878c6e9d9e60 56 if(animation_counter == 16 || animation_counter == 18 || animation_counter == 20) led_pattern = 0x01;
jah128 12:878c6e9d9e60 57 char green_state = 0;
jah128 12:878c6e9d9e60 58 char red_state = 0;
jah128 12:878c6e9d9e60 59 if(hold_colour % 2 == 1) red_state = led_pattern;
jah128 12:878c6e9d9e60 60 if(hold_colour > 1) green_state = led_pattern;
jah128 12:878c6e9d9e60 61 led.set_leds(green_state,red_state);
jah128 12:878c6e9d9e60 62 animation_counter++;
jah128 12:878c6e9d9e60 63 if(animation_counter < 21) {
jah128 12:878c6e9d9e60 64 animation_timeout.attach(this, &Animations::led_run1, 0.05f);
jah128 12:878c6e9d9e60 65 } else {
jah128 12:878c6e9d9e60 66 animation_counter = 0;
jah128 12:878c6e9d9e60 67 led.restore_led_states();
jah128 12:878c6e9d9e60 68 }
jah128 12:878c6e9d9e60 69 }
jah128 0:d6269d17c8cf 70
jah128 11:312663037b8c 71 //Do a simple wiggle
jah128 12:878c6e9d9e60 72 void Animations::vibrate(void)
jah128 0:d6269d17c8cf 73 {
jah128 12:878c6e9d9e60 74 if(animation_counter == 0)led.save_led_states();
jah128 12:878c6e9d9e60 75 if(animation_counter % 2 == 0) {
jah128 9:dde9e21030eb 76 led.set_leds(0xC7,0x00);
jah128 8:6c92789d5f87 77 motors.turn(1.0);
jah128 0:d6269d17c8cf 78 } else {
jah128 9:dde9e21030eb 79 led.set_leds(0x00,0xC7);
jah128 8:6c92789d5f87 80 motors.turn(-1.0);
jah128 0:d6269d17c8cf 81 }
jah128 12:878c6e9d9e60 82 animation_counter++;
jah128 0:d6269d17c8cf 83
jah128 12:878c6e9d9e60 84 if(animation_counter < 14) {
jah128 0:d6269d17c8cf 85 float wiggle_timeout_period = 0.06;
jah128 0:d6269d17c8cf 86 //Move less on first 'wiggle' so that we stay in roughly the same place!
jah128 12:878c6e9d9e60 87 if(animation_counter == 0) wiggle_timeout_period = 0.03;
jah128 12:878c6e9d9e60 88 animation_timeout.attach(this, &Animations::vibrate, wiggle_timeout_period);
jah128 0:d6269d17c8cf 89 } else {
jah128 12:878c6e9d9e60 90 animation_counter = 0;
jah128 8:6c92789d5f87 91 motors.brake();
jah128 9:dde9e21030eb 92 led.restore_led_states();
jah128 0:d6269d17c8cf 93 }
jah128 0:d6269d17c8cf 94 }