PsiSwarm Library  0.8
animations.cpp
1 /* University of York Robotics Laboratory PsiSwarm Library: Animations Source File
2  *
3  * Copyright 2016 University of York
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS
8  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9  * See the License for the specific language governing permissions and limitations under the License.
10  *
11  * Library of simple predetermined movements and LED animations
12  *
13  * File: animations.cpp
14  * [Was dances.cpp in version 0.7]
15  *
16  * (C) Dept. Electronics & Computer Science, University of York
17  * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis
18  *
19  * PsiSwarm Library Version: 0.8
20  *
21  * October 2016
22  *
23  *
24  */
25 
26 
27 #include "psiswarm.h"
28 
29 char hold_colour = 1;
30 //
31 void Animations::set_colour(char colour)
32 {
33  hold_colour = colour;
34 }
35 
37 {
38  if(animation_counter == 0)led.save_led_states();
39  char led_pattern = 0x0;
40  if(animation_counter < 16){
41  switch(animation_counter % 4){
42  case 0:
43  led_pattern = 0x10;
44  break;
45  case 1:
46  led_pattern = 0x28;
47  break;
48  case 2:
49  led_pattern = 0x44;
50  break;
51  case 3:
52  led_pattern = 0x83;
53  break;
54  }
55  }
56  if(animation_counter == 16 || animation_counter == 18 || animation_counter == 20) led_pattern = 0x01;
57  char green_state = 0;
58  char red_state = 0;
59  if(hold_colour % 2 == 1) red_state = led_pattern;
60  if(hold_colour > 1) green_state = led_pattern;
61  led.set_leds(green_state,red_state);
62  animation_counter++;
63  if(animation_counter < 21) {
64  animation_timeout.attach(this, &Animations::led_run1, 0.05f);
65  } else {
66  animation_counter = 0;
67  led.restore_led_states();
68  }
69 }
70 
71 //Do a simple wiggle
73 {
74  if(animation_counter == 0)led.save_led_states();
75  if(animation_counter % 2 == 0) {
76  led.set_leds(0xC7,0x00);
77  motors.turn(1.0);
78  } else {
79  led.set_leds(0x00,0xC7);
80  motors.turn(-1.0);
81  }
82  animation_counter++;
83 
84  if(animation_counter < 14) {
85  float wiggle_timeout_period = 0.06;
86  //Move less on first 'wiggle' so that we stay in roughly the same place!
87  if(animation_counter == 0) wiggle_timeout_period = 0.03;
88  animation_timeout.attach(this, &Animations::vibrate, wiggle_timeout_period);
89  } else {
90  animation_counter = 0;
91  motors.brake();
92  led.restore_led_states();
93  }
94 }
void set_leds(char green, char red)
Definition: led.cpp:38
void led_run1(void)
Definition: animations.cpp:36
void brake(void)
Definition: motors.cpp:56
void turn(float speed)
Definition: motors.cpp:92
void save_led_states(void)
Definition: led.cpp:112
void set_colour(char colour)
Definition: animations.cpp:31
void restore_led_states(void)
Definition: led.cpp:118
void vibrate(void)
Definition: animations.cpp:72