Class ReaderM

  • All Implemented Interfaces:
    java.lang.Runnable

    public class ReaderM
    extends java.lang.Thread
    Start a SerialPortreader and interpret the incoming bytes from the serial port.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$, $Id$
    Author:
    Hunter Massey and Rajesh Kuni
    See Also:
    SerialPortController
    Pt.AcceptedRating:
    Pt.ProposedRating:
    Yellow Hunter
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean isStart
      True when the thread has been started.
      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Constructor Summary

      Constructors 
      Constructor Description
      ReaderM​(int com, int baudRate, int window)
      Construct a ReaderM.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      CircularFifoQueue<int[]> getBuffer()
      Return the sample buffer.
      int getBufIndex()
      Return the current index in the circular buffer.
      int[] getNextUnreadSample()
      Get the next unread sample from the sample buffer.
      void preProcess​(int[] raw)
      Grab the individual raw sensor (accelerometer and gyroscope) values and store them into the circular sample buffer as a 6 integer array.
      void run()
      Read the packets from the IMU and decode them.
      void stopRead()
      Close the serial port and end the connection.
      int UCharToInt​(char a, char b)
      Convert two 'unsigned char's to an integer by shifting and adding.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • isStart

        public boolean isStart
        True when the thread has been started.
    • Constructor Detail

      • ReaderM

        public ReaderM​(int com,
                       int baudRate,
                       int window)
        Construct a ReaderM.
        Parameters:
        com - The comm port number to connect to
        baudRate - The baud rate at which the connection runs
        window - The window size of the circular sample buffer
    • Method Detail

      • run

        public void run()
        Read the packets from the IMU and decode them.
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • preProcess

        public void preProcess​(int[] raw)
        Grab the individual raw sensor (accelerometer and gyroscope) values and store them into the circular sample buffer as a 6 integer array.
        Parameters:
        raw - The integer array containing all the sensor values (ADC values)
      • getBuffer

        public CircularFifoQueue<int[]> getBuffer()
        Return the sample buffer.
        Returns:
        The circular sample buffer
      • stopRead

        public void stopRead()
        Close the serial port and end the connection.
      • getBufIndex

        public int getBufIndex()
        Return the current index in the circular buffer.
        Returns:
        the current write index into the circular buffer
      • getNextUnreadSample

        public int[] getNextUnreadSample()
        Get the next unread sample from the sample buffer.
        Returns:
        the current read index into the circular buffer
      • UCharToInt

        public int UCharToInt​(char a,
                              char b)
        Convert two 'unsigned char's to an integer by shifting and adding. As a note, Java does not actually have unsigned values but we treat these chars as such.
        Parameters:
        a - The most significant 8 bits of the integer in char form
        b - The least significant 8 bits of the integer in char form
        Returns:
        The integer value from the two input unsigned chars