Log in

View Full Version : Function for O over a serial.


Metalgod4eva
01-02-2007, 15:41
I am a happy computer programmer and well never played around with a robot before. Being a computer programmer I am use to the computer standard ways of doing things. I wrote this for the robot #include <stdio.h>
#define AMOUNT_OF_LINES 1
int reprint(void)
{
int i,x,r;
int farray[200],*fa;
FILE *fp;
fp = fopen("c:\\text3.txt", "r");
fa = &farray[0];

for(x=0;x<123;x++)
{

*(fa+x) = (fgetc( fp ));
printf("%s",fa+x);
}
fclose(fp);
}
int write(void)
{
int c,x,i,y,n, *sp, string[200];
sp = &string[0];
FILE *fp;
fp=fopen("c:\\text3.txt", "w");

for(x=0;x<3;x++){
scanf("%s",sp+x); }
for(n=0;n<3;n++) {
fprintf(fp,"%s",sp+n); }
fclose(fp);
}
int main() {
int x;
write();
reprint();
scanf("%d",x);
/* by metalgod4eva team 870 */
}
/*for loops not complete, still need to make another function */

Well as you can read its a nice file IO, I am looking to use the serial to O back to the computers hard drive and save and in looking in the source for the serial I found no O function back over its device. Maybe I just over looked it and its there or I will have to write it. If anyone has an idea or solution let me know. Also I think I might have to use fwrite instead of fprintf but no issues there. Dont complain if you do run it and find the garbage data I have not finished the fuction for the for loops yet. Thanks for your time and have a nice day!

bear24rw
01-02-2007, 18:35
The code for the robot isnt exactly like standard C for a computer, you might want to look at the default code

www.kevin.org/frc

And read the programming ref guide from IFI

http://www.ifirobotics.com/docs/legacy/2004-programming-reference-guide-12-apr-2004.pdf

chris31
01-02-2007, 20:54
If I understand this is what you want. Just Printf all you info like you normally would. But write a custom app that reads those values and logs them to a text file. Is that what you want?

Matt Krass
01-02-2007, 21:31
Even simpler, forget a custom App, depending on the kind of data you're using a properly formatted printf(), Hyperterm and Excel are your best friend.

I had to monitor the PID response for last years robot and a bunch of numbers wasn't doing it for me, so I had a printf like this:


printf("%d,%d,%d,%d,%d",kp, ki, kd, error, output); // This is a loose guess at what it was


Then I told HyperTerm to save to a file, and let the robot run, then using Notepad++ (it handles large text files better than notepad does) I trimmed out the section I needed and imported to Excel as a CSV (Comma Separated Values) file. Then I re-saved to .xls and started graphing, thanks to Mark McLeod for that awesome tip.