This program contains a class that makes it easy for the mbed to communicate with the Mini SSC II or the Pololu Maestro in SSC compatibility mode. (they are servo/motor controllers)

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers minissc.h Source File

minissc.h

00001 #pragma once
00002 
00003 #include "mbed.h"
00004 #include <string>
00005 #include <sstream>
00006 
00007 #define SSC_SYNC_BYTE 255
00008 
00009 // Stores values for and communicates with the Mini SSC II. This is used to control the motors and move the sub.
00010 class MiniSSC2 {
00011 public:
00012     MiniSSC2(int num_motors, int baud, PinName tx, PinName rx);
00013     ~MiniSSC2();
00014     void send(); // send all motors' speeds to the Mini SSC II
00015     void send(int i_motor); // send speed of motor i_motor to the Mini SSC II
00016     void set(unsigned char value); // set, but don't send, all the motors to a single value
00017     void set(int i_motor, unsigned char value); // set, but don't send, motor number i_motor to value
00018     unsigned char get(int i_motor); // get the current speed for motor number i_motor
00019 private:
00020     Serial* p_device; // pointer to our serial object (used to send stuff)
00021     int num_motors; // number of motors, counting from 1
00022     
00023     /*
00024      * These arrays send input to the Mini SSC II which in turn sends to the motors. 
00025      * The format for the arrays: {SYNC_BYTE, servo number, speed}
00026      * SYNC_BYTE tells the Mini SSC II that we're about to send new instructions.
00027      * The servo number picks the motor. 1 = right, 2 = back, 3 = front, 4 = left
00028      * We set the speed anywhere between 0 and 254. 127 is off, 254 is 100% forward, 0 is 100% back.
00029      * On the back motor, the numbers are reversed. 0 is 100% forward, 254 is 100% back. 127 is still off.
00030      * The speed scales approximately linearly with the set values, though there is no motor motion until around 127+-15.
00031      */
00032      
00033      //The Mini SSC II supports 8 motors. The Pololu supports 12. This array locally stores their speeds.
00034      unsigned char motors[24];
00035 };
00036 
00037 void ssc_send_cb();
00038 MiniSSC2 ssc(4, 9600, p13, p14); // 4 motors, baud for Mini SSC II is 9600, Mini SSC II is connected to pins 9 and 10
00039 Ticker ssc_to;
00040 
00041 Ticker led1_on, led1_off;
00042 
00043 // debug
00044 Serial PC(USBTX, USBRX); // tx, rx
00045 DigitalOut led1(LED1), led2(LED2), led3(LED3), led4(LED4);