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.

void  inverseKinematics()
{
  FILE * pFile;
  pFile = fopen ("myfile.txt","a");

  double Px, Py, Pz;

  Px = P[0], Py = P[1], Pz = P[2]; 
 	printf("Target  Position: x=%6.2f y=%6.2f z=%6.2f \n", Px, Py, Pz);
	printf("This is a trick!!!\n");

  double tmpL  = sqrt(Px * Px + Py * Py);
  double P1P   = sqrt(Px * Px + Py * Py 
							 + (Pz - (l[0] + l[1])) * (Pz - (l[0] + l[1]))); 
  double Ca    = (l[2] * l[2] + P1P * P1P -l[3] * l[3])/(2 * l[2] * P1P); 

  double phi   = atan2(Pz - (l[0] + l[1]), tmpL);                     
  double alpha = atan2(sqrt(1 - Ca * Ca), Ca);                        

  double Cb    = (l[2]*l[2] + l[3]*l[3] - P1P*P1P)/(2 * l[2] * l[3]);  
  double beta  = atan2(sqrt(1- Cb * Cb), Cb);                          

  switch (ANSWER) { 
  case 1:                                                                          
    THETA[1] = atan2(Py, Px);
    THETA[2] = M_PI/2 - phi - alpha;
    THETA[3] = M_PI - beta; break;
  case 2:                                                                       
    THETA[1] = atan2(Py, Px);
    THETA[2] = M_PI/2 - phi + alpha;
    THETA[3] = M_PI + beta; break;
  case 3:                                                                         
    THETA[1] = atan2(Py, Px) + M_PI;
    THETA[2] = -(M_PI/2 - phi - alpha);
    THETA[3] = M_PI + beta; break;
  case 4:                                                                     
    THETA[1] = atan2(Py, Px) + M_PI;
    THETA[2] = -(M_PI/2 - phi + alpha);
    THETA[3] = M_PI - beta; break;
   }
printf("Arm Angles: theta1=%6.2f theta2=%6.2f theta3=%6.2f \n", THETA[1], THETA[2], THETA[3]);
fprintf (pFile, "theta1: %f",THETA[1]);
fprintf (pFile, "theta2: %f",THETA[2]);
fprintf (pFile, "theta3: %f \n",THETA[3]);
fclose (pFile);
}

Recommended Answers

All 4 Replies

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 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.

Oh I see those now :) .. I do need to look closer

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.