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!