Maestro Servo Controller library
 All Classes Files Functions Variables
PololuMaestro.h
Go to the documentation of this file.
1 // Copyright (C) Pololu Corporation. See LICENSE.txt for details.
2 
14 #pragma once
15 
16 #include <Arduino.h>
17 #include <Stream.h>
18 
26 class Maestro
27 {
28  public:
32  static const uint8_t deviceNumberDefault = 255;
33 
37  static const uint8_t noResetPin = 255;
38 
47  void reset();
48 
57  void setTargetMiniSSC(uint8_t channelNumber, uint8_t target);
58 
76  void setTarget(uint8_t channelNumber, uint16_t target);
77 
92  void setSpeed(uint8_t channelNumber, uint16_t speed);
93 
108  void setAcceleration(uint8_t channelNumber, uint16_t acceleration);
109 
121  void goHome();
122 
133  void stopScript();
134 
151  void restartScript(uint8_t subroutineNumber);
152 
171  void restartScriptWithParameter(uint8_t subroutineNumber, uint16_t parameter);
172 
198  uint16_t getPosition(uint8_t channelNumber);
199 
215  uint8_t getMovingState();
216 
224  uint8_t getScriptStatus();
225 
237  uint16_t getErrors();
238 
243  protected:
244  Maestro(Stream &stream,
245  uint8_t resetPin,
246  uint8_t deviceNumber,
247  bool CRCEnabled);
248 
249  void writeByte(uint8_t dataByte);
250  void writeCRC();
251  void writeCommand(uint8_t commandByte);
252  void write7BitData(uint8_t data);
253  void write14BitData(uint16_t data);
256  private:
257  static const uint8_t CRC7Polynomial = 0x91;
258  static const uint8_t baudRateIndication = 0xAA;
259 
260  static const uint8_t miniSscCommand = 0xFF;
261  static const uint8_t setTargetCommand = 0x84;
262  static const uint8_t setSpeedCommand = 0x87;
263  static const uint8_t setAccelerationCommand = 0x89;
264  static const uint8_t getPositionCommand = 0x90;
265  static const uint8_t getMovingStateCommand = 0x93;
266  static const uint8_t getErrorsCommand = 0xA1;
267  static const uint8_t goHomeCommand = 0xA2;
268  static const uint8_t stopScriptCommand = 0xA4;
269  static const uint8_t restartScriptAtSubroutineCommand = 0xA7;
270  static const uint8_t restartScriptAtSubroutineWithParameterCommand = 0xA8;
271  static const uint8_t getScriptStatusCommand = 0xAE;
272 
273  uint8_t _deviceNumber;
274  uint8_t _resetPin;
275  bool _CRCEnabled;
276  uint8_t _CRCByte;
277  Stream *_stream;
278 };
279 
280 class MicroMaestro : public Maestro
281 {
282  public:
301  MicroMaestro(Stream &stream,
302  uint8_t resetPin = noResetPin,
303  uint8_t deviceNumber = deviceNumberDefault,
304  bool CRCEnabled = false);
305 };
306 
307 class MiniMaestro : public Maestro
308 {
309  public:
331  MiniMaestro(Stream &stream,
332  uint8_t resetPin = noResetPin,
333  uint8_t deviceNumber = deviceNumberDefault,
334  bool CRCEnabled = false);
335 
352  void setPWM(uint16_t onTime, uint16_t period);
353 
374  void setMultiTarget(uint8_t numberOfTargets,
375  uint8_t firstChannel,
376  uint16_t *targetList);
377 
378  private:
379  static const uint8_t setPwmCommand = 0x8A;
380  static const uint8_t setMultipleTargetsCommand = 0x9F;
381 };
uint16_t getErrors()
Gets the error register.
uint8_t getScriptStatus()
Gets if the script is running or stopped.
void setMultiTarget(uint8_t numberOfTargets, uint8_t firstChannel, uint16_t *targetList)
Sets multiple targets starting with the channel specified by firstChannel to a list of values listed ...
void stopScript()
Stops the script.
void goHome()
Sends the servos and outputs to home position.
MiniMaestro(Stream &stream, uint8_t resetPin=noResetPin, uint8_t deviceNumber=deviceNumberDefault, bool CRCEnabled=false)
Create a MiniMaestro object.
static const uint8_t deviceNumberDefault
The default device number, used to construct a MicroMaestro or MiniMaestro object that will use the c...
Definition: PololuMaestro.h:32
void reset()
Resets the Maestro by toggling the resetPin, if a resetPin was given.
static const uint8_t noResetPin
The default reset pin is no reset pin, used to construct a MicroMaestro or MiniMaestro object that wi...
Definition: PololuMaestro.h:37
void restartScript(uint8_t subroutineNumber)
Starts loaded script at specified subroutineNumber location.
MicroMaestro(Stream &stream, uint8_t resetPin=noResetPin, uint8_t deviceNumber=deviceNumberDefault, bool CRCEnabled=false)
Create a MicroMaestro object.
void setAcceleration(uint8_t channelNumber, uint16_t acceleration)
Sets the acceleration limit of channelNumber.
uint8_t getMovingState()
Gets the moving state for all configured servo channels.
void restartScriptWithParameter(uint8_t subroutineNumber, uint16_t parameter)
Starts loaded script at specified subroutineNumber location after loading parameter on to the stack...
void setSpeed(uint8_t channelNumber, uint16_t speed)
Sets the speed limit of channelNumber.
uint16_t getPosition(uint8_t channelNumber)
Gets the position of channelNumber.
Main Maestro class that handles common functions between the Micro Maestro and Mini Maestro...
Definition: PololuMaestro.h:26
void setTarget(uint8_t channelNumber, uint16_t target)
Sets the target of the servo on channelNumber.
void setTargetMiniSSC(uint8_t channelNumber, uint8_t target)
Sets the target of the servo on channelNumber using the Mini SSC protocol.
void setPWM(uint16_t onTime, uint16_t period)
Sets the PWM specified by onTime and period in units of 1/48 microseconds.