Acoustic Touch Recognition
Public Member Functions | Private Attributes | List of all members
InstanceBuilder Class Reference

Front-end to create instance objects step by step. More...

#include <libacoustic_touch.h>

Public Member Functions

 InstanceBuilder (string mode)
 Constructs the object. First sets up the ROS elements. More...
 
 ~InstanceBuilder ()
 Destroys the object. Now, since we're working with elements that auto-destroy properly its function is merely conventional. More...
 
void startGestureCallback (const std_msgs::Int8::ConstPtr &msg)
 Starts a gesture callback. More...
 
void endGestureCallback (const touch_gesture_msgs::SoundGesture::ConstPtr &msg)
 This callbacks first extract the info from the message, then modifies the appropriate sound gesture inside the class and finally triggers the timer that establish the end of the gesture. More...
 
bool optionsCallback (acoustic_touch_recognition::MenuOptions::Request &req, acoustic_touch_recognition::MenuOptions::Response &res)
 This is the training service callback. In the request it can receive changes in the three one of the class attributes or a shutdown request, commanding this object to close the file and shutdown this node. More...
 
void timerCallback (const ros::TimerEvent &)
 The timer callback ends when it is considered that the gesture is over. It is refreshed for each microphone that sends a gesture and once is finished, writes all the gestures in the file and cleans the container with the sound gestures. More...
 
void shutdownCallback (const ros::TimerEvent &)
 This callback allows the system to shutdown properly. Once the timer is set, the node sends back the signal to the client that sent in the first place the shutdown signal. More...
 
void setSoundGestures (vector< SoundGesture > s_gests)
 Sets the sound gestures at once. Might be unused but useful. More...
 
void setSoundGestures (SoundGesture s_gest, int index)
 Sets the sound gestures individually. More...
 
void clearSoundGestures ()
 This function clear every sound gesture in the vector (sets zeros to its attributes) and set the empty flag to true. More...
 
void clearSoundGestures (int index)
 Atomic function that erases all the attributes (substitutes them with zeros) from the selected sound gesture and set the empty flag to true. More...
 
void setClassAttributes (string index, string c_att)
 Sets the class attributes. Checks if the key is already in the container. More...
 
void setFile (string path)
 This function assigns the file path and opens the file. If the file was not created, the system will create the arff file from scratch. More...
 
void closeFile ()
 Closes the file. Used when receiving shutdown signal. More...
 
vector< SoundGesturegetSoundGestures () const
 Gets the sound gestures. More...
 
SoundGesture getSoundGestures (int index) const
 Gets the sound gestures. Atomic function. More...
 
void init ()
 Initializes the object by extracting the parameters from the parameter server, then the sound gesture-related and finally sets up the file that will be created or overwritten. More...
 
bool fileExists (string path)
 This function checks if a file with a certain name exists. More...
 
void createArffFile ()
 Creates an arff file. The format associated is the Multi-target Meka format. More...
 
void writeGestures ()
 Writes a gesture in the file of the class. When it is done clear the containers, setting the empty flags to true. More...
 

Private Attributes

ros::NodeHandle nh_
 
ros::Publisher gesture_pub_
 
ros::Subscriber gest_start_sub_
 
bool flag_start_sub_
 
ros::Subscriber gest_end_sub_
 
ros::ServiceServer settings_srv_
 
ros::Timer timer_
 
ros::Timer shutdown_timer_
 
string robot_
 
const string mode_
 
int mic_amount_
 
vector< SoundGesturesound_gestures_
 
XmlRpc::XmlRpcValue class_labels_
 
XmlRpc::XmlRpcValue train_labels_
 
vector< string > label_names_
 
string path_
 
fstream sound_file_
 

Detailed Description

Front-end to create instance objects step by step.

Constructor & Destructor Documentation

◆ InstanceBuilder()

InstanceBuilder::InstanceBuilder ( string  mode)

Constructs the object. First sets up the ROS elements.

Parameters
[in]modeThe mode. Can be "train" or "classify"

◆ ~InstanceBuilder()

InstanceBuilder::~InstanceBuilder ( )

Destroys the object. Now, since we're working with elements that auto-destroy properly its function is merely conventional.

Member Function Documentation

◆ clearSoundGestures() [1/2]

void InstanceBuilder::clearSoundGestures ( )

This function clear every sound gesture in the vector (sets zeros to its attributes) and set the empty flag to true.

◆ clearSoundGestures() [2/2]

void InstanceBuilder::clearSoundGestures ( int  index)

Atomic function that erases all the attributes (substitutes them with zeros) from the selected sound gesture and set the empty flag to true.

Parameters
[in]indexThe index of the element

◆ closeFile()

void InstanceBuilder::closeFile ( )

Closes the file. Used when receiving shutdown signal.

◆ createArffFile()

void InstanceBuilder::createArffFile ( )

Creates an arff file. The format associated is the Multi-target Meka format.

◆ endGestureCallback()

void InstanceBuilder::endGestureCallback ( const touch_gesture_msgs::SoundGesture::ConstPtr &  msg)

