Hackpads are smart collaborative documents. .

陳致佑

96 days ago
550 days ago
Unfiled. Edited by 施季青 , 陳致佑 550 days ago
  • 設計機構雛形
 
  • 1/20進度,新增c code
  •  
  • void PosToAng(float ang[],float x,float y,float z){
  •     float r;
  •     float pi = 3.1415926535897;
  •  
  •     //limit state
  •     if(x > 300 || x < -300){
  •         x = 1; printf("x is out of range!\n value should be -300 < x < 300\n");
  •     }
  •     if(y > 300 || y < 0){
  •         y = 1; printf("y is out of range!\n value should be 0 < y < 300\n");
  •     }
  •  
  •     //calculate angle
  •     r = sqrt(x*x + y*y);
  •     printf("r: %f\n",r);
  •     ang[1] = acos(r/320) * (180/pi);
  •     ang[2] = asin(x/r) * (180/pi)+90;
  •     ang[0] = ang[1]+10;
  •  
  •     //z axis
  •     if(z == 1.0){
  •         //z = 0 means the pen is down
  •         ang[0]-=10;
  •     }
  •  
  •     //reverse 0~180
  •     ang[2] = abs(180 - ang[2]);
  • }
  •  
  • int main()
  • {
  •     float pos[]={40,0,1};
  •     float ang[] = {1,1,1};
  • //read data
  •     FILE *fPtr;
  •     fPtr = fopen("B.txt", "r");
  •     if (fPtr)
  •         printf("open success...\n");
  •     else
  •         printf("open fail...\n");
  •  
  • //calculate angle
  •     while(!feof(fPtr)){
  •         fscanf(fPtr,"%f %f %f\n",&pos[0],&pos[1],&pos[2]);
  •         printf("pos: %f %f %f\n",pos[0],pos[1],pos[2]);
  •         PosToAng(ang,pos[0],pos[1],pos[2]);
  •         printf("ang: %f %f %f\n",ang[0],ang[1],ang[2]);
  •         //here can place the motor call function
  •     }
  •     fclose(fPtr);
  •     return 0;
  • }
  •  
1/20
 

Contact Support



Please check out our How-to Guide and FAQ first to see if your question is already answered! :)

If you have a feature request, please add it to this pad. Thanks!


Log in