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

add fading/ resetting leds services #100

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ set(
src/services/robot_config.cpp
src/services/set_language.cpp
src/services/get_language.cpp
src/services/fade_leds.cpp
src/services/reset_leds.cpp
)

set(
Expand Down
18 changes: 18 additions & 0 deletions src/helpers/driver_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ std::string& getLanguage( const qi::SessionPtr& session )
return language;
}

/** Function that fades eye leds
*/
std_msgs::Empty& fadeLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::FadeLedsRequest req )
{
std::cout << "Receiving service call of fading leds" << std::endl;
qi::AnyObject p_leds = session->service("ALLeds");
p_leds.call<void>("fadeRGB", req.fade_rgb.led_name, req.fade_rgb.color.r, req.fade_rgb.color.g, req.fade_rgb.color.b, req.fade_rgb.fade_duration.toSec());
}

/** Function that reset leds color
*/
std_msgs::Empty& resetLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRequest req )
{
std::cout << "Receiving service call of resetting leds" << std::endl;
qi::AnyObject p_leds = session->service("ALLeds");
p_leds.call<void>("reset", req.data);
}

} // driver
} // helpers
} // naoqi
8 changes: 8 additions & 0 deletions src/helpers/driver_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@

#include <naoqi_bridge_msgs/RobotInfo.h>

#include <std_msgs/Empty.h>

#include <naoqi_bridge_msgs/SetString.h>

#include <naoqi_bridge_msgs/FadeLeds.h>

#include <qi/applicationsession.hpp>

namespace naoqi
Expand All @@ -42,6 +46,10 @@ bool& setLanguage( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRe

std::string& getLanguage( const qi::SessionPtr& session );

std_msgs::Empty& fadeLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::FadeLedsRequest req );

std_msgs::Empty& resetLeds( const qi::SessionPtr& session, naoqi_bridge_msgs::SetStringRequest req );

} // driver
} // helpers
} // naoqi
Expand Down
4 changes: 4 additions & 0 deletions src/naoqi_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
#include "services/robot_config.hpp"
#include "services/set_language.hpp"
#include "services/get_language.hpp"
#include "services/fade_leds.hpp"
#include "services/reset_leds.hpp"

/*
* RECORDERS
Expand Down Expand Up @@ -893,6 +895,8 @@ void Driver::registerDefaultServices()
registerService( boost::make_shared<service::RobotConfigService>("robot config service", "/naoqi_driver/get_robot_config", sessionPtr_) );
registerService( boost::make_shared<service::SetLanguageService>("set language service", "/naoqi_driver/set_language", sessionPtr_) );
registerService( boost::make_shared<service::GetLanguageService>("get language service", "/naoqi_driver/get_language", sessionPtr_) );
registerService( boost::make_shared<service::FadeLedsService>("fade leds service", "/naoqi_driver/fade_leds", sessionPtr_) );
registerService( boost::make_shared<service::ResetLedsService>("reset leds service", "/naoqi_driver/reset_leds", sessionPtr_) );
}

std::vector<std::string> Driver::getAvailableConverters()
Expand Down
45 changes: 45 additions & 0 deletions src/services/fade_leds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2018 Aldebaran
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "fade_leds.hpp"
#include "../helpers/driver_helpers.hpp"

namespace naoqi
{
namespace service
{

FadeLedsService::FadeLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session )
: name_(name),
topic_(topic),
session_(session)
{}

void FadeLedsService::reset( ros::NodeHandle& nh )
{
service_ = nh.advertiseService(topic_, &FadeLedsService::callback, this);
}

bool FadeLedsService::callback( naoqi_bridge_msgs::FadeLedsRequest& req, naoqi_bridge_msgs::FadeLedsResponse& resp )
{
helpers::driver::fadeLeds(session_, req);
return true;
}


}
}
67 changes: 67 additions & 0 deletions src/services/fade_leds.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2018 Aldebaran
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/


#ifndef FADE_LEDS_SERVICE_HPP
#define FADE_LEDS_SERVICE_HPP

#include <iostream>

#include <ros/node_handle.h>
#include <ros/service_server.h>

#include <naoqi_bridge_msgs/FadeLeds.h>
#include <qi/session.hpp>

namespace naoqi
{
namespace service
{

class FadeLedsService
{
public:
FadeLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session );

~FadeLedsService(){};

std::string name() const
{
return name_;
}

std::string topic() const
{
return topic_;
}

void reset( ros::NodeHandle& nh );

bool callback( naoqi_bridge_msgs::FadeLedsRequest& req, naoqi_bridge_msgs::FadeLedsResponse& resp );


private:
const std::string name_;
const std::string topic_;

const qi::SessionPtr& session_;
ros::ServiceServer service_;
};

} // service
} // naoqi
#endif
46 changes: 46 additions & 0 deletions src/services/reset_leds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2018 Aldebaran
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "reset_leds.hpp"
#include "../helpers/driver_helpers.hpp"

namespace naoqi
{
namespace service
{

ResetLedsService::ResetLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session )
: name_(name),
topic_(topic),
session_(session)
{}

void ResetLedsService::reset( ros::NodeHandle& nh )
{
service_ = nh.advertiseService(topic_, &ResetLedsService::callback, this);
}

bool ResetLedsService::callback( naoqi_bridge_msgs::SetStringRequest& req, naoqi_bridge_msgs::SetStringResponse& resp )
{
helpers::driver::resetLeds(session_, req);
resp.success = true;
return true;
}


}
}
67 changes: 67 additions & 0 deletions src/services/reset_leds.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2018 Aldebaran
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/


#ifndef RESET_LEDS_SERVICE_HPP
#define RESET_LEDS_SERVICE_HPP

#include <iostream>

#include <ros/node_handle.h>
#include <ros/service_server.h>

#include <naoqi_bridge_msgs/SetString.h>
#include <qi/session.hpp>

namespace naoqi
{
namespace service
{

class ResetLedsService
{
public:
ResetLedsService( const std::string& name, const std::string& topic, const qi::SessionPtr& session );

~ResetLedsService(){};

std::string name() const
{
return name_;
}

std::string topic() const
{
return topic_;
}

void reset( ros::NodeHandle& nh );

bool callback( naoqi_bridge_msgs::SetStringRequest& req, naoqi_bridge_msgs::SetStringResponse& resp );


private:
const std::string name_;
const std::string topic_;

const qi::SessionPtr& session_;
ros::ServiceServer service_;
};

} // service
} // naoqi
#endif