Ward Elder / m3pi_V6_Ward_copy
Embed: (wiki syntax)

« Back to documentation index

m3pi Class Reference

m3pi Class Reference

m3pi Class More...

#include <m3pi.h>

Public Member Functions

 m3pi ()
 m3pi constructor
 ~m3pi ()
 m3pi destructor
void init ()
 Initialisation function.
void scan ()
 Causes the robot to read the IR sensors.
void get_signature (char *signature)
 Get signature of slave firmware.
void get_raw_values (unsigned int *values)
 Read raw sensor values from IR sensors (0 - 2000)
void get_calibrated_values (unsigned int *values)
 Read calibrated sensor values from IR sensors (0 - 1000)
float get_trimpot_value ()
 Read user potentiometer values (0.0 - 1.0)
float get_battery_voltage ()
 Read battery voltage.
void play_music (const char notes[], int length)
 Play music.
void calibrate ()
 Calibrate.
void reset_calibration ()
 Reset previous calibration values.
float get_line_position ()
 Returns estimate of normalised line position.
float read_line ()
 Returns an estimate of the normalised line position.
void lcd_clear ()
 Clear LCD.
void lcd_print (char text[], int length)
 Print text on LCD.
void lcd_goto_xy (int x, int y)
 Move cursor on LCD.
void auto_calibrate ()
 Call automatic calibration function.
void left_motor (float speed)
 Move left motor.
void right_motor (float speed)
 Move right motor.
void motors (float left_speed, float right_speed)
 Move both motors.
void stop ()
 Stop both motors.
void forward (float speed)
 Move buggy forward.
void reverse (float speed)
 Reverse buggy.
void spin_right (float speed)
 Spin right.
void spin_left (float speed)
 Spin left.
void display_battery_voltage (int x, int y)
 Display battery voltage on LCD.
void display_signature (int x, int y)
 Display slave firmware signature on LCD.
void display_data ()
 Display line position and bar graph of sensor readings on LCD.
void display_sensor_values (unsigned int values[], int y)
 Display sensor values on LCD.
unsigned int get_sensor_array_value (unsigned int values[])
 Gets value of sensor array expressed as decimal number.
float calc_line_position (unsigned int values[])
 Calculates an estimate of normalised line position from the sensor readings.

Detailed Description

m3pi Class

Library to control m3pi robot from Polulu running the serial slave code Revision 1.0

Author:
Craig A. Evans <C.A.Evans@leeds.ac.uk>
Date:
April 2017

Definition at line 13 of file m3pi.h.


Constructor & Destructor Documentation

m3pi (  )

m3pi constructor

Definition at line 6 of file m3pi.cpp.

~m3pi (  )

m3pi destructor

Definition at line 22 of file m3pi.cpp.


Member Function Documentation

void auto_calibrate (  )

Call automatic calibration function.

Definition at line 246 of file m3pi.cpp.

float calc_line_position ( unsigned int  values[] )

Calculates an estimate of normalised line position from the sensor readings.

Returns:
float in the range -1.0 to 1.0

-1.0 for line under sensor 0, -0.5 for line under sensor 1

0.0 for line under sensor 2, 0.5 for line under sensor 3 etc.

Definition at line 447 of file m3pi.cpp.

void calibrate (  )

Calibrate.

manual calibration of sensors. Should be called repeatedly.

Definition at line 168 of file m3pi.cpp.

void display_battery_voltage ( int  x,
int  y 
)

Display battery voltage on LCD.

Parameters:
x- x position on LCD to display
y- line on LCD to display

Definition at line 369 of file m3pi.cpp.

void display_data (  )

Display line position and bar graph of sensor readings on LCD.

must call scan() and read_line() first

Definition at line 416 of file m3pi.cpp.

void display_sensor_values ( unsigned int  values[],
int  y 
)

Display sensor values on LCD.

Parameters:
values- array of calibrated sensor values
y- line on LCD to display

Definition at line 396 of file m3pi.cpp.

void display_signature ( int  x,
int  y 
)

Display slave firmware signature on LCD.

Parameters:
x- x position on LCD to display
y- line on LCD to display

Definition at line 380 of file m3pi.cpp.

void forward ( float  speed )

Move buggy forward.

Parameters:
speed- value in range 0.0 to 1.0 (full-speed forward)

Definition at line 330 of file m3pi.cpp.

float get_battery_voltage (  )

Read battery voltage.

Returns:
battery voltage in volts

Definition at line 129 of file m3pi.cpp.

void get_calibrated_values ( unsigned int *  values )

Read calibrated sensor values from IR sensors (0 - 1000)

Parameters:
values- array of size 5 to store values

Definition at line 83 of file m3pi.cpp.

float get_line_position (  )

Returns estimate of normalised line position.

Returns:
float in the range -1.0 to 1.0

-1.0 for line under sensor 0, -0.5 for line under sensor 1

0.0 for line under sensor 2, 0.5 for line under sensor 3 etc.

Definition at line 184 of file m3pi.cpp.

void get_raw_values ( unsigned int *  values )

Read raw sensor values from IR sensors (0 - 2000)

Parameters:
values- array of size 5 to store values

Definition at line 56 of file m3pi.cpp.

unsigned int get_sensor_array_value ( unsigned int  values[] )

Gets value of sensor array expressed as decimal number.

Each sensor is a bit (PC4 is bit 0, PC0 is bit 5)

Returns:
value - 5-bit value of sensor reading

Definition at line 427 of file m3pi.cpp.

void get_signature ( char *  signature )

Get signature of slave firmware.

Parameters:
signature- array of size 7 to store signature

Definition at line 46 of file m3pi.cpp.

float get_trimpot_value (  )

Read user potentiometer values (0.0 - 1.0)

Returns:
float in range 0.0 to 1.0

Definition at line 109 of file m3pi.cpp.

void init (  )

Initialisation function.

Should be called at the start of the program to interrupt demo

code and start 3pi in serial slave mode

Definition at line 31 of file m3pi.cpp.

void lcd_clear (  )

Clear LCD.

Definition at line 202 of file m3pi.cpp.

void lcd_goto_xy ( int  x,
int  y 
)

Move cursor on LCD.

Parameters:
x- x position
y- line number

Definition at line 232 of file m3pi.cpp.

void lcd_print ( char  text[],
int  length 
)

Print text on LCD.

Parameters:
text[]- string of max size 8
-length of string

Definition at line 210 of file m3pi.cpp.

void left_motor ( float  speed )

Move left motor.

Parameters:
speed- value in range -1.0 (full-speed backward) to 1.0 (full-speed forward)

Definition at line 262 of file m3pi.cpp.

void motors ( float  left_speed,
float  right_speed 
)

Move both motors.

Parameters:
leftspeed - value in range -1.0 (full-speed backward) to 1.0 (full-speed forward)
rightspeed - value in range -1.0 (full-speed backward) to 1.0 (full-speed forward)

Definition at line 317 of file m3pi.cpp.

void play_music ( const char  notes[],
int  length 
)

Play music.

Parameters:
notes- const array containing Pololu notes
length- number of notes in array

Definition at line 146 of file m3pi.cpp.

float read_line (  )

Returns an estimate of the normalised line position.

Returns:
float in the range -1.0 to 1.0

uses the values of sensor stored in the class - must call scan() first!

-1.0 for line under sensor 0, -0.5 for line under sensor 1

0.0 for line under sensor 2, 0.5 for line under sensor 3 etc.

Definition at line 475 of file m3pi.cpp.

void reset_calibration (  )

Reset previous calibration values.

Definition at line 176 of file m3pi.cpp.

void reverse ( float  speed )

Reverse buggy.

Parameters:
speed- value in range 0.0 to 1.0 (full-speed forward)

Definition at line 340 of file m3pi.cpp.

void right_motor ( float  speed )

Move right motor.

Parameters:
speed- value in range -1.0 (full-speed backward) to 1.0 (full-speed forward)

Definition at line 289 of file m3pi.cpp.

void scan (  )

Causes the robot to read the IR sensors.

is an alterative to get_*_values methods if you don't need the values themselves

Definition at line 41 of file m3pi.cpp.

void spin_left ( float  speed )

Spin left.

Parameters:
speed- value in range 0.0 to 1.0

Definition at line 358 of file m3pi.cpp.

void spin_right ( float  speed )

Spin right.

Parameters:
speed- value in range 0.0 to 1.0

Definition at line 349 of file m3pi.cpp.

void stop (  )

Stop both motors.

Definition at line 323 of file m3pi.cpp.