Psi Swarm robot library version 0.9
Fork of PsiSwarmV8_CPP by
Diff: psiswarm.cpp
- Revision:
- 12:878c6e9d9e60
- Parent:
- 11:312663037b8c
- Child:
- 13:adbd827234a4
--- a/psiswarm.cpp Sun Oct 16 21:06:15 2016 +0000 +++ b/psiswarm.cpp Mon Oct 17 13:09:10 2016 +0000 @@ -1,4 +1,4 @@ -/* University of York Robotics Laboratory PsiSwarm Library: PsiSwarm Core Source File +/* University of York Robotics Laboratory PsiSwarm Library: PsiSwarm C++ Core Source File * * Copyright 2016 University of York * @@ -13,7 +13,7 @@ * (C) Dept. Electronics & Computer Science, University of York * James Hilder, Alan Millard, Alexander Horsfield, Homero Elizondo, Jon Timmis * - * PsiSwarm Library Version: 0.7 + * PsiSwarm Library Version: 0.8 * * October 2016 * @@ -32,7 +32,8 @@ Sound sound; Setup i2c_setup; Demo demo; -Dances dances; +Animations animations; +Basic basic; //Setup MBED connections to PsiSwarm Robot Serial pc(USBTX,USBRX); @@ -164,11 +165,11 @@ * * Set up the GPIO expansion ICs, launch demo mode if button is held */ -void init() +void Psiswarm::init() { firmware_version=0; timer_minute_count = 0; - timer_ticker.attach(&IF_update_minutes, 300); + timer_ticker.attach(this,&Psiswarm::IF_update_minutes, 300); uptime.start(); primary_i2c.frequency(400000); serial.setup_serial_interfaces(); @@ -200,7 +201,7 @@ debug("- WARNING: Check firmware to enable robot features"); } if(ENABLE_BASIC == 1) { - read_list_of_file_names(); + basic.read_list_of_file_names(); if(psi_basic_file_count == 0) { debug("- No PsiBasic files found\n"); } else use_flash_basic = 1; @@ -243,7 +244,7 @@ char demo_on = 0; if(ENABLE_DEMO == 1 && switchstate > 0) demo_on=1; display.init_display(demo_on); - event_handler.attach_us(&IF_handle_events, 1000); + event_handler.attach_us(this,&Psiswarm::IF_handle_events, 1000); if(demo_on > 0) { debug("- Demo mode button is pressed\n"); wait(1.0); @@ -253,13 +254,13 @@ } } -void IF_update_minutes() +void Psiswarm::IF_update_minutes() { uptime.reset(); timer_minute_count += 5; } -void IF_handle_events() +void Psiswarm::IF_handle_events() { // This is the main 'operating system' thread that handles events from robot stimuli // By default it is run every 1ms and checks if there are events to handle @@ -286,7 +287,7 @@ } } -void IF_update_encoders() +void Psiswarm::IF_update_encoders() { char rwep = previous_wheel_encoder_byte >> 2; char rwe = wheel_encoder_byte >> 2; @@ -300,11 +301,11 @@ if(left_encoder % 100 == 0) pc.printf("L:%d\n",left_encoder); } -void IF_update_user_id() +void Psiswarm::IF_update_user_id() { } -void IF_update_switch() +void Psiswarm::IF_update_switch() { // The user switch has changed state // In this implementation we will only act on positive changes (rising edges) @@ -314,13 +315,13 @@ else handle_switch_event(positive_change); } -void reset_encoders() +void Psiswarm::reset_encoders() { left_encoder = 0; right_encoder = 0; } -void debug(const char* format, ...) +void Psiswarm::debug(const char* format, ...) { char buffer[256]; if (debug_mode) { @@ -334,24 +335,24 @@ } } -float get_uptime(void) +float Psiswarm::get_uptime(void) { return uptime.read() + (timer_minute_count * 60); } -void pause_user_code(float period) +void Psiswarm::pause_user_code(float period) { user_code_restore_mode = user_code_running; user_code_running = 0; - pause_usercode_timeout.attach(&IF_end_pause_user_code, period); + pause_usercode_timeout.attach(this,&Psiswarm::IF_end_pause_user_code, period); } -void IF_end_pause_user_code() +void Psiswarm::IF_end_pause_user_code() { user_code_running = user_code_restore_mode; } -void IF_get_hardware_description() +void Psiswarm::IF_get_hardware_description() { debug("- Robot serial number %1.2f\n",serial_number); debug("- PCB version %1.2f\n",pcb_version);