Function in C++


dears , hi

i have function written in matlab takes 5 variables , return 1 , convert in c++ , think many of statements in function  same in c/c++, don't know statements need rewritten convenient c++ form . please



code: [select]
function th =apfpreogram(xc,yc,sf,sl,sr)


qx=xc; qy=yc;     

golx=12.8; goly=14;
%
obs1=[0 0];   
obs2=[0 0];
obs3=[0 0];


resultant = [0.001;0.001 ];
 

    zeta = 0.1;

    dq = sqrt (   (qx-golx)^2 + (qy-goly)^2   );

    dstar = 1;

    if  dq < dstar
       
        gatt = zeta * ( [qx ; qy] - [golx ; goly]);     
    else     
        gatt = dstar * zeta * ( [qx ; qy] - [golx ; goly]) / dq;       
    end
   

    grep = [ 0;  0];

    qstar = 1.5;

    n = 0.005;

m=1;
         d1 = sf;
   
            if (d1<qstar && d1>0)
           
             
                obs1(1) = xc + d1;
                obs1(2) = yc + d1;
             
grep = grep + (  n * (   (1/qstar) - (1/d1)   ) * (([qx ; qy]-[obs1(1) ; obs1(2)])/ d1^2) );

     
            end
   
     
                     d2 = sl;
 
           if (d2<qstar && d2>0) 
         
           
                obs2(1) = xc + d2;
                obs2(2) = yc + d2;
             
grep = grep + (  n * (   (1/qstar) - (1/d2)   ) * (([qx ; qy]-[obs2(1) ; obs2(2)])/ d2^2) );

     
          end
           
           
          d3 = sr;
   
          if (d3<qstar && d3>0) 
             
           
                obs3(1) = xc + d3;
                obs3(2) = yc + d3;
             
grep = grep + (  n * (   (1/qstar) - (1/d3)   ) * (([qx ; qy]-[obs3(1) ; obs3(2)])/ d3^2) );

     
         end
 
    resultant = -1* (gatt + grep);


    new = [qx ; qy] + resultant;

    dmoved = sqrt (  (qx-new(1))^2 + (qy-new(2))^2  );
   
 
    xth= new(1) - qx    ;
    yth=new(2) - qy    ;
   

     
   qx = new(1);
   qy = new(2);

   
   th= (atan2(yth , xth)); ;

   


end

you need lean basic c/c++ syntax.   get elementary textbook.

fiirst place need start,  have declare variables using.   what's qx ?   what's qy ?

you don't need declare variables in matlab,  have in c/c++


Arduino Forum > Using Arduino > Programming Questions > Function in C++


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support