MRD Lab / ServoRingBuffer

Dependents:   SpindleBot_1_5b

Embed: (wiki syntax)

« Back to documentation index

ServoRingBuffer Class Reference

ServoRingBuffer Class Reference

Servo ring buffer class, to store data between acquisiton and export. More...

#include <ServoRingBuffer.h>

Public Member Functions

 ServoRingBuffer ()
 Creates a ServoRingBuffer object.
void purge ()
 Clears a ServoRingBuffer object by setting the indices to zero.
void write (spindleData data)
 Adds data, filling the time from the timer.
void write (unsigned short pos0, unsigned short force0, unsigned short pos1=0, unsigned short force1=0)
 Adds data, filling the time from the timer.
void dumpBufferToSerial (void)
 Writes each unread line of a ServoRingBuffer object to serial as hex.
void dumpBufferToSD (FILE *txtFile)
 Writes each unread line of a text file on an SD card as hex.
unsigned int writesRemaining (void)
 Calculates how many spaces are left in the buffer for writing.
unsigned int readsRemaining (void)
 Calculates how many entries in the buffer are written but unread.
float percentFull (void)
 Normalized current fullness of buffer, for checking health of buffer.

Detailed Description

Servo ring buffer class, to store data between acquisiton and export.

Example:

 #include "mbed.h"
 #include "ServoRingBuffer.h"

 int main() {

   ServoRingBuffer Buffer;     //Set up ring buffer
   AnalogIn Ain(p20);          //Set up potentiometer on pin 20

   while (1) {

       // This section of code should run whenever data needs to be acquired
       Buffer.write(Ain.read_u16(),Ain.read_u16());

       // This section of code should run whenever there is free time to print to the screen
       Buffer.dumpBufferToSerial();
       wait (0.1);
   }
 }

Definition at line 59 of file ServoRingBuffer.h.


Constructor & Destructor Documentation

Creates a ServoRingBuffer object.

Definition at line 7 of file ServoRingBuffer.cpp.


Member Function Documentation

void dumpBufferToSD ( FILE *  txtFile )

Writes each unread line of a text file on an SD card as hex.

Definition at line 93 of file ServoRingBuffer.cpp.

void dumpBufferToSerial ( void   )

Writes each unread line of a ServoRingBuffer object to serial as hex.

Definition at line 74 of file ServoRingBuffer.cpp.

float percentFull ( void   )

Normalized current fullness of buffer, for checking health of buffer.

Return values:
Fractionof buffer with unread data, 0 -> 1

Definition at line 139 of file ServoRingBuffer.cpp.

void purge ( void   )

Clears a ServoRingBuffer object by setting the indices to zero.

Definition at line 19 of file ServoRingBuffer.cpp.

unsigned int readsRemaining ( void   )

Calculates how many entries in the buffer are written but unread.

Return values:
Numberof entries written but unread

Definition at line 129 of file ServoRingBuffer.cpp.

void write ( spindleData  data )

Adds data, filling the time from the timer.

Parameters:
dataThe object with the data in it

Definition at line 30 of file ServoRingBuffer.cpp.

void write ( unsigned short  pos0,
unsigned short  force0,
unsigned short  pos1 = 0,
unsigned short  force1 = 0 
)

Adds data, filling the time from the timer.

Parameters:
posInput position
forceInput force

Definition at line 52 of file ServoRingBuffer.cpp.

unsigned int writesRemaining ( void   )

Calculates how many spaces are left in the buffer for writing.

Note:
If this reads 1, you actually can't write anymore, because an entirely full buffer is identical to an entirely empty one, so we must always leave one entry blank. Sorry!
Return values:
Numberof entries available for writing (But never go below 1)

Definition at line 119 of file ServoRingBuffer.cpp.