forked from CoreSenseEU/CoreSense4Home
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2024 Intelligent Robotics Lab - Gentlebots | ||
// | ||
// 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 CONFIGURATION__SLEEP_HPP_ | ||
#define CONFIGURATION__SLEEP_HPP_ | ||
|
||
#include <tf2_ros/buffer.h> | ||
|
||
#include <memory> | ||
#include <string> | ||
#include <chrono> | ||
|
||
#include "behaviortree_cpp_v3/behavior_tree.h" | ||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "rclcpp_cascade_lifecycle/rclcpp_cascade_lifecycle.hpp" | ||
|
||
#include "rclcpp_action/rclcpp_action.hpp" | ||
|
||
namespace configuration | ||
{ | ||
|
||
class Sleep : public BT::ActionNodeBase | ||
{ | ||
public: | ||
explicit Sleep(const std::string & xml_tag_name, const BT::NodeConfiguration & conf); | ||
|
||
void halt(); | ||
BT::NodeStatus tick(); | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return BT::PortsList( | ||
{ | ||
BT::InputPort<double>("time") | ||
}); | ||
} | ||
|
||
private: | ||
std::shared_ptr<rclcpp_cascade_lifecycle::CascadeLifecycleNode> node_; | ||
|
||
double time_; | ||
std::chrono::time_point<std::chrono::high_resolution_clock> start_time_; | ||
}; | ||
|
||
} // namespace configuration | ||
|
||
#endif // CONFIGURATION__SLEEP_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 Intelligent Robotics Lab - Gentlebots | ||
// | ||
// 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 "configuration/sleep.hpp" | ||
|
||
namespace configuration | ||
{ | ||
|
||
Sleep::Sleep(const std::string & xml_tag_name, const BT::NodeConfiguration & conf) | ||
: BT::ActionNodeBase(xml_tag_name, conf) | ||
{ | ||
config().blackboard->get("node", node_); | ||
} | ||
|
||
BT::NodeStatus Sleep::tick() | ||
{ | ||
RCLCPP_INFO(node_->get_logger(), "[Sleep] ticked"); | ||
|
||
getInput("time", time_); | ||
|
||
if (status() == BT::NodeStatus::IDLE) { | ||
start_time_ = std::chrono::high_resolution_clock::now(); | ||
return BT::NodeStatus::RUNNING; | ||
} | ||
|
||
auto end_time = std::chrono::high_resolution_clock::now(); | ||
auto elapsed_time = std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time_).count(); | ||
if (elapsed_time < time_) { | ||
return BT::NodeStatus::RUNNING; | ||
} else { | ||
return BT::NodeStatus::SUCCESS; | ||
} | ||
} | ||
|
||
void Sleep::halt() | ||
{ | ||
RCLCPP_INFO(node_->get_logger(), "[Sleep] halted"); | ||
} | ||
|
||
} // namespace navigation | ||
|
||
BT_REGISTER_NODES(factory) { | ||
factory.registerNodeType<configuration::Sleep>("Sleep"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Intelligent Robotics Lab - Gentlebots | ||
// | ||
// 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 andGO2OBJECT | ||
// limitations under the License. | ||
|
||
#ifndef HRI__START_MUSIC_HPP_ | ||
#define HRI__START_MUSIC_HPP_ | ||
|
||
#include <string> | ||
|
||
#include "behaviortree_cpp_v3/behavior_tree.h" | ||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
#include "hri/bt_service_node.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "rclcpp_cascade_lifecycle/rclcpp_cascade_lifecycle.hpp" | ||
#include "audio_common_msgs/srv/music_play.hpp" | ||
|
||
|
||
namespace hri | ||
{ | ||
|
||
class StartMusic | ||
: public hri::BtServiceNode<yolov8_msgs::srv::ChangeModel, | ||
rclcpp_cascade_lifecycle::CascadeLifecycleNode> | ||
{ | ||
public: | ||
explicit StartMusic( | ||
const std::string & xml_tag_name, const std::string & action_name, | ||
const BT::NodeConfiguration & conf); | ||
|
||
void on_tick() override; | ||
void on_result() override; | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return BT::PortsList({ | ||
BT::InputPort<std::string>("audio", "elevator", "audio to play"), | ||
}); | ||
} | ||
|
||
private: | ||
std::string audio_; | ||
}; | ||
|
||
} // namespace hri | ||
|
||
#endif // HRI__START_MUSIC_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 Intelligent Robotics Lab - Gentlebots | ||
// | ||
// 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 andGO2OBJECT | ||
// limitations under the License. | ||
|
||
#ifndef HRI__STOP_MUSIC_HPP_ | ||
#define HRI__STOP_MUSIC_HPP_ | ||
|
||
#include <string> | ||
|
||
#include "behaviortree_cpp_v3/behavior_tree.h" | ||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
#include "hri/bt_service_node.hpp" | ||
#include "rclcpp/rclcpp.hpp" | ||
#include "rclcpp_cascade_lifecycle/rclcpp_cascade_lifecycle.hpp" | ||
#include "std_srvs/srv/trigger.hpp" | ||
|
||
|
||
namespace hri | ||
{ | ||
|
||
class StopMusic | ||
: public hri::BtServiceNode<yolov8_msgs::srv::ChangeModel, | ||
rclcpp_cascade_lifecycle::CascadeLifecycleNode> | ||
{ | ||
public: | ||
explicit StopMusic( | ||
const std::string & xml_tag_name, const std::string & action_name, | ||
const BT::NodeConfiguration & conf); | ||
|
||
void on_tick() override; | ||
void on_result() override; | ||
|
||
static BT::PortsList providedPorts() | ||
{ | ||
return BT::PortsList({ | ||
}); | ||
} | ||
}; | ||
|
||
} // namespace hri | ||
|
||
#endif // HRI__STOP_MUSIC_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2024 Intelligent Robotics Lab - Gentlebots | ||
// | ||
// 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 "hri/stop_music.hpp" | ||
|
||
#include <string> | ||
|
||
namespace hri | ||
{ | ||
|
||
using namespace std::chrono_literals; | ||
using namespace std::placeholders; | ||
|
||
StopMusic::StopMusic( | ||
const std::string & xml_tag_name, const std::string & action_name, | ||
const BT::NodeConfiguration & conf) | ||
: configuration::BtServiceNode<std_srvs::srv::Trigger, | ||
rclcpp_cascade_lifecycle::CascadeLifecycleNode>( | ||
xml_tag_name, action_name, conf) | ||
{ | ||
} | ||
|
||
void StopMusic::on_tick() | ||
{ | ||
RCLCPP_DEBUG(node_->get_logger(), "StopMusic ticked"); | ||
} | ||
|
||
void StopMusic::on_result() | ||
{ | ||
if (result_.success) { | ||
std::cout << "Success StopMusic" << std::endl; | ||
setStatus(BT::NodeStatus::SUCCESS); | ||
|
||
} else { | ||
std::cout << "Failure StopMusic" << std::endl; | ||
// setOutput("listen_text", result_.result->text); | ||
setStatus(BT::NodeStatus::FAILURE); | ||
} | ||
} | ||
|
||
} // namespace perception | ||
|
||
#include "behaviortree_cpp_v3/bt_factory.h" | ||
BT_REGISTER_NODES(factory) | ||
{ | ||
BT::NodeBuilder builder = [](const std::string & name, const BT::NodeConfiguration & config) { | ||
return std::make_unique<hri::StopMusic>( | ||
name, "/stop_music", config); | ||
}; | ||
|
||
factory.registerBuilder<hri::StopMusic>("StopMusic", builder); | ||
} |
File renamed without changes.