This callbacks first extract the info from the message, then modifies the appropriate sound gesture inside the class and finally triggers the timer that establish the end of the gesture.

Parameters
[in]msgThe message containing one sound gesture from one microphone

◆ fileExists()

bool InstanceBuilder::fileExists ( string  path)

This function checks if a file with a certain name exists.

Parameters
[in]pathThe path of the file with te name included
Returns
Returns true if the file exists, false otherwise

◆ getSoundGestures() [1/2]

vector< SoundGesture > InstanceBuilder::getSoundGestures ( ) const

Gets the sound gestures.

Returns
The sound gestures.

◆ getSoundGestures() [2/2]

SoundGesture InstanceBuilder::getSoundGestures ( int  index) const

Gets the sound gestures. Atomic function.

Parameters
[in]indexThe index
Returns
The sound gestures.

◆ init()

void InstanceBuilder::init ( )

Initializes the object by extracting the parameters from the parameter server, then the sound gesture-related and finally sets up the file that will be created or overwritten.

◆ optionsCallback()

bool InstanceBuilder::optionsCallback ( acoustic_touch_recognition::MenuOptions::Request &  req,
acoustic_touch_recognition::MenuOptions::Response &  res 
)

This is the training service callback. In the request it can receive changes in the three one of the class attributes or a shutdown request, commanding this object to close the file and shutdown this node.

Parameters
reqThe request containing the class attributes or the shutdown command
resThe response is just an integer
Returns
The service callbacks return true if the task has been done properly or false otherwise. This is because the client of the service is kept on hold until the task is finished.

◆ setClassAttributes()

void InstanceBuilder::setClassAttributes ( string  index,
string  c_att 
)

Sets the class attributes. Checks if the key is already in the container.

Parameters
[in]c_attThe class attribute value
[in]indexThe index, since is train_labels_ element is a map, the index is a string

◆ setFile()

void InstanceBuilder::setFile ( string  path)

This function assigns the file path and opens the file. If the file was not created, the system will create the arff file from scratch.

Parameters
[in]pathThe path

◆ setSoundGestures() [1/2]

void InstanceBuilder::setSoundGestures ( vector< SoundGesture s_gests)

Sets the sound gestures at once. Might be unused but useful.

Parameters
[in]s_gestsThe sound gestures

◆ setSoundGestures() [2/2]

void InstanceBuilder::setSoundGestures ( SoundGesture  s_gest,
int  index 
)

Sets the sound gestures individually.

Parameters
[in]s_gestThe sound gesture which will be copied.
[in]indexThe index. Check if it is out of bounds.

◆ shutdownCallback()

void InstanceBuilder::shutdownCallback ( const ros::TimerEvent &  )

This callback allows the system to shutdown properly. Once the timer is set, the node sends back the signal to the client that sent in the first place the shutdown signal.

Parameters
[in]ros::TimerEventContains info about the event (times, durations, etc.)

◆ startGestureCallback()

void InstanceBuilder::startGestureCallback ( const std_msgs::Int8::ConstPtr &  msg)

Starts a gesture callback.

Parameters
[in]msgThe message

◆ timerCallback()

void InstanceBuilder::timerCallback ( const ros::TimerEvent &  )

The timer callback ends when it is considered that the gesture is over. It is refreshed for each microphone that sends a gesture and once is finished, writes all the gestures in the file and cleans the container with the sound gestures.

Parameters
[in]ros::TimerEventWhen the time is over the timer pops a timer event, starting the callbacks associated with this events.

◆ writeGestures()

void InstanceBuilder::writeGestures ( )

Writes a gesture in the file of the class. When it is done clear the containers, setting the empty flags to true.

Member Data Documentation

◆ class_labels_

XmlRpc::XmlRpcValue InstanceBuilder::class_labels_
private

◆ flag_start_sub_

bool InstanceBuilder::flag_start_sub_
private

◆ gest_end_sub_

ros::Subscriber InstanceBuilder::gest_end_sub_
private

◆ gest_start_sub_

ros::Subscriber InstanceBuilder::gest_start_sub_
private

◆ gesture_pub_

ros::Publisher InstanceBuilder::gesture_pub_
private

◆ label_names_

vector<string> InstanceBuilder::label_names_
private

◆ mic_amount_

int InstanceBuilder::mic_amount_
private

◆ mode_

const string InstanceBuilder::mode_
private

◆ nh_

ros::NodeHandle InstanceBuilder::nh_
private

◆ path_

string InstanceBuilder::path_
private

◆ robot_

string InstanceBuilder::robot_
private

◆ settings_srv_

ros::ServiceServer InstanceBuilder::settings_srv_
private

◆ shutdown_timer_

ros::Timer InstanceBuilder::shutdown_timer_
private

◆ sound_file_

fstream InstanceBuilder::sound_file_
private

◆ sound_gestures_

vector<SoundGesture> InstanceBuilder::sound_gestures_
private

◆ timer_

ros::Timer InstanceBuilder::timer_
private

◆ train_labels_

XmlRpc::XmlRpcValue InstanceBuilder::train_labels_
private

The documentation for this class was generated from the following files: