librairie pour robot Zumo
zumo.h
- Committer:
- bouaziz
- Date:
- 2022-01-10
- Revision:
- 11:1082c5b3b418
- Parent:
- 10:7935bbc4ebf1
- Child:
- 12:d9c9ef63c5ff
File content as of revision 11:1082c5b3b418:
/* mbed zumo Library
* Copyright (c) 2007-2010 cstyles
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef zumo_H
#define zumo_H
#include "mbed.h"
#include "platform.h"
#define SEND_MOTOR_SPEED 0xA4
#define SEND_MOTOR_STOP 0xA0
#define SEND_CALIB_SENSOR_VALUES 0x87
#define SEND_TRIMPOT 0xB0
#define SEND_BATTERY_MILLIVOLTS 0xB1
#define DO_PLAY 0xB3
#define PI_CALIBRATE 0xB4
#define DO_CLEAR 0xB7
#define DO_PRINT 0xB8
#define DO_LCD_GOTO_XY 0xB9
#define LINE_SENSORS_RESET_CALIBRATION 0xB5
#define SEND_LINE_POSITION 0xB6
#define AUTO_CALIBRATE 0xBA
#define SET_PID 0xBB
#define STOP_PID 0xBC
#define M1_FORWARD 0xC1
#define M1_BACKWARD 0xC2
#define M2_FORWARD 0xC5
#define M2_BACKWARD 0xC6
/** zumo control class
*
* Example:
* @code
* // Drive the zumo forward, turn left, back, turn right, at half speed for half a second
#include "mbed.h"
#include "zumo.h"
zumo 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();
}
* @endcode
*/
class zumo {
// Public functions
public:
/** Create the zumo object connected to the default pins
*
* @param nrst GPIO pin used for reset. for futre use
* @param tx Serial transmit pin. Default is p9
* @param rx Serial receive pin. Default is p10
*/
zumo();
//reset();
/** Create the zumo object connected to specific pins
*
*/
zumo(PinName nrst, PinName tx, PinName rx);
/** Force a hardware reset of the 3pi
*/
void reset (void);
/** Stop both motors
*
*/
void stop (void);
/** Read the battery voltage on the 3pi
* @returns battery voltage as a float
*/
float battery(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
*/
float line_position (void);
/** lecture capteurs calibres
* @returns tableau val capteurs de gauche à droite
* 0 blanc (reflexion max)
* 1000 noir (pas de reflexion)
*/
void calibrated_sensors(unsigned short ltab[5]);
/** fonction speed
* @returns pour le future retourne 0x0A pour indiquer bonne prise en compte.
* Pour le moment retourne rien.
*
*/
char speed(short spg,short spd);
/** Calibrate the sensors. This turns the robot left then right, looking for a line
*
*/
char sensor_auto_calibrate (void);
void PID_start(int max_speed, int a, int b, int c, int d);
void PID_stop();
/** Write to the 8 LEDs
*
* @param leds An 8 bit value to put on the LEDs
*/
void leds(int val);
Serial _ser;
private :
DigitalOut _nrst;
};
#endif