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

Start implementation of TaskClient and TaskServer #10

Merged
merged 3 commits into from
Jul 26, 2018
Merged
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
8 changes: 8 additions & 0 deletions src/control/src/DwaController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2018 Intel Corporation. All Rights Reserved.

#include "control/DwaController.hpp"
#include <chrono>

DwaController::DwaController(const std::string & name, Robot * robot)
: ControlTask(name, robot)
Expand All @@ -24,4 +25,11 @@ void
DwaController::workerThread()
{
RCLCPP_INFO(get_logger(), "DwaController::workerThread");

while (!stopWorkerThread_)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
RCLCPP_INFO(get_logger(), "DwaController::workerThread: doing work");
}
}

1 change: 1 addition & 0 deletions src/mission_execution/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_executable(mission_execution
ament_target_dependencies(mission_execution
rclcpp
std_msgs
task
)

install(TARGETS ${PROJECT_NAME}
Expand Down
8 changes: 6 additions & 2 deletions src/navigation/include/navigation/SimpleNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "navigation/NavigateToPoseTask.hpp"
#include "planning/AStarPlanner.hpp"
#include "control/DwaController.hpp"
#include "task/TaskClient.hpp"

class SimpleNavigator : public NavigateToPoseTask
{
Expand All @@ -21,8 +22,11 @@ class SimpleNavigator : public NavigateToPoseTask
void workerThread();

// TODO: These will be the client-side proxies (like SimpleActionClient):
AStarPlanner * planner_;
DwaController * controller_;
//AStarPlanner * planner_;
//DwaController * controller_;

TaskClient * planner_;
TaskClient * controller_;
};

#endif // NAVIGATION__SIMPLENAVIGATOR_HPP_
21 changes: 20 additions & 1 deletion src/navigation/src/SimpleNavigator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
// Copyright 2018 Intel Corporation. All Rights Reserved.

#include "navigation/SimpleNavigator.hpp"
#include <chrono>

SimpleNavigator::SimpleNavigator(const std::string & name, Robot * robot)
: NavigateToPoseTask(name, robot), planner_(nullptr), controller_(nullptr)
: NavigateToPoseTask(name, robot)
{
RCLCPP_INFO(get_logger(), "SimpleNavigator::SimpleNavigator");

// TODO: make into C++ smart pointers
planner_ = new TaskClient("AStarPlanner", this);
controller_ = new TaskClient("DwaController", this);
}

SimpleNavigator::~SimpleNavigator()
Expand All @@ -24,4 +29,18 @@ void
SimpleNavigator::workerThread()
{
RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread");

RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread: sending executes");
planner_->execute();
controller_->execute();

while (!stopWorkerThread_ /* && rclcpp::ok() */ )
{
RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread: doing work");
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}

RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread: sending cancels");
planner_->cancel();
controller_->cancel();
}
4 changes: 2 additions & 2 deletions src/planning/include/planning/PlanningTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#ifndef PLANNING__PLANNINGTASK_HPP_
#define PLANNING__PLANNINGTASK_HPP_

#include "task/Task.hpp"
#include "task/TaskServer.hpp"
#include "geometry_msgs/msg/pose_stamped.hpp"

class PlanningTask : public Task
class PlanningTask : public TaskServer
{
public:
PlanningTask(const std::string & name);
Expand Down
8 changes: 8 additions & 0 deletions src/planning/src/AStarPlanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright 2018 Intel Corporation. All Rights Reserved.

#include "planning/AStarPlanner.hpp"
#include <chrono>

AStarPlanner::AStarPlanner(const std::string & name)
: PlanningTask(name)
Expand All @@ -25,4 +26,11 @@ void
AStarPlanner::workerThread()
{
RCLCPP_INFO(get_logger(), "AStarPlanner::workerThread");

while (!stopWorkerThread_)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
RCLCPP_INFO(get_logger(), "AStarPlanner::workerThread: doing work");
}
}

2 changes: 1 addition & 1 deletion src/planning/src/PlanningTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "planning/PlanningTask.hpp"

PlanningTask::PlanningTask(const std::string & name)
: Task(name)
: TaskServer(name)
{
RCLCPP_INFO(get_logger(), "PlanningTask::PlanningTask");
}
Expand Down
3 changes: 2 additions & 1 deletion src/task/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "../libs/")

add_library(task STATIC
src/RobotTask.cpp
src/Task.cpp
src/TaskServer.cpp
src/TaskClient.cpp
)

ament_target_dependencies(task
Expand Down
23 changes: 0 additions & 23 deletions src/task/include/task/AStarPlanner.hpp

This file was deleted.

22 changes: 0 additions & 22 deletions src/task/include/task/DwaController.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/task/include/task/RobotTask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#ifndef TASK__ROBOTTASK_HPP_
#define TASK__ROBOTTASK_HPP_

#include "task/Task.hpp"
#include "task/TaskServer.hpp"
#include "robot/Robot.hpp"

class RobotTask : public Task
class RobotTask : public TaskServer
{
public:
RobotTask(const std::string & name, Robot * robot);
Expand Down
33 changes: 0 additions & 33 deletions src/task/include/task/Task.hpp

This file was deleted.

41 changes: 41 additions & 0 deletions src/task/include/task/TaskClient.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright 2018 Intel Corporation. All Rights Reserved.

#ifndef TASK__TASKCLIENT_HPP_
#define TASK__TASKCLIENT_HPP_

#include <string>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

class TaskClient
{
public:
TaskClient(const std::string & name, rclcpp::Node * node);
virtual ~TaskClient();

typedef std_msgs::msg::String Goal;
typedef std_msgs::msg::String GoalID;
typedef std_msgs::msg::String Result;
typedef std_msgs::msg::String Feedback;
typedef std_msgs::msg::String Status;

void execute();
void cancel();

protected:
void onResultReceived(const Result::SharedPtr msg);
void onFeedbackReceived(const Feedback::SharedPtr msg);
void onStatusReceived(const Status::SharedPtr msg);

rclcpp::Node * node_;

rclcpp::Publisher<Goal>::SharedPtr goalPub_;
rclcpp::Publisher<GoalID>::SharedPtr cancelPub_;

rclcpp::Subscription<Result>::SharedPtr resultSub_;
rclcpp::Subscription<Feedback>::SharedPtr feedbackSub_;
rclcpp::Subscription<Status>::SharedPtr statusSub_;
};

#endif // TASK__TASKCLIENT_HPP_
56 changes: 56 additions & 0 deletions src/task/include/task/TaskServer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// License: Apache 2.0. See LICENSE file in root directory.
// Copyright 2018 Intel Corporation. All Rights Reserved.

#ifndef TASK__TASKSERVER_HPP_
#define TASK__TASKSERVER_HPP_

#include <atomic>
#include <thread>
#include <string>
#include <functional>
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

class TaskServer: public rclcpp::Node
{
public:
TaskServer(const std::string & name);
virtual ~TaskServer();

// Execute
typedef std::function<void (const std_msgs::msg::String&)> ExecuteCallback;

typedef std_msgs::msg::String Goal;
typedef std_msgs::msg::String GoalID;
typedef std_msgs::msg::String Result;
typedef std_msgs::msg::String Feedback;
typedef std_msgs::msg::String Status;

// void publishStatus();
// void publishResult();
// void publishFeedback();

// Timer, status frequency

protected:
void start();
void stop();

virtual void workerThread() = 0;

std::thread *workerThread_;
std::atomic<bool> stopWorkerThread_;
std::atomic<bool> running_;

void onGoalReceived(const Goal::SharedPtr msg);
void onCancelReceived(const GoalID::SharedPtr msg);

rclcpp::Subscription<Goal>::SharedPtr goalSub_;
rclcpp::Subscription<GoalID>::SharedPtr cancelSub_;

rclcpp::Publisher<Result>::SharedPtr resultPub_;
rclcpp::Publisher<Feedback>::SharedPtr feedbackPub_;
rclcpp::Publisher<Status>::SharedPtr statusPub_;
};

#endif // TASK__TASKSERVER_HPP_
28 changes: 0 additions & 28 deletions src/task/src/AStarPlanner.cpp

This file was deleted.

27 changes: 0 additions & 27 deletions src/task/src/DwaController.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/task/src/RobotTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "task/RobotTask.hpp"

RobotTask::RobotTask(const std::string & name, Robot * robot)
: Task(name)
: TaskServer(name)
{
RCLCPP_INFO(get_logger(), "RobotTask::RobotTask");
robot = robot;
Expand Down
Loading