Unfinished v0.7, added bearing detection

Fork of Pi_Swarm_Library_v06_alpha by piswarm

Revision:
4:52b3e4c5a425
Parent:
3:4c0f2f3de33e
Child:
9:7a4fc1d7e484
--- a/piswarm.cpp	Sun Feb 02 21:18:05 2014 +0000
+++ b/piswarm.cpp	Sun Feb 02 22:30:47 2014 +0000
@@ -1,13 +1,14 @@
-/* University of York Robot Lab Pi Swarm Robot Library
+/*******************************************************************************************
+ *
+ * University of York Robot Lab Pi Swarm Robot Library
  *
  * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York
  * 
- * Version 0.4  January 2014
+ * Version 0.5  February 2014
  *
  * Designed for use with the Pi Swarm Board (enhanced MBED sensor board) v1.2
  *
- * Based on the original m3pi library, Copyright (c) 2007-2010 cstyles (see copyright notice at end of file) * 
- */
+ ******************************************************************************************/
 
 #include "piswarm.h" 
 
@@ -76,12 +77,6 @@
     _oled_b.pulsewidth_us(blue);
 }
 
-
-// Returns the enable state of the center LED 
-char PiSwarm::get_cled_state( void ){
-    return cled_enable;
-}
-
 // Set the state of an individual LED. oled = LED to enable. value = 0 for disable, 1 for enable. Use to change 1 LED without affecting others.
 void PiSwarm::set_oled(char oled, char value){
     oled_array[oled]=value;
@@ -155,7 +150,6 @@
     _i2c.write(EXPANSION_IC_ADDRESS,data,3,false);    
 }
 
-
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Center LED Functions
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -165,6 +159,11 @@
     return (cled_red << 16) + (cled_green << 8) + cled_blue;
 }
 
+// Returns the enable state of the center LED 
+char PiSwarm::get_cled_state( void ){
+    return cled_enable;
+}
+
 // Set the colour of the center LED.  Values for red, green and blue range from 0 (off) to 255 (maximum).
 void PiSwarm::set_cled_colour( char red, char green, char blue ){
     cled_red = red;
@@ -190,12 +189,7 @@
 // Set the center LED brightness (total period of PWM output increases as brightness decreases). Ranges from 0 (minimum) to 255 (maximum)
 void PiSwarm::set_cled_brightness ( char brightness ) {
     if( brightness > 100 ) brightness = 100;
-    // Brightness is set by adjusting period of PWM
-    // Max brightness is when total period = 256 uS
-    // When brightness is 90 total period =  274 uS
-    // When brightness is 50 total period =  546 uS
-    // When brightness is 10 total period = 1138 uS
-    // When brightness is 0  total period = 1336 uS
+    // Brightness is set by adjusting period of PWM.  Period ranged from ~260uS at 100% to 1336uS at 0%
     // When calibrate_colours = 1, red = 2x normal, green = 2x normal
     cled_brightness = brightness;
     int cled_period = (104 - brightness);
@@ -209,7 +203,6 @@
     _cled_b.period_us(cled_period);
 }
 
-
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // IR Sensor Functions
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -327,7 +320,6 @@
     _i2c.write(EXPANSION_IC_ADDRESS,data,2,false);
 }
 
-
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // MEMS Sensor Functions
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -390,7 +382,6 @@
     return mag_values[2];
 }
 
- 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Other Sensor Functions
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -414,7 +405,6 @@
 }
 
 
-
 void PiSwarm::read_raw_sensors ( int * raw_ls_array ) {
     _ser.putc(SEND_RAW_SENSOR_VALUES);
     for (int i = 0; i < 5 ; i ++) {
@@ -458,8 +448,6 @@
 }
 
 
-
-
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Motor Functions
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -513,14 +501,6 @@
     motor(0,0.0);
     motor(1,0.0);
 }
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// RF Transceiver Functions
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-void PiSwarm::send_rf_message(char* message, char length){
-    _rf.sendString(length, message);
-}
-
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Sound Functions
@@ -534,6 +514,19 @@
     }
 }
 
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// Display Functions
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void PiSwarm::locate(int x, int y) {
+    _ser.putc(DO_LCD_GOTO_XY);
+    _ser.putc(x);
+    _ser.putc(y);
+}
+
+void PiSwarm::cls(void) {
+    _ser.putc(DO_CLEAR);
+}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // EEPROM Functions
@@ -619,6 +612,13 @@
     return ret;
 }
 
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// RF Transceiver Functions
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+void PiSwarm::send_rf_message(char* message, char length){
+    _rf.sendString(length, message);
+}
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Setup and Calibration Functions
@@ -883,15 +883,6 @@
 }
 
 
-void PiSwarm::locate(int x, int y) {
-    _ser.putc(DO_LCD_GOTO_XY);
-    _ser.putc(x);
-    _ser.putc(y);
-}
-
-void PiSwarm::cls(void) {
-    _ser.putc(DO_CLEAR);
-}
 
 int PiSwarm::print (char* text, int length) {
     _ser.putc(DO_PRINT);  
@@ -1038,11 +1029,11 @@
     }
 }
 
-
-
 /********************************************************************************
  * COPYRIGHT NOTICE                                                             *
  *                                                                              *
+ * Parts of code based on the original m3pi library, Copyright (c) 2010 cstyles *
+ *                                                                              *
  * Permission is hereby granted, free of charge, to any person obtaining a copy *
  * of this software and associated documentation files (the "Software"), to deal*
  * in the Software without restriction, including without limitation the rights *