Mike Spadaru / physcom
Embed: (wiki syntax)

« Back to documentation index

M3pi Class Reference

M3pi Class Reference

m3pi control class More...

#include <m3pi.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 reset (void)
 Force a hardware reset of the 3pi.
void stop ()
 This function will smoothly stop the motors of the robot by gradually slowing down.
void activate_motor (int motor, float speed)
 Activate motor.
void raw_sensors (int sensors[5])
 Reads the values of the active light sensors.
void calibrated_sensors (int sensors[5])
 Reads the values of the active light sensors.
float battery (void)
 Read the battery voltage on the 3pi.
char sensor_auto_calibrate (void)
 Calibrate the sensors.

Detailed Description

m3pi control class

Definition at line 26 of file m3pi.h.


Constructor & Destructor Documentation

M3pi (  )

Create the m3pi object connected to the default pins.

Parameters:
nrstGPIO pin used for reset. Default is p23
txSerial transmit pin. Default is p9
rxSerial receive pin. Default is p10

Definition at line 13 of file m3pi.cpp.

M3pi ( PinName  nrst,
PinName  tx,
PinName  rx 
)

Create the m3pi object connected to specific pins.

Definition at line 6 of file m3pi.cpp.


Member Function Documentation

void activate_motor ( int  motor,
float  speed 
)

Activate motor.

Parameters:
motor.Values: 0: Left; 1: Right
speedFloat value representing the speed of the motor. Negative values will turn the wheels in reverse. The possible values of this parameter range between -1 and 1. The values are normalized, so speed=1 means the motor will activate at full (100%) power, while speed=0.2 would activate the motor with 20% of its maximum power. A good starting value can be speed=0.1. In most cases the speed value you will use should be between -0.5 and 0.5.

Definition at line 49 of file m3pi.cpp.

float battery ( void   )

Read the battery voltage on the 3pi.

Returns:
battery voltage as a float

Definition at line 76 of file m3pi.cpp.

void calibrated_sensors ( int  sensors[5] )

Reads the values of the active light sensors.

The result values are normalized in the range 0-1000 based on the calibration. The function sensor_auto_calibrate() should be called once at the start of the program before reading the calibrated values.

Parameters:
sensorsArray of 5 int elements that will be populated with the sensor values

Definition at line 109 of file m3pi.cpp.

void raw_sensors ( int  sensors[5] )

Reads the values of the active light sensors.

Parameters:
sensorsArray of 5 int elements that will be populated with the sensor values

Definition at line 84 of file m3pi.cpp.

void reset ( void   )

Force a hardware reset of the 3pi.

Definition at line 21 of file m3pi.cpp.

char sensor_auto_calibrate ( void   )

Calibrate the sensors.

This turns the robot left then right, looking for a line. Make sure that when this function is called, the robot is positioned on the black line on white background. The values of the calibration are storred internaly and used when computing the normalized result values of calibrated_sensors().

Definition at line 134 of file m3pi.cpp.

void stop (  )

This function will smoothly stop the motors of the robot by gradually slowing down.

Contributed by Menno Vermeulen and Daniel Trujillo

Definition at line 30 of file m3pi.cpp.