Permalink
Browse files

Finished rough copy of the Pololu library

  • Loading branch information...
1 parent 3b90636 commit 13eb867ab25431e65c1ffd03916ad2abc9b849a6 @allgood38 allgood38 committed Feb 5, 2013
Showing with 90 additions and 2 deletions.
  1. +24 −0 PololuServo/doc.md
  2. +40 −0 PololuServo/pololu_servo.cpp
  3. +26 −2 PololuServo/pololu_servo.h
View
@@ -0,0 +1,24 @@
+To use the Pololu Micro Servo Controller library.
+
+ ```c
+ #include <pololu_servo.h>
+
+ static const int pololu_reset_pin = 3;
+ static const int MOTOR_ONE = 7;
+
+ PololuMSC* pololu;
+
+ void setup() {
+ Serial1.begin(9600);
+ pinMode(pololu_reset_pin, OUTPUT);
+ pololu = new PololuMSC(&Serial1, pololu_reset_pin);
+ pololu->restart();
+ }
+
+ void loop() {
+ pololu->setPosition(MOTOR_ONE, 250);
+ delay(500);
+ pololu->setPosition(MOTOR_ONE, 0);
+ delay(500);
+ }
+ ```
@@ -1,6 +1,13 @@
#include "pololu_servo.h"
PololuMSC::PololuMSC(Stream* serialIn, int reset_pin) {
+ for( int i = 0; i < this->SERVO_SLOTS; i++ ) {
+ this->available_servos[i].current_value = SERVO_DEFAULT;
+ this->available_servos[i].is_attached = false;
+ }
+
+ this->DEBUG = false;
+
this->serialCom = serialIn;
this->reset_pin = reset_pin;
}
@@ -17,3 +24,36 @@ int PololuMSC::restart() {
return 0;
}
+int PololuMSC::setPosition(int motorID, int newValue) {
+ if ( newValue > 254 || newValue < 0
+ || motorID < 0 || motorID > this->SERVO_SLOTS - 1 ) {
+ if ( this->DEBUG ) {
+ this->serialDebug->println("Invalid setPosition Values");
+ }
+ return -1;
+ }
+ this->available_servos[motorID].current_value = newValue;
+ this->available_servos[motorID].is_attached = true;
+
+ this->serialCom->write(0xFF);
+ this->serialCom->write(motorID);
+ this->serialCom->write(newValue);
+
+ return 0;
+}
+
+int PololuMSC::debugSet(Stream* newSerial) {
+ if ( newSerial == NULL ) {
+ return -1;
+ }
+ this->serialDebug = newSerial;
+ this->DEBUG = true;
+
+ return 0;
+}
+
+int PololuMSC::debugOff() {
+ this->DEBUG = false;
+ this->serialDebug = NULL;
+ return 0;
+}
View
@@ -20,9 +20,9 @@
*
* Basically the servo controller only needs to have serial commands sent
* to it, in accord with the mode of operation you choose. In this case,
- * the library is using the MiniServo commands as opposed to the Pololu
+ * the library is using the Mini SSC II commands as opposed to the Pololu
* specific commands, which you can read about in the documentation
- * posted on the wiki
+ * posted on the wiki.
*/
#ifndef pololu_servo_h
@@ -34,15 +34,39 @@ class PololuMSC {
private:
static const int RESET_HIGH_WAIT = 100;
static const int RESET_LOW_WAIT = 1000;
+ static const int SERVO_SLOTS = 8;
+ static const int SERVO_DEFAULT = 127;
+
+ struct servo {
+ int current_value;
+ bool is_attached;
+ };
+ struct servo available_servos[SERVO_SLOTS];
+
+ // To check for a high current situation
+ // No hardware to implement this as of yet
+ int power_supply_current;
Stream* serialCom;
int reset_pin;
+
+ Stream* serialDebug;
+ int DEBUG;
+
public:
/** One instance of an initialised serial port and the pin for
* the reset on the Pololu
*/
PololuMSC(Stream*, int);
+
+ /** This device has no error reporting, if behaviour becomes
+ * suspect, restart device.
+ */
int restart();
+ int setPosition(int motorID, int newValue);
+
+ int debugSet(Stream*);
+ int debugOff();
};
#endif

0 comments on commit 13eb867

Please sign in to comment.