Last year, my school's FTC robotics team had trouble making an autonomous program, and so we didn't get as many points as we wanted to. This year, I am trying to implement the autonomous section of the match into the robot's program. I thought that it would be a good idea to have a pre-match configuration program that would create a file that the autonomous program could then read before the waitForStart() function. I would like some help with this due to the fact that the RobotC help file doesn't really say all that much (no examples) about the file access section of the nxt functions.

Robert Allen, Glencoe High School

Sat Dec 03, 2011 9:17 pm

bfeher

Site Admin

Joined: Mon Jun 08, 2009 4:50 pmPosts: 70

Re: Help with file access usage

Hi Robert Allen,

Below is a small sample for reading and writing strings and bytes. If you are working with numbers but like to read in chars you can always store your numbers as a string and then convert them back to ints and floats after reading them with atoi("3.14") and atof("3.14"). Anyways, have a look at the code below and feel free to respond with any questions. We are currently working on an API revamp that we hope everybody will find much more useful than our current documentation.

string sMessageToWrite = "ROBOTC IO test!"; // we will write this to the file string sMesageToWrite_2 = "A new line!"; // we will also write this to the file on the next line char incommingChar; // this will store each char as we read back in from the file string incommingString[5]; // this will store the final, fully-read strings (with new strings getting put into new indexes int nLineCounter = 0; // this will let us know which line we are on when reading and writing (used as the index to 'incommingString[]')

for(int i = 0; i < nFileSize; i++) // iterate through the file until we've hit the end: { ReadByte(hFileHandle, nIOResult, incommingChar); // read in a single byte

if(incommingChar == CR || incommingChar == LF) // if the incomming byte is a carriage return or a line feed: { if(incommingChar == LF) // if it's a line feed: nLineCounter++; // increment our index (will now store next char on a 'new line' (a new index into our 'incommingString[]') } else { incommingString[nLineCounter] += incommingChar; // append that byte (char) to the end of our final string, at the right index } } Close(hFileHandle, nIOResult); // close our file (DON'T FORGET THIS STEP!)

EV3 External Controller (TETRIX, MATRIX) Support Daisy Chaining EV3's together and using chained motors/sensors Wifi Download and Debugging Joystick Support for EV3 File System Commands (Read/Write files in a ROBOTC program)

As of right now, file system commands are not fully compatible with the EV3 platform. It is on our list of things to develop, however, and we hope to have a build with this functionality available as soon as possible.

I fixed it by changing thet type of the nFileSize variable to be short, but is there any other way to overcome this problem and make it work with int as well as short?

Sat May 23, 2015 11:13 pm

alberthandsome

Rookie

Joined: Thu Jun 30, 2016 3:10 amPosts: 4

Re: Help with file access usage

I have a friend who owns some websites, one is an info site and two are forums and he got a message from the host that it's getting too big in CPU usage and there is a problem that it could be shut down. He has been working very hard on these sites and has been paying for them out of his own pocket but he really can't afford to pay any more then he already is. Many people use his sites and it would be very disappointing if it was to go down. He was told by the hosts that if they moved to a RootDS Server they would be able to keep the sites but the problem is that the cost would be much more. I was just wondering if any of you had any solutions or any suggestions that would help out with the amount of usuage being used. People are already willing to donate some, but I don't think that will be enough. We are guide to u.

Who is online

Users browsing this forum: No registered users and 2 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum