I still haven’t got my project working, but I’m making headway.
I believe I have the serial command sending table sorted out, and now have a few more specific questions.
my conversion table now looks like this, modified according to the information in the SDK guide.
//*********************************
//********** MAESTRO MODE *********
//*********************************
//# OF BYTES: 5 or 6
//---------------------------------
// BYTE 1: Start Byte (0xAA)
// BYTE 2: Device type number (0x12 for Maestro Controller)
// BYTE 3: Specify Servo Command
// COMMAND 4: (0x04) Target (2 bytes 1Low/2High)
// COMMAND 7: (0x07) Speed, (2 bytes 1Low/2High)
// COMMAND 9: (0x09) Acceleration (1 byte?)
// BYTE 4: Servo Number eg: Servo 1 (0x01? or 0x00)
// BYTE 5: Values from Command (in conjunction with BYTE 3) Low byte
// BYTE 6: Command Data Values ((in conjunction with BYTE 3) High byte (if needed)
So, Assuming i’ve understood that correctly, the code i’m using to send the comands looks like this:
//Set Target: 0xAA, device number, 0x04, servo number, target low bits, target high bits
port.Write(new byte[] {
0xAA, //synch value (always 0xAA)
0x12, //device ID (0x12 for Maestro servo controller)
ServoNumberByte, //servo number
lowerBitsByte //Data Byte 1: This byte is composed of the upper bits of an integer ranging from 500-5500.
// This is so because we are trying to send 13 bits to a controller which can only read 7,
// therefore the upper 6 bits must be sent in one byte, and later we will send the lower 7.
upperBitsByte, //Data Byte 2: Byte 2 is composed of the 7 remaining bits (from bit 0 up to and including bit 6)
}, 0, 6);[/code]
It’s not working for me at the moment, and it’s so annoying as i’ve been working on this for about a month now, and I know that if I had a little more C# knowledge, i’d have the project running faster than it will take me to write this post!!!
My issues could also lie here:
The software we’re using is breaking the speed/target values into the nessecary 2, 7 bit bytes. (in Pololu mode)
The code i’m working with was developed for the pololu 16 servo USB controller and it’s resolution.
Do i need to modify the resolution calculation of the target value for the Maestro.
Meaning, if it’s approximately 0.025 degree steps, it’s about 7200 steps per 180 degrees.
Is this the same resolution as the USB 16 servo controller?
(Actually the range that the Maestro Control Centre uses is perfect, if you know what it uses, i’d love to know!)
Here’s the current value converter.
//code to convert integer servo position (500-5500) into 2 7 bit bytes.
int[] binaryArray = new int[13] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int[] upperBits = new int[6];
int upperBitsInt = 0;
int[] lowerBits = new int[7];
int lowerBitsInt = 0;
string[] binarystring = new string[13];
//2^12 == 4096 maximum number of binary combinations
int pow = 4096;
//MSB to LSB: working from left to right working out the exact value for the binary conversion.
for (int i = 0; i < 13; i++)
{
if (ServoPos >= pow)
{
binaryArray[i] = 1;
ServoPos = ServoPos - pow;
binarystring[i] = "1";
}
// reduce the power of 2, eg, 2^4, 2^3, 2^2, etc so the computer can decide in the next loop
//
pow = pow / 2;
}
//LOWER BITS
//COPY
for (int i = 6; i < 12; i++)
{
lowerBits[i - 6] = binaryArray[i];
}
//convert lowerbits to decimal
pow = 1;
for (int i = 6; i >= 0; i--) //start at 6 and go down so that we start with the LSB (pow = 1) and go up to the MSB
{
if (lowerBits[i] == 1)
{
lowerBitsInt = lowerBitsInt + pow;
}
pow = pow * 2;
}
//UPPER BITS
//COPY
for (int i = 0; i < 6; i++)
{
upperBits[i] = binaryArray[i];
}
//convert upper bits to decimal
pow = 1;
for (int i = 5; i >= 0; i--) //start at 6 and go down so that we start with the LSB (pow = 1) and go up to the MSB
{
if (upperBits[i] == 1)
{
upperBitsInt = upperBitsInt + pow;
}
pow = pow * 2;
}[/code]
From this information, can you see where my problem lies. If the code above doesn’t have any major issues, I know I need to look else where.
For the moment it’s not throwing any errors, it’s just not reacting.
-Ben.