All Classes Namespaces Files Functions Variables Typedefs
Functions | Variables
phidget_reader.cpp File Reference
#include <ros/ros.h>
#include <math.h>
#include <std_msgs/Float32.h>
#include <std_msgs/String.h>
#include <std_msgs/Bool.h>
#include <string>
#include <phidget_ik/phidget_ik.h>
#include <Grijper/command.h>
Include dependency graph for phidget_reader.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Main method reading the phidget at a specified frequency and smoothing the signal before passing it on. More...
 
int mean ()
 Method for calulating the mean of the buffer to pass on to the controller. More...
 
void printbuffer ()
 A small control method to print the buffer. More...
 
float sensorToDistance (int sensorValue)
 simple calculation method to extract a distance from the sensor value. More...
 
void shiftBuffer (int data)
 Method for shifting the buffer and inserting the newest sensor value. More...
 
void shutdown (const std_msgs::Bool::ConstPtr &b)
 Controll method to shutdown this ROS node when the command is given. More...
 

Variables

int buffer [buffer_size]
 
const int buffer_size = 25
 
const int freq = 250
 
const int sensor_id = 4
 

Function Documentation

int main ( int  argc,
char **  argv 
)

Main method reading the phidget at a specified frequency and smoothing the signal before passing it on.

Here the phidget is read at a fixed interval, given by freq. These values are stored in the buffer and sliding mean smoothing is applied. This ensures a less spikey signal for the controller and impulses are filtered out. This also means that the system has a longer response time, but by increasing the frequency this is nullified. The buffer acts as a queue, shifting the values every time before calculating a mean value to pass on to the controller.

See Also
shiftBuffer(int), mean()

Definition at line 32 of file phidget_reader.cpp.

int mean ( )

Method for calulating the mean of the buffer to pass on to the controller.

This method calculated the mean of the values in the buffer.

Returns
The calculated mean.
See Also
shiftBuffer(int)

Definition at line 102 of file phidget_reader.cpp.

void printbuffer ( )

A small control method to print the buffer.

Prints the buffer for each iteration so the calculated mean value can be evaluated.

See Also
mean()

Definition at line 116 of file phidget_reader.cpp.

float sensorToDistance ( int  sensorValue)

simple calculation method to extract a distance from the sensor value.

This method converts the sersorvalue to a distance.

Parameters
sensorValueThe value of the sensor.
Returns
The calculated distance.

Definition at line 132 of file phidget_reader.cpp.

void shiftBuffer ( int  data)

Method for shifting the buffer and inserting the newest sensor value.

This method shifts all the data elements in the buffer to make place for the new sensor data. The buffer is initialised as an array filled with '1', so the first buffer_size values will be invalid.

Parameters
dataThe new sensor value to be shifted into the buffer.
See Also
mean()

Definition at line 89 of file phidget_reader.cpp.

void shutdown ( const std_msgs::Bool::ConstPtr &  b)

Controll method to shutdown this ROS node when the command is given.

This method will shutdown this node when the command is given by the console.

Parameters
bThe message containing the command. Nothing is done with the command since we know what it will be when this message is received.

Variable Documentation

int buffer[buffer_size]

The buffer used for smoothing.

Definition at line 21 of file phidget_reader.cpp.

const int buffer_size = 25

Value buffer size for signal smoothing.

Definition at line 20 of file phidget_reader.cpp.

const int freq = 250

The frequency at which the sensor should be read and the value passed on.

Definition at line 19 of file phidget_reader.cpp.

const int sensor_id = 4

The sensor ID.

Definition at line 18 of file phidget_reader.cpp.



Grijper
Author(s): Stijn van Schooten, Wybren ten Cate, Florens Kreuk, Jan Wymenga,Joris Coenen, Roy Groot
autogenerated on Thu Oct 3 2013 22:59:42