Joystick recording for Auton.

Hello all.
So I am working on an off season project that involves writing a program (JAVA) that allows the robot to record joystick values and then be able to play them back in auton.
Such as what Team 1717 did in the book, The New Cool (awesome btw).

I was first thinking to just have the program, print all the values in an text file however then ran into the problem how the heck do you do that on a cRIO?

In addition saw this thread earlier:

As anyone used ^ successfully? Or done have done this before?
Thanks

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:


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:

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.

One of the things you will probably find if you go the route of playing back joystick commands is that your bot is going to do somewhat different things each time! Maybe one time it will drive further, or not turn quite the same amount, as the time before. Why is this?

When you are recording a joystick command during teleop, that command is usually being sent as a PWM value (you can think of this as an “average voltage”) to a motor. But what happens if you record the data with a 12.8V battery, then play it back with a 12.5V battery? Or if your wheels have worn a bit. Or if it’s warmer than when you first recorded. Or if there’s a slight uneven spot in the carpet. Etc. Etc.

You will get slight differences that might mean the difference between hanging that ubertube and dropping it to the left of the peg!

I very much recommend you do what you set out to do, as it is a great learning exercise. But if you are not satisfied with the repeatability of the solution, don’t stop there! You will learn about great tools such as sensors (encoders + gyros) and control algorithms (PID controllers) if you keep investigating. Imagine if you recorded the wheel speeds instead of the joystick or PWM values. If you know you want to go 5 feet per second, and have a sensor that can measure your current speed, there are techniques to force your wheel to go 5 feet per second regardless of battery, environment, wear, etc.

Wow, I love this idea. Would love to hear any results as far as repeatability goes.

One tip: use an actual timer or encoders. Do not rely on a "counter’ where you increase the value every clock cycle. From my experiments, the counter method is reliable only about 90% of the time. In the 10%, the values end up being so dramatic that I would never trust it in competition.