Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ALChestButton] add chest button topic (pressed or not) #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions share/boot_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
{
"enabled" : true
},
"chest_button":
{
"enabled" : true
},
"odom":
{
"enabled" : true,
Expand Down
1 change: 1 addition & 0 deletions src/converters/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void TouchEventConverter<T>::callAll(const std::vector<message_actions::MessageA
template class TouchEventConverter<naoqi_bridge_msgs::Bumper>;
template class TouchEventConverter<naoqi_bridge_msgs::HandTouch>;
template class TouchEventConverter<naoqi_bridge_msgs::HeadTouch>;
template class TouchEventConverter<naoqi_bridge_msgs::ChestButtonPressed>;
}

}
1 change: 1 addition & 0 deletions src/converters/touch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <naoqi_bridge_msgs/Bumper.h>
#include <naoqi_bridge_msgs/HandTouch.h>
#include <naoqi_bridge_msgs/HeadTouch.h>
#include <naoqi_bridge_msgs/ChestButtonPressed.h>

/*
* ALDEBARAN includes
Expand Down
12 changes: 12 additions & 0 deletions src/event/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,21 @@ void TouchEventRegister<T>::touchCallbackMessage(std::string &key, bool &state,
}
}

template<class T>
void TouchEventRegister<T>::touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::ChestButtonPressed &msg)
{
for(std::vector<std::string>::const_iterator it = keys_.begin(); it != keys_.end(); ++it)
{
if ( key == it->c_str() ) {
msg.state = state?(naoqi_bridge_msgs::ChestButtonPressed::statePressed):(naoqi_bridge_msgs::ChestButtonPressed::stateReleased);
}
}
}

// http://stackoverflow.com/questions/8752837/undefined-reference-to-template-class-constructor
template class TouchEventRegister<naoqi_bridge_msgs::Bumper>;
template class TouchEventRegister<naoqi_bridge_msgs::HandTouch>;
template class TouchEventRegister<naoqi_bridge_msgs::HeadTouch>;
template class TouchEventRegister<naoqi_bridge_msgs::ChestButtonPressed>;

}//namespace
16 changes: 16 additions & 0 deletions src/event/touch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <naoqi_bridge_msgs/Bumper.h>
#include <naoqi_bridge_msgs/HandTouch.h>
#include <naoqi_bridge_msgs/HeadTouch.h>
#include <naoqi_bridge_msgs/ChestButtonPressed.h>

#include <naoqi_driver/tools.hpp>
#include <naoqi_driver/recorder/globalrecorder.hpp>
Expand Down Expand Up @@ -82,6 +83,7 @@ class TouchEventRegister: public boost::enable_shared_from_this<TouchEventRegist
void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::Bumper &msg);
void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::HandTouch &msg);
void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::HeadTouch &msg);
void touchCallbackMessage(std::string &key, bool &state, naoqi_bridge_msgs::ChestButtonPressed &msg);


private:
Expand Down Expand Up @@ -129,6 +131,12 @@ class HandTouchEventRegister: public TouchEventRegister<naoqi_bridge_msgs::HandT
HandTouchEventRegister( const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session ) : TouchEventRegister<naoqi_bridge_msgs::HandTouch>(name, keys, frequency, session) {}
};

class ChestTouchEventRegister: public TouchEventRegister<naoqi_bridge_msgs::ChestButtonPressed>
{
public:
ChestTouchEventRegister( const std::string& name, const std::vector<std::string> keys, const float& frequency, const qi::SessionPtr& session ) : TouchEventRegister<naoqi_bridge_msgs::ChestButtonPressed>(name, keys, frequency, session) {}
};

//QI_REGISTER_OBJECT(BumperEventRegister, touchCallback)
//QI_REGISTER_OBJECT(HeadTouchEventRegister, touchCallback)

Expand Down Expand Up @@ -156,6 +164,14 @@ static bool _qiregisterTouchEventRegisterHeadTouch() {
}
static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterHeadTouch();

static bool _qiregisterTouchEventRegisterChestTouch() {
::qi::ObjectTypeBuilder<TouchEventRegister<naoqi_bridge_msgs::ChestButtonPressed> > b;
QI_VAARGS_APPLY(__QI_REGISTER_ELEMENT, TouchEventRegister<naoqi_bridge_msgs::ChestButtonPressed>, touchCallback)
b.registerType();
return true;
}
static bool BOOST_PP_CAT(__qi_registration, __LINE__) = _qiregisterTouchEventRegisterChestTouch();

} //naoqi

#endif
16 changes: 16 additions & 0 deletions src/naoqi_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ void Driver::registerDefaultConverter()
bool bumper_enabled = boot_config_.get( "converters.bumper.enabled", true);
bool hand_enabled = boot_config_.get( "converters.touch_hand.enabled", true);
bool head_enabled = boot_config_.get( "converters.touch_head.enabled", true);
bool chest_enabled = boot_config_.get( "converters.chest_button.enabled", true);
/*
* The info converter will be called once after it was added to the priority queue. Once it is its turn to be called, its
* callAll method will be triggered (because InfoPublisher is considered to always have subscribers, isSubscribed always
Expand Down Expand Up @@ -834,6 +835,21 @@ void Driver::registerDefaultConverter()
}
}

if ( chest_enabled )
{
std::vector<std::string> chest_touch_events;
chest_touch_events.push_back("ChestButtonPressed");
boost::shared_ptr<ChestTouchEventRegister> event_register =
boost::make_shared<ChestTouchEventRegister>( "chest_touch", chest_touch_events, 0, sessionPtr_ );
insertEventConverter("chest_touch", event_register);
if (keep_looping) {
event_map_.find("chest_touch")->second.startProcess();
}
if (publish_enabled_) {
event_map_.find("chest_touch")->second.isPublishing(true);
}
}

/** Odom */
if ( odom_enabled )
{
Expand Down