--- In bestinc@yahoogroups.com, "joeymarshall@..." <joeymarshall@...> wrote:
>
> Hello everyone!
>
> I am actually coming down to the wire on this one, and I really would
appreciate someone bailing me out!
>
> I need a program for the Brain that has 3 motors: channel 1,2,and 4
>
> and then channel 3 would have 2 servos going opposite directions of each
other. (one clockwise the other counter clockwise)
>
> Has anyone already done this program for their robot, or already have a
completed program they could just share with me?
>
> I need to use this program Friday, and I ran out of time to learn c
programming :)
>
> Just FYI, I'm not a student, I'm an official working on next years game :)
>
> You can just reply to me personally if you prefer, you don't have to share the
program with the whole group if you don't want to!
> Thanks very much! -Joey
Hey Joey,
I'm glad to see I won't be the only one there without much driving practice.
I previously posted this whole program under subjects including the word
remap. I'll followup with you in email as well.
This does arcade drive with parabolic scaling.
The Brain wizard would probably be able to do what you want.
Note that this uses raw C numbering, starting at 0, instead of 1.
I've added some servo reverse code to the bottom.
It is untested so far, but it should get you started.
--Joel
// OK, I'll just post the whole thing here in every topic list.
// Click IAR, do Create new project, type C, subtype Brain
// edit main.c, paste in this text instead.
#include <msp430x14x.h>
#include <bestapi.h>
int main( void ) {
unsigned short inval;
int xInput, yInput, rightValue,leftValue;
InitBrain(); // initialize the system
while(1) { // do this forever, remap start
yInput=parabolicScale(getRcValue(1,16,100),125)-RCIDLEVAL; //speed
xInput=parabolicScale(getRcValue(0,16,100),125)-RCIDLEVAL; //steer
leftValue = yInput + xInput; // combine the inputs
rightValue = yInput - xInput; // to create output deltas
// bound the delta values (remember RCIDLEVAL is half RCMAXVAL)
if (leftValue > RCIDLEVAL) leftValue = RCIDLEVAL;
if (leftValue < -RCIDLEVAL) leftValue = -RCIDLEVAL;
if (rightValue > RCIDLEVAL) rightValue = RCIDLEVAL;
if (rightValue < -RCIDLEVAL) rightValue = -RCIDLEVAL;
// protobot: m0 = lift, m1=leftw, m2 = rightw
inval = parabolicScale( getRcValue(3,50,100), 125); // c4=c3 left
side to side stick
setMotor(0,inval); // set lift motor, needs limit switch!
// output the values and include the idle offset
setMotor(1,rightValue+RCIDLEVAL); // right wheel is m1 = 2
setMotor(2,leftValue+RCIDLEVAL); // left wheel is m2 = 3
// end remap
// add Joey reversable servo code from channel3 = enum2
inval = parabolicScale( getRcValue(2,50,100), 125); // c3=2 left
updown stick
setServo(0, inval); // servo1 follow left updown stick
setServo(1, RCMAXVAL - inval ); // invert servo 2
}
}