#include <cstdio>
#include <rclcpp/rclcpp.hpp>
#include "back_wall_is_close_enough.h"
#include "behaviortree_cpp_v3/bt_factory.h"
#include "behaviortree_cpp_v3/loggers/bt_cout_logger.h"
#include "behaviortree_cpp_v3/loggers/bt_zmq_publisher.h"
#include "find_back_wall.h"
#include "find_front_wall.h"
#include "front_wall_is_close_enough.h"
#include "get_hallway_width_distances.h"
#include "goto_back_wall.h"
#include "move_backwards_centered.h"
#include "move_forwards_centered.h"
rclcpp::Node::SharedPtr g_node;
inline void SleepMS(int ms)
{
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
int main(int argc, char** argv) {
rclcpp::init(argc, argv);
g_node = rclcpp::Node::make_shared("floorbot_1_node");
std::string xml_path;
g_node->declare_parameter<std::string>("xml_path", "foo");
g_node->get_parameter("xml_path", xml_path);
BT::BehaviorTreeFactory factory;
factory.registerSimpleCondition("BackWallIsCloseEnough", std::bind(BackWallIsCloseEnough));
factory.registerSimpleCondition("FindBackWall", std::bind(FindBackWall));
factory.registerSimpleCondition("FindFrontWall", std::bind(FindFrontWall));
factory.registerSimpleCondition("FrontWallIsCloseEnough", std::bind(FrontWallIsCloseEnough));
factory.registerSimpleCondition("GetHallwayWidthDistances", std::bind(GetHallwayWidthDistances));
factory.registerNodeType<GotoBackWall>("GotoBackWall");
factory.registerNodeType<MoveBackwardsCentered>("MoveBackwardsCentered");
factory.registerNodeType<MoveForwardsCentered>("MoveForwardsCentered");
auto tree = factory.createTreeFromFile(xml_path);
BT::PublisherZMQ publisher_zmq(tree);
BT::StdCoutLogger logger_cout(tree);
BT::printTreeRecursively(tree.rootNode());
{
BT::NodeStatus status = BT::NodeStatus::RUNNING;
while (status == BT::NodeStatus::RUNNING) {
status = tree.tickRoot();
SleepMS(5000);
}
SleepMS(2000);
}
printf("Floorbot Level 1 Challenge completed\n");
return 0;
}