![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Random walk for psiSwarm
Dependencies: PsiSwarmV8_CPP mbed
Fork of PsiSwarm_V8_Blank_CPP by
main.cpp@2:5d37e5fd7141, 2016-10-17 (annotated)
- Committer:
- jah128
- Date:
- Mon Oct 17 13:20:23 2016 +0000
- Revision:
- 2:5d37e5fd7141
- Parent:
- 0:9c0ccd879613
- Child:
- 3:5d11c69d95df
Updated copyright message
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 0:9c0ccd879613 | 1 | /*********************************************************************** |
jah128 | 0:9c0ccd879613 | 2 | ** ██████╗ ███████╗██╗███████╗██╗ ██╗ █████╗ ██████╗ ███╗ ███╗ ** |
jah128 | 0:9c0ccd879613 | 3 | ** ██╔══██╗██╔════╝██║██╔════╝██║ ██║██╔══██╗██╔══██╗████╗ ████║ ** |
jah128 | 0:9c0ccd879613 | 4 | ** ██████╔╝███████╗██║███████╗██║ █╗ ██║███████║██████╔╝██╔████╔██║ ** |
jah128 | 0:9c0ccd879613 | 5 | ** ██╔═══╝ ╚════██║██║╚════██║██║███╗██║██╔══██║██╔══██╗██║╚██╔╝██║ ** |
jah128 | 0:9c0ccd879613 | 6 | ** ██║ ███████║██║███████║╚███╔███╔╝██║ ██║██║ ██║██║ ╚═╝ ██║ ** |
jah128 | 0:9c0ccd879613 | 7 | ** ╚═╝ ╚══════╝╚═╝╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ** |
jah128 | 0:9c0ccd879613 | 8 | ************************************************************************ |
jah128 | 2:5d37e5fd7141 | 9 | ** Copyright 2016 University of York - See notice at end of file ** |
jah128 | 0:9c0ccd879613 | 10 | ***********************************************************************/ |
jah128 | 0:9c0ccd879613 | 11 | |
jah128 | 2:5d37e5fd7141 | 12 | /// PsiSwarm C++ Blank Example Code - Version 0.8 |
jah128 | 0:9c0ccd879613 | 13 | /// James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis |
jah128 | 0:9c0ccd879613 | 14 | |
jah128 | 0:9c0ccd879613 | 15 | /// Include main.h - this includes psiswarm.h all the other necessary core files |
jah128 | 0:9c0ccd879613 | 16 | #include "main.h" |
jah128 | 0:9c0ccd879613 | 17 | |
jah128 | 2:5d37e5fd7141 | 18 | Psiswarm psi; |
jah128 | 2:5d37e5fd7141 | 19 | |
jah128 | 0:9c0ccd879613 | 20 | char * program_name = "Blank"; |
jah128 | 0:9c0ccd879613 | 21 | char * author_name = "YRL"; |
jah128 | 2:5d37e5fd7141 | 22 | char * version_name = "0.80"; |
jah128 | 0:9c0ccd879613 | 23 | |
jah128 | 2:5d37e5fd7141 | 24 | ///User code loop: This is where user code should go; it is run as an infinite loop |
jah128 | 0:9c0ccd879613 | 25 | void user_code_loop() |
jah128 | 0:9c0ccd879613 | 26 | { |
jah128 | 2:5d37e5fd7141 | 27 | // Example: |
jah128 | 2:5d37e5fd7141 | 28 | // animations.led_run1(); |
jah128 | 2:5d37e5fd7141 | 29 | // wait(1.2); |
jah128 | 0:9c0ccd879613 | 30 | } |
jah128 | 0:9c0ccd879613 | 31 | |
jah128 | 0:9c0ccd879613 | 32 | ///Place user code here that should be run after initialisation but before the main loop |
jah128 | 0:9c0ccd879613 | 33 | void user_code_setup() |
jah128 | 0:9c0ccd879613 | 34 | { |
jah128 | 0:9c0ccd879613 | 35 | wait(1); |
jah128 | 0:9c0ccd879613 | 36 | display.clear_display(); |
jah128 | 0:9c0ccd879613 | 37 | display.set_position(0,0); |
jah128 | 0:9c0ccd879613 | 38 | display.write_string("No Code"); |
jah128 | 0:9c0ccd879613 | 39 | } |
jah128 | 0:9c0ccd879613 | 40 | |
jah128 | 0:9c0ccd879613 | 41 | /// Code goes here to handle what should happen when the user switch is pressed |
jah128 | 0:9c0ccd879613 | 42 | void handle_switch_event(char switch_state) |
jah128 | 0:9c0ccd879613 | 43 | { |
jah128 | 0:9c0ccd879613 | 44 | /// Switch_state = 1 if up is pressed, 2 if down is pressed, 4 if left is pressed, 8 if right is pressed and 16 if the center button is pressed |
jah128 | 0:9c0ccd879613 | 45 | /// NB For maximum compatability it is recommended to minimise reliance on center button press |
jah128 | 0:9c0ccd879613 | 46 | } |
jah128 | 0:9c0ccd879613 | 47 | |
jah128 | 0:9c0ccd879613 | 48 | void handle_user_serial_message(char * message, char length, char interface) |
jah128 | 0:9c0ccd879613 | 49 | { |
jah128 | 0:9c0ccd879613 | 50 | // This is where user code for handling a (non-system) serial message should go |
jah128 | 0:9c0ccd879613 | 51 | // |
jah128 | 0:9c0ccd879613 | 52 | // message = pointer to message char array |
jah128 | 0:9c0ccd879613 | 53 | // length = length of message |
jah128 | 0:9c0ccd879613 | 54 | // interface = 0 for PC serial connection, 1 for Bluetooth |
jah128 | 0:9c0ccd879613 | 55 | } |
jah128 | 0:9c0ccd879613 | 56 | |
jah128 | 0:9c0ccd879613 | 57 | /// The main routine: it is recommended to leave this function alone and add user code to the above functions |
jah128 | 0:9c0ccd879613 | 58 | int main() |
jah128 | 0:9c0ccd879613 | 59 | { |
jah128 | 2:5d37e5fd7141 | 60 | psi.init(); ///psi.init() in psiswarm.cpp sets up the robot |
jah128 | 2:5d37e5fd7141 | 61 | user_code_setup(); ///run user code setup block |
jah128 | 2:5d37e5fd7141 | 62 | user_code_running = 1; ///nb. user code can be paused by external commands sent from PC\BT interfaces |
jah128 | 0:9c0ccd879613 | 63 | while(1) { |
jah128 | 2:5d37e5fd7141 | 64 | user_code_loop(); ///run user code |
jah128 | 0:9c0ccd879613 | 65 | } |
jah128 | 2:5d37e5fd7141 | 66 | } |
jah128 | 2:5d37e5fd7141 | 67 | |
jah128 | 2:5d37e5fd7141 | 68 | |
jah128 | 2:5d37e5fd7141 | 69 | /*********************************************************************** |
jah128 | 2:5d37e5fd7141 | 70 | ** Copyright 2016 University of York ** |
jah128 | 2:5d37e5fd7141 | 71 | ** ** |
jah128 | 2:5d37e5fd7141 | 72 | ** Licensed under the Apache License, Version 2.0 (the "License") ** |
jah128 | 2:5d37e5fd7141 | 73 | ** You may not use this file except in compliance with the License. ** |
jah128 | 2:5d37e5fd7141 | 74 | ** You may obtain a copy of the License at ** |
jah128 | 2:5d37e5fd7141 | 75 | ** http://www.apache.org/licenses/LICENSE-2.0 Unless required by ** |
jah128 | 2:5d37e5fd7141 | 76 | ** applicable law or agreed to in writing, software distributed under ** |
jah128 | 2:5d37e5fd7141 | 77 | ** under the License is distributed on an "AS IS" BASIS WITHOUT ** |
jah128 | 2:5d37e5fd7141 | 78 | ** WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** |
jah128 | 2:5d37e5fd7141 | 79 | ** See the License for the specific language governing permissions ** |
jah128 | 2:5d37e5fd7141 | 80 | ** and limitations under the License. ** |
jah128 | 2:5d37e5fd7141 | 81 | ***********************************************************************/ |