You are viewing an older revision! See the latest version
ARM Summer Students 2013 Workshop
Welcome to the ARM Summer Workshop!¶
 
Useful numbers¶
- Speed of rotation: 720 degrees per second at half speed
 - Forward/Backward: 470mm per second at half speed
 
Documents¶
- /media/uploads/AndrewBetts/guide_part_1.pdf
 - /media/uploads/AndrewBetts/guide_part_2.pdf
 - /media/uploads/AndrewBetts/ref1-_programming_basics.pdf
 - /media/uploads/AndrewBetts/ref2-_list_of_functions.pdf
 
Library¶
Import library
    Public Member Functions | 
  |
| m3pi () | |
| 
    Create the
    
     m3pi
    
    object connected to the default pins.
    
    
     | 
  |
| m3pi (PinName nrst, PinName tx, PinName rx) | |
| 
    Create the
    
     m3pi
    
    object connected to specific pins.
    
    
     | 
  |
| void | reset (void) | 
| 
    Force a hardware reset of the 3pi.
    
    
     | 
  |
| void | left_motor (float speed) | 
| 
    Directly control the speed and direction of the left motor.
    
    
     | 
  |
| void | right_motor (float speed) | 
| 
    Directly control the speed and direction of the right motor.
    
    
     | 
  |
| void | forward (float speed) | 
| 
    Drive both motors forward as the same speed.
    
    
     | 
  |
| void | backward (float speed) | 
| 
    Drive both motors backward as the same speed.
    
    
     | 
  |
| void | left (float speed) | 
| 
    Drive left motor backwards and right motor forwards at the same speed to turn on the spot.
    
    
     | 
  |
| void | right (float speed) | 
| 
    Drive left motor forward and right motor backwards at the same speed to turn on the spot.
    
    
     | 
  |
| void | stop (void) | 
| 
    Stop both motors.
    
    
     | 
  |
| float | pot_voltage (void) | 
| 
    Read the voltage of the potentiometer on the 3pi.
    
    
     | 
  |
| float | battery (void) | 
| 
    Read the battery voltage on the 3pi.
    
    
     | 
  |
| float | line_position (void) | 
| 
    Read the position of the detected line.
    
    
     | 
  |
| char | sensor_auto_calibrate (void) | 
| 
    Calibrate the sensors.
    
    
     | 
  |
| void | calibrate (void) | 
| 
    Set calibration manually to the current settings.
    
    
     | 
  |
| void | reset_calibration (void) | 
| 
    Clear the current calibration settings.
    
    
     | 
  |
| void | leds (int val) | 
| 
    Write to the 8 LEDs.
    
    
     | 
  |
| void | locate (int x, int y) | 
| 
    Locate the cursor on the 8x2 LCD.
    
    
     | 
  |
| void | cls (void) | 
| 
    Clear the LCD.
    
    
     | 
  |
| int | putc (int c) | 
| 
    Send a character directly to the 3pi serial interface.
    
    
     | 
  |
| int | getc () | 
| 
    Receive a character directly to the 3pi serial interface.
    
    
     | 
  |
| int | print (char *text, int length) | 
| 
    Send a string buffer to the 3pi serial interface.
    
    
     | 
  |
Hello World¶
Example¶
Import program
00001 #include "mbed.h" 00002 #include "m3pi.h" 00003 00004 m3pi m3pi; 00005 00006 int main() { 00007 00008 // Parameters that affect the performance 00009 float speed = 0.2; 00010 float correction = 0.1; 00011 float threshold = 0.5; 00012 00013 m3pi.locate(0,1); 00014 m3pi.printf("Line Flw"); 00015 00016 wait(2.0); 00017 00018 m3pi.sensor_auto_calibrate(); 00019 00020 while (1) { 00021 00022 // -1.0 is far left, 1.0 is far right, 0.0 in the middle 00023 float position_of_line = m3pi.line_position(); 00024 00025 // Line is more than the threshold to the right, slow the left motor 00026 if (position_of_line > threshold) { 00027 m3pi.right_motor(speed); 00028 m3pi.left_motor(speed-correction); 00029 } 00030 00031 // Line is more than 50% to the left, slow the right motor 00032 else if (position_of_line < -threshold) { 00033 m3pi.left_motor(speed); 00034 m3pi.right_motor(speed-correction); 00035 } 00036 00037 // Line is in the middle 00038 else { 00039 m3pi.forward(speed); 00040 } 00041 } 00042 }