Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: newlib PID Robot WarehouseBot1 ... more
Fork of m3pi_ng by
m3pi Class Reference
#include <m3pi_ng.h>
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 | signature (char *) |
| Get the signature needs a length 6 char array to write into. | |
| void | raw_sensor (int *) |
| Get the raw sensor values needs a int[5] array to write into. | |
| void | calibrated_sensor (int *) |
| Get the calibrated sensor values needs a int[5] array to write into. | |
| void | playtune (char *text, int length) |
| Play music using the buzzer. | |
| 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. | |
Detailed Description
m3pi control class
Example:
// Drive the m3pi forward, turn left, back, turn right, at half speed for half a second #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 88 of file m3pi_ng.h.
Constructor & Destructor Documentation
| m3pi | ( | ) |
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 35 of file m3pi_ng.cpp.
| m3pi | ( | PinName | nrst, |
| PinName | tx, | ||
| PinName | rx | ||
| ) |
Create the m3pi object connected to specific pins.
Definition at line 30 of file m3pi_ng.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 96 of file m3pi_ng.cpp.
| float battery | ( | void | ) |
Read the battery voltage on the 3pi.
- Returns:
- battery voltage as a float
Definition at line 152 of file m3pi_ng.cpp.
| void calibrate | ( | void | ) |
Set calibration manually to the current settings.
Definition at line 176 of file m3pi_ng.cpp.
| void calibrated_sensor | ( | int * | cal ) |
Get the calibrated sensor values needs a int[5] array to write into.
Definition at line 58 of file m3pi_ng.cpp.
| void cls | ( | void | ) |
Clear the LCD.
Definition at line 218 of file m3pi_ng.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 91 of file m3pi_ng.cpp.
| int getc | ( | void | ) |
Receive a character directly to the 3pi serial interface.
- Returns:
- c The character received from the 3pi
Definition at line 248 of file m3pi_ng.cpp.
| void leds | ( | int | val ) |
Write to the 8 LEDs.
- Parameters:
-
leds An 8 bit value to put on the LEDs
Definition at line 205 of file m3pi_ng.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 101 of file m3pi_ng.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 83 of file m3pi_ng.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 160 of file m3pi_ng.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 212 of file m3pi_ng.cpp.
| void playtune | ( | char * | text, |
| int | length | ||
| ) |
Play music using the buzzer.
Definition at line 68 of file m3pi_ng.cpp.
| float pot_voltage | ( | void | ) |
Read the voltage of the potentiometer on the 3pi.
- Returns:
- voltage as a float
Definition at line 196 of file m3pi_ng.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 222 of file m3pi_ng.cpp.
| int putc | ( | int | c ) |
Send a character directly to the 3pi serial interface.
- Parameters:
-
c The character to send to the 3pi
Definition at line 244 of file m3pi_ng.cpp.
| void raw_sensor | ( | int * | raw ) |
Get the raw sensor values needs a int[5] array to write into.
Definition at line 48 of file m3pi_ng.cpp.
| void reset | ( | void | ) |
Force a hardware reset of the 3pi.
Definition at line 76 of file m3pi_ng.cpp.
| void reset_calibration | ( | void | ) |
Clear the current calibration settings.
Definition at line 180 of file m3pi_ng.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 106 of file m3pi_ng.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 87 of file m3pi_ng.cpp.
| char sensor_auto_calibrate | ( | void | ) |
Calibrate the sensors.
This turns the robot left then right, looking for a line
Definition at line 170 of file m3pi_ng.cpp.
| void signature | ( | char * | sig ) |
Get the signature needs a length 6 char array to write into.
Definition at line 41 of file m3pi_ng.cpp.
| void stop | ( | void | ) |
Stop both motors.
Definition at line 111 of file m3pi_ng.cpp.
Generated on Sat Jul 16 2022 20:26:26 by
1.7.2
