Fork of 
        m3pi 
        by  Samir Bouaziz 
« Back to documentation index 
    
m3pi Class Reference 
m3pi  control class  
More... 
#include <m3pi.h >
  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.   void  calibrated_sensors  (unsigned short ltab[5])  lecture capteurs calibres   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.   void  play  (char *music, int length)  Send a string buffer to the 3pi serial interface for playing music.   
Detailed Description 
m3pi  control class 
Example: 
 
   #include "mbed.h" 
   #include "m3pi.h" 
   m3pi  pi;
   int  main() {
     wait(0.5);
     pi.forward (0.5);
     wait (0.5);
     pi.left (0.5);
     wait (0.5);
     pi.backward (0.5);
     wait (0.5);
     pi.right (0.5);
     wait (0.5);
     pi.stop ();
 }
 Definition at line 84  of file m3pi.h .
Constructor & Destructor Documentation 
Create the m3pi  object connected to the default pins. 
Parameters: 
  
    nrst GPIO pin used for reset. Default is p23  tx Serial transmit pin. Default is p9  rx Serial receive pin. Default is p10  
   
Definition at line 32  of file m3pi.cpp .
 
 
      
        
          m3pi  ( 
          PinName  
           nrst ,  
         
        
          PinName  
           tx ,  
         
        
          PinName  
           rx   
         
        
          ) 
           
      
 
Create the m3pi  object connected to specific pins. 
Definition at line 27  of file m3pi.cpp .
 
 
Member Function Documentation 
      
        
          void backward  
          ( 
          float  
           speed  ) 
           
      
 
Drive both motors backward as the same speed. 
Parameters: 
  
    speed A normalised number 0 - 1.0 represents the full range.  
   
Definition at line 58  of file m3pi.cpp .
 
 
Read the battery voltage on the 3pi. 
Returns: battery voltage as a float  Definition at line 97  of file m3pi.cpp .
 
 
Set calibration manually to the current settings. 
Definition at line 130  of file m3pi.cpp .
 
 
      
        
          void calibrated_sensors  
          ( 
          unsigned short  
           ltab [5] ) 
           
      
 
lecture capteurs calibres 
Returns: tableau val capteurs de gauche à droite 0 blanc (reflexion max) 1000 noir (pas de reflexion)  Definition at line 115  of file m3pi.cpp .
 
 
Clear the LCD. 
Definition at line 172  of file m3pi.cpp .
 
 
      
        
          void forward  
          ( 
          float  
           speed  ) 
           
      
 
Drive both motors forward as the same speed. 
Parameters: 
  
    speed A normalised number 0 - 1.0 represents the full range.  
   
Definition at line 53  of file m3pi.cpp .
 
 
Receive a character directly to the 3pi serial interface. 
Returns: c The character received from the 3pi  Definition at line 215  of file m3pi.cpp .
 
 
Write to the 8 LEDs. 
Parameters: 
  
    leds An 8 bit value to put on the LEDs  
   
Definition at line 159  of file m3pi.cpp .
 
 
      
        
          void left  
          ( 
          float  
           speed  ) 
           
      
 
Drive left motor backwards and right motor forwards at the same speed to turn on the spot. 
Parameters: 
  
    speed A normalised number 0 - 1.0 represents the full range.  
   
Definition at line 63  of file m3pi.cpp .
 
 
      
        
          void left_motor  
          ( 
          float  
           speed  ) 
           
      
 
Directly control the speed and direction of the left motor. 
Parameters: 
  
    speed A normalised number -1.0 - 1.0 represents the full range.  
   
Definition at line 45  of file m3pi.cpp .
 
 
      
        
          float line_position  
          ( 
          void  
           ) 
           
      
 
Read the position of the detected line. 
Returns: position as A normalised number -1.0 - 1.0 represents the full range. -1.0 means line is on the left, or the line has been lost 0.0 means the line is in the middle 1.0 means the line is on the right  Definition at line 105  of file m3pi.cpp .
 
 
      
        
          void locate  
          ( 
          int  
           x ,  
         
        
          int  
           y   
         
        
          ) 
           
      
 
Locate the cursor on the 8x2 LCD. 
Parameters: 
  
    x The horizontal position, from 0 to 7  y The vertical position, from 0 to 1  
   
Definition at line 166  of file m3pi.cpp .
 
 
      
        
          void play  
          ( 
          char *  
           music ,  
         
        
          int  
           length   
         
        
          ) 
           
      
 
Send a string buffer to the 3pi serial interface for playing music. 
See here for details about the string's format: http://www.pololu.com/docs/0J18/3  
Parameters: 
  
    music A pointer to a char array  length The length of the music string  
   
Definition at line 186  of file m3pi.cpp .
 
 
      
        
          float pot_voltage  
          ( 
          void  
           ) 
           
      
 
Read the voltage of the potentiometer on the 3pi. 
Returns: voltage as a float  Definition at line 150  of file m3pi.cpp .
 
 
      
        
          int print  
          ( 
          char *  
           text ,  
         
        
          int  
           length   
         
        
          ) 
           
      
 
Send a string buffer to the 3pi serial interface. 
Parameters: 
  
    text A pointer to a char array  int The character to send to the 3pi  
   
Definition at line 176  of file m3pi.cpp .
 
 
Send a character directly to the 3pi serial interface. 
Parameters: 
  
    c The character to send to the 3pi  
   
Definition at line 211  of file m3pi.cpp .
 
 
Force a hardware reset of the 3pi. 
Definition at line 38  of file m3pi.cpp .
 
 
      
        
          void reset_calibration  
          ( 
          void  
           ) 
           
      
 
Clear the current calibration settings. 
Definition at line 134  of file m3pi.cpp .
 
 
      
        
          void right  
          ( 
          float  
           speed  ) 
           
      
 
Drive left motor forward and right motor backwards at the same speed to turn on the spot. 
Parameters: 
  
    speed A normalised number 0 - 1.0 represents the full range.  
   
Definition at line 68  of file m3pi.cpp .
 
 
      
        
          void right_motor  
          ( 
          float  
           speed  ) 
           
      
 
Directly control the speed and direction of the right motor. 
Parameters: 
  
    speed A normalised number -1.0 - 1.0 represents the full range.  
   
Definition at line 49  of file m3pi.cpp .
 
 
      
        
          char sensor_auto_calibrate  
          ( 
          void  
           ) 
           
      
 
Calibrate the sensors. 
This turns the robot left then right, looking for a line 
Definition at line 124  of file m3pi.cpp .
 
 
Stop both motors. 
Definition at line 73  of file m3pi.cpp .