trouble collecting data to external file frorm a call inside a function

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 19
Reputation: rob_xx17 is an unknown quantity at this point 
Solved Threads: 0
rob_xx17 rob_xx17 is offline Offline
Newbie Poster

trouble collecting data to external file frorm a call inside a function

 
0
  #1
Oct 3rd, 2008
Hell,

This might be a big vague, but I hope that someone might be able to help me.

I have a program that does virtual simulation of robotic arm using inverse kinematics. The program works fine but right now I'm trying to collect some data, generated inside the program, into an external file for later manipulation (I'm going to train an artificial neural network). The problem that I'm having is that, for some reason, I'm only able to collect subset of generated data, meaning that not all of the data generated inside the program is passed into the external file. I'm also not quite sure about how to determine when the data collection process is stopped. Thanks.

r.

  1. void inverseKinematics()
  2. {
  3. FILE * pFile;
  4. pFile = fopen ("myfile.txt","a");
  5.  
  6. double Px, Py, Pz;
  7.  
  8. Px = P[0], Py = P[1], Pz = P[2];
  9. printf("Target Position: x=%6.2f y=%6.2f z=%6.2f \n", Px, Py, Pz);
  10. printf("This is a trick!!!\n");
  11.  
  12. double tmpL = sqrt(Px * Px + Py * Py);
  13. double P1P = sqrt(Px * Px + Py * Py
  14. + (Pz - (l[0] + l[1])) * (Pz - (l[0] + l[1])));
  15. double Ca = (l[2] * l[2] + P1P * P1P -l[3] * l[3])/(2 * l[2] * P1P);
  16.  
  17. double phi = atan2(Pz - (l[0] + l[1]), tmpL);
  18. double alpha = atan2(sqrt(1 - Ca * Ca), Ca);
  19.  
  20. double Cb = (l[2]*l[2] + l[3]*l[3] - P1P*P1P)/(2 * l[2] * l[3]);
  21. double beta = atan2(sqrt(1- Cb * Cb), Cb);
  22.  
  23. switch (ANSWER) {
  24. case 1:
  25. THETA[1] = atan2(Py, Px);
  26. THETA[2] = M_PI/2 - phi - alpha;
  27. THETA[3] = M_PI - beta; break;
  28. case 2:
  29. THETA[1] = atan2(Py, Px);
  30. THETA[2] = M_PI/2 - phi + alpha;
  31. THETA[3] = M_PI + beta; break;
  32. case 3:
  33. THETA[1] = atan2(Py, Px) + M_PI;
  34. THETA[2] = -(M_PI/2 - phi - alpha);
  35. THETA[3] = M_PI + beta; break;
  36. case 4:
  37. THETA[1] = atan2(Py, Px) + M_PI;
  38. THETA[2] = -(M_PI/2 - phi + alpha);
  39. THETA[3] = M_PI - beta; break;
  40. }
  41. printf("Arm Angles: theta1=%6.2f theta2=%6.2f theta3=%6.2f \n", THETA[1], THETA[2], THETA[3]);
  42. fprintf (pFile, "theta1: %f",THETA[1]);
  43. fprintf (pFile, "theta2: %f",THETA[2]);
  44. fprintf (pFile, "theta3: %f \n",THETA[3]);
  45. fclose (pFile);
  46. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: trouble collecting data to external file frorm a call inside a function

 
0
  #2
Oct 3rd, 2008
You probably want to put a break after each case statement in your switch ? otherwise it will just go onto the next one

switch (number){
  case 1:
   break;
  case 2:
   break;
   ......
}
Last edited by stilllearning; Oct 3rd, 2008 at 6:21 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,048
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 179
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: trouble collecting data to external file frorm a call inside a function

 
0
  #3
Oct 3rd, 2008
Originally Posted by stilllearning View Post
You probably want to put a break after each case statement in your switch ? otherwise it will just go onto the next one

switch (number){
  case 1:
   break;
  case 2:
   break;
   ......
}
You need to look a little bit closer. There are breaks where they are intended to be.

>I'm having is that, for some reason, I'm only able to collect subset of generated data, meaning that not all of the data generated inside the program is passed into the external file.

I am not quite sure what its the question.
The program is saving to file only the three floating points you ask to save:THETA[1], THETA[2], THETA[3]. It makes me wonder where's THETA[0].
Also from this point of view, I don't know what ANSWER is, or where it comes from.
Neither P[0],P[1],P[2] are local to inverseKinematics() so I wouldn't know what they are. I just bring it up because the function relays heavily in exterior global variables.

Nevertheless, I wouldn't feel comfortable with pFile = fopen ("myfile.txt","a"); by itself.
It is always imperative to check that the result is an open file ready to accept data.
And so a check it is a must with every call to fprintf() writing to file.
Last edited by Aia; Oct 3rd, 2008 at 7:06 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 305
Reputation: stilllearning has a spectacular aura about stilllearning has a spectacular aura about 
Solved Threads: 43
stilllearning stilllearning is offline Offline
Posting Whiz

Re: trouble collecting data to external file frorm a call inside a function

 
0
  #4
Oct 3rd, 2008
Oh I see those now .. I do need to look closer
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 19
Reputation: rob_xx17 is an unknown quantity at this point 
Solved Threads: 0
rob_xx17 rob_xx17 is offline Offline
Newbie Poster

Re: trouble collecting data to external file frorm a call inside a function

 
0
  #5
Oct 5th, 2008
I guess I should have mentioned that I'm using MinGW/MSYS as my environment.

What I was able to notice is that when I send the data to the external file, that file ONLY collects 509 lines of code. Not 508 or 510, but exactly 509 upon a single execution. I can restart the program and another 509 lines will be collected. Which makes me believe that either MinGW/MSYS or ODE (Open Dynamics Engine, which is the set of libraries that I'm using for this physics based/constrain simulation) puts this restriction. Has anyone heard anything about this? Is the any way of bypassing that? Thanks.

r.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 631 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC