| | |
trouble collecting data to external file frorm a call inside a function
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 19
Reputation:
Solved Threads: 0
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.
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.
C Syntax (Toggle Plain Text)
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); }
•
•
Join Date: Oct 2007
Posts: 305
Reputation:
Solved Threads: 43
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.
•
•
•
•
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; ...... }
>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
•
•
Join Date: Apr 2008
Posts: 19
Reputation:
Solved Threads: 0
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.
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.
![]() |
Other Threads in the C Forum
- Previous Thread: assignment from incompatible pointer type
- Next Thread: trouble with creating a database
Views: 631 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C
* adobe api append array arrays bash binarysearch char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory drawing dynamic executable execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux highest homework i/o ide infiniteloop initialization interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lowest matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send single socketprogramming spoonfeeding stack standard strchr string student suggestions system test testautomation unix urboc user whythiscodecausesegmentationfault win32 win32api windows.h







.. I do need to look closer