View Single Post
  #2   Spotlight this post!  
Unread 27-06-2011, 02:13
Jeremy Germita's Avatar
Jeremy Germita Jeremy Germita is online now
Co-Advisor/Lead Engineering Mentor
AKA: wood is good. plastic is fantastic.
FRC #5012 (Gryffingear) / (Antelope Valley FIRST Teams)
Team Role: Coach
 
Join Date: Jan 2010
Rookie Year: 2007
Location: Lancaster, CA
Posts: 284
Jeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond reputeJeremy Germita has a reputation beyond repute
Re: Joystick recording for Auton.

In the past, we have used file operations to log various values like gyro headings or motor current readings.

File operations for FRC are just as they are in Java SE.
This is our DataLogger class:
Code:
import java.io.*;
import javax.microedition.io.Connector;
/**
 * Data Logger Class
 * @author Jeremy Germita
 */
public class DataLogger {

    private PrintStream m_printStream;
    private DataLogger m_instance;


    /**
     * Constructor
     * @param fileName the filename to write to
     */
    public DataLogger(String fileName) {
        try {
            OutputStream m_output = Connector.openOutputStream(fileName);
            m_printStream = new PrintStream(m_output);
        } catch(IOException ioe) {
            ioe.printStackTrace();
        }
    }

    /**
     * Get instance of datalogger
     * @param fileName the filename to write to
     * @return the instance of the DataLogger
     */
    public DataLogger getInstance(String fileName) {
        if(m_instance == null) {
            m_instance = new DataLogger(fileName);
        }
        return m_instance;
    }

    /**
     * Print data, followed by a newline character to the printstream and flush it
     * @param data the data to print
     */
    public void println(String data) {
        m_printStream.println(data);
        m_printStream.flush();
    }

    /**
     * Print data to the printStream and flush it
     * @param data
     */
    public void print(String data) {
        m_printStream.print(data);
        m_printStream.flush();
    }

    /**
     * Close the printStream
     */
    public void close() {
        m_printStream.close();
    }

}
You simply provide the file path in the constructor and you can write data to that file using the print/println methods. A note: you must call the close method after you write the data.

The cRio's file paths are in this format:
Code:
file:///Your_File_Is_In_The_Root.txt
If you need any help in reading that information from the file, I can dig up that code for you as well.

As mentioned in the previous thread, be wary of writing data too many times.
For recording joystick values, I recommend reading values (and writing to the file) every 50-100ms, or every 2-4 loops in autonomous/teleop/disabledPeriodic. Your Mileage May Vary.
__________________
Drive Coach Team 5012 Gryffingear / Antelope Valley FIRST teams / EWCP - (2013 - Current)
Student / Driver / Programmer / CAD - FRC Team 399: Eagle Robotics / FTC Team 72: GarageBots - (2009 - 2013)
Los Angeles Region FTC FTA/CSA/Head Ref
[FF] FIRST Pick
2014 FTC Los Angeles Regional Compass Award Winner.

2017 - San Diego Regional / Sacramento Regional / Las Vegas Regional
2016 - Los Angeles Regional Creativity + Winners (1197, 987, 5012) / Las Vegas Regional Team Spirit + SF (5012, 5851, 5049) / Galileo Subdivision
2015 - Inland Empire QF (597, 5012, 4413) / Las Vegas Imagery + Winners (148, 987, 5012) / Newton Subdivision and World Champions (118, 1678, 1671, 5012)
2014 - Inland Empire Rookie All Star + Highest Rookie Seed + SF (2339, 1967, 5012) / Las Vegas Rookie All Star / Galileo Division Imagery

Last edited by Jeremy Germita : 27-06-2011 at 02:15. Reason: forgot imports