Trouble with function calling
hi all
could 1 me sketch , doesn't work , sketch has function takes 5 parameters , return float 1 , when try call function , on serial monitor , statement of "firststate" appeared before function call , neither returned value function , nor statement of "secondstate" appear , there syntax error in function body ?
could 1 me sketch , doesn't work , sketch has function takes 5 parameters , return float 1 , when try call function , on serial monitor , statement of "firststate" appeared before function call , neither returned value function , nor statement of "secondstate" appear , there syntax error in function body ?
code: [select]
const float golx=12;
const float goly=14;
const float n=0.005;
const int dstar=1;
const float qstar=1.5;
const float zeta=0.5;
float qx,qy,d1,d2,d3,th,zzz;
int obs1[2]; // array
int obs2[2];
int obs3[2];
float gatt [2];
float grep [2];
float resultant [2];
void setup() {
// put setup code here, run once:
serial.begin(115200);
}
void loop() {
// put main code here, run repeatedly:
serial.println("firststate");
zzz=apftt(3,4,1,1.4,3);
serial.println(zzz);
serial.println("secondstate");
}
float apftt (float xc,float yc,float sf,float sl,float sr) {
qx=xc;
qy=yc;
float dq ;
dq = sqrt (pow((qx-golx),2) + pow((qy-goly),2));
if (dq < dstar )
{
gatt [1]= zeta * (qx - golx);
gatt [2]= zeta * (qy - goly);
}
else
{
gatt[1] =dstar * zeta * (qx - golx )/ dq;
gatt[2] =dstar * zeta * (qy - goly )/ dq;
}
d1 = sf;
if (d1<qstar && d1>0){
obs1[1] = xc + d1;
obs1[2] = yc + d1;
grep[1] = grep[1] + (n * ( (1/qstar) - (1/d1) ) * ((qx - obs1[1])/ pow(d1,2)));
grep[2] = grep[2] + (n * ( (1/qstar) - (1/d1) ) * ((qy - obs1[2])/ pow(d1,2))); }
d2 = sl;
if (d2<qstar && d2>0){
obs2[1] = xc + d2;
obs2[2] = yc + d2;
grep[1] = grep[1] + (n * ( (1/qstar) - (1/d2) ) * ((qx - obs2[1])/ pow(d2,2)));
grep[2] = grep[2] + (n * ( (1/qstar) - (1/d2) ) * ((qy - obs2[2])/ pow(d2,2))); }
d3 = sr;
if (d3<qstar && d3>0){
obs3[1] = xc + d3;
obs3[2] = yc + d3;
grep[1] = grep[1] + (n * ( (1/qstar) - (1/d3) ) * ((qx - obs3[1])/ pow(d3,2)));
grep[2] = grep[2] + (n * ( (1/qstar) - (1/d3) ) * ((qy - obs3[2])/ pow(d3,2))); }
// resultant = -1* (gatt + grep);
resultant[1] = -1* (gatt[1] + grep[1]);
resultant[2] = -1* (gatt[2] + grep[2]);
th= atan2(resultant[2] , resultant[1]);//%* 180/3.14 ;
return th;
}
hi maria88
when declare arrays 2 elements, these elements numbered 0 , 1. in code, however, trying access elements numbered 1 , 2.
reading element 2 give incorrect data. writing element 2 corrupt memory , cause strange behaviour.
try correcting , see if helps problem.
regards
ray
code: [select]
int obs1[2]; // array
...
obs1[1] = xc + d1;
obs1[2] = yc + d1;
when declare arrays 2 elements, these elements numbered 0 , 1. in code, however, trying access elements numbered 1 , 2.
reading element 2 give incorrect data. writing element 2 corrupt memory , cause strange behaviour.
try correcting , see if helps problem.
regards
ray
Arduino Forum > Using Arduino > Programming Questions > Trouble with function calling
arduino
Comments
Post a Comment