-2

I don't understand why this code won't run. I'm writing movement code for my Zero Robotics team, and my current system is to set the velocity target to a factor of the distance for every initial distance from the target position. I'm not looking for critique on the code, but I would love to understand why absolutely nothing happens when I run this code–I'd expect something to occur, at least. The sphere just sits there, doing nothing.

float tarPos[3];
float currDist[3];
float currPos[3];
float initPos[3];
float initDist[3];
float tarVelo[3];
float myZRState[12];
float powfResult[3];

void init()
{
    api.getMyZRState(myZRState);

    tarPos[0]=0.5f;
    tarPos[1]=0.0f;
    tarPos[2]=0.5f;
}

void moveTo(float target[3])
{
    api.getMyZRState(myZRState);

    currPos[0]=myZRState[0];
    currPos[1]=myZRState[1];
    currPos[2]=myZRState[2];

    currDist[0]=tarPos[0]-currPos[0];
    currDist[1]=tarPos[1]-currPos[1];
    currDist[2]=tarPos[2]-currPos[2];

    //tarVelo[0]=(100)*(currDist[0]);
    //tarVelo[1]=(100)*(currDist[1]);
    //tarVelo[2]=(100)*(currDist[2]);

    tarVelo[0]=powfResult[0]*currDist[0];
    tarVelo[1]=powfResult[1]*currDist[1];
    tarVelo[2]=powfResult[2]*currDist[2];

    api.setVelocityTarget(tarVelo);

    //DEBUG (( "powf result 1, powf result 2, powf result 3, init dist 1, init dist 2, init dist 3 \t %f %f %f %f %f %f" , powfResult[0] , powfResult[1] , powfResult[2] , initDist[0] , initDist[1] , initDist[2] ));
}

void loop()
{
    if (api.getTime()==0)
    {
        api.getMyZRState(myZRState);

        initPos[0]=myZRState[0];
        initPos[1]=myZRState[1];
        initPos[2]=myZRState[2];

        initDist[0]=tarPos[0]-initPos[0];
        initDist[1]=tarPos[1]-initPos[1];
        initDist[2]=tarPos[2]-initPos[2];

        if (initDist[0]==0)
        powfResult[0]=0;
        else
            powfResult[0]=(0.1508*(powf( initDist[0] , -0.56 )));
        if (initDist[1]==0)
            powfResult[1]=0;
        else
            powfResult[1]=(0.1508*(powf( initDist[1] , -0.56 )));
        if (initDist[2]==0)
            powfResult[2]=0;
        else
            powfResult[2]=(0.1508*(powf( initDist[2] , -0.56 )));
    }
    moveTo(tarPos);
}

EDIT: Solution found! I handed this off to the programming whiz at my school (his name's Bryce, you might want to keep an eye out for him in the future. Utter genius), along with my compsci teacher, and they figured out that there needed to be an absolute value around [code] initDist [/code] within the [code] powfResult [/code] initialization. Thanks for your help!

David Bluhm
  • 7
  • 2
  • 5
  • 1
    Nothing happens! well this code has not `main()`. I mean you should show what do you expect as result and show the complete relevant code. – masoud Sep 27 '13 at 16:55
  • 1
    I don't suppose you turned the robot *on* ? – WhozCraig Sep 27 '13 at 17:02
  • Might be you'd have better halp from someone at the zero robotics website? I just downloaded the tutorial, it has not `main()` as well. Knowing the external hooks would be helpful, and likely requires this mysterious "IDE" of theirs. What you've got there is a fragment of source, not a program. –  Sep 27 '13 at 17:06

1 Answers1

0

My first program might look something like this:

void init()
{
   DEBUG(("init entered\n"));
   DEBUG(("init leaving\n"));
}
void moveTo(float target[3])
{
   DEBUG (( "moveTo entered" ));
   DEBUG (( "moveTo leaving" ));
}
void loop()
{
   DEBUG (( "loop for David Bluhm entered\n" ));
   DEBUG (( "loop leaving\n" ));
}

If I could find the output after running it, I might gain a little faith in some of the API. (I'd definitely be outputting debug states the first few times I got things to move too)

PS - why are you calling: setVelocityTarget()

instead of: setPositionTarget()? (This is apparently the most basic location control)

  • 1
    Just so you guys know, this is a very specific style–the "main" method is replaced by the "loop" method, which calls once/second. – David Bluhm Sep 27 '13 at 17:36
  • @DavidBluhm I read the tutorial. When you said "nothing happens", it immediately occurs to me that the simplest "thing" one can cause to "happen" is debug/textual output. So... did you successfully write a bot that can output "Hello World"? If not, how can you expect something more complicated to work? –  Sep 27 '13 at 17:48
  • Oh! I forgot to mention something EXTREMELY important. I'm able to get the bot to move when I replace `powfResult` with a constant in the moveTo method. That's where I got the very complex, specific equation used in deriving `powfResult`: I collected data points and extrapolated a function for them. – David Bluhm Sep 27 '13 at 20:54
  • Also, I'm not using `setPositionTarget()` because `setPositionTarget()` is a crappy method. It moves the SPHERE to the target, but INCREDIBLY slowly. My goal here is to write the movement code for our team–and drastically improve upon the `setPositionTarget()` method. – David Bluhm Sep 27 '13 at 20:56
  • @DavidBluhm If you want specific help with a variable that you control yourself, cannot understand, and are closing your eyes to the actual value of (DEBUG was commented out) then you should say something to that effect instead of: "NOTHING WORKS". Advice #1: UNCOMMENT THE DEBUG STATEMENT!!! PS - Most of us aren't in High-school on this site. Therefore we cannot play with the IDE and working environment which you are in. Enjoy it, and I hope the competition goes well for you. Good luck. PPS - Equation may run backward. (more magnitude close less magnitude far) Particularly for 0 –  Sep 30 '13 at 16:06