Skip to content

Commit 435db94

Browse files
author
Michael Jeronimo
authored
Start implementation of TaskClient and TaskServer (#10)
* Move some of the task base classes out to separate directories. * Implement start/stop for TaskClient and TaskServer
1 parent b7c30bb commit 435db94

File tree

20 files changed

+282
-197
lines changed

20 files changed

+282
-197
lines changed

src/control/src/DwaController.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2018 Intel Corporation. All Rights Reserved.
33

44
#include "control/DwaController.hpp"
5+
#include <chrono>
56

67
DwaController::DwaController(const std::string & name, Robot * robot)
78
: ControlTask(name, robot)
@@ -24,4 +25,11 @@ void
2425
DwaController::workerThread()
2526
{
2627
RCLCPP_INFO(get_logger(), "DwaController::workerThread");
28+
29+
while (!stopWorkerThread_)
30+
{
31+
std::this_thread::sleep_for(std::chrono::milliseconds(500));
32+
RCLCPP_INFO(get_logger(), "DwaController::workerThread: doing work");
33+
}
2734
}
35+

src/mission_execution/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_executable(mission_execution
2929
ament_target_dependencies(mission_execution
3030
rclcpp
3131
std_msgs
32+
task
3233
)
3334

3435
install(TARGETS ${PROJECT_NAME}

src/navigation/include/navigation/SimpleNavigator.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "navigation/NavigateToPoseTask.hpp"
88
#include "planning/AStarPlanner.hpp"
99
#include "control/DwaController.hpp"
10+
#include "task/TaskClient.hpp"
1011

1112
class SimpleNavigator : public NavigateToPoseTask
1213
{
@@ -21,8 +22,11 @@ class SimpleNavigator : public NavigateToPoseTask
2122
void workerThread();
2223

2324
// TODO: These will be the client-side proxies (like SimpleActionClient):
24-
AStarPlanner * planner_;
25-
DwaController * controller_;
25+
//AStarPlanner * planner_;
26+
//DwaController * controller_;
27+
28+
TaskClient * planner_;
29+
TaskClient * controller_;
2630
};
2731

2832
#endif // NAVIGATION__SIMPLENAVIGATOR_HPP_

src/navigation/src/SimpleNavigator.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
// Copyright 2018 Intel Corporation. All Rights Reserved.
33

44
#include "navigation/SimpleNavigator.hpp"
5+
#include <chrono>
56

67
SimpleNavigator::SimpleNavigator(const std::string & name, Robot * robot)
7-
: NavigateToPoseTask(name, robot), planner_(nullptr), controller_(nullptr)
8+
: NavigateToPoseTask(name, robot)
89
{
910
RCLCPP_INFO(get_logger(), "SimpleNavigator::SimpleNavigator");
11+
12+
// TODO: make into C++ smart pointers
13+
planner_ = new TaskClient("AStarPlanner", this);
14+
controller_ = new TaskClient("DwaController", this);
1015
}
1116

1217
SimpleNavigator::~SimpleNavigator()
@@ -24,4 +29,18 @@ void
2429
SimpleNavigator::workerThread()
2530
{
2631
RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread");
32+
33+
RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread: sending executes");
34+
planner_->execute();
35+
controller_->execute();
36+
37+
while (!stopWorkerThread_ /* && rclcpp::ok() */ )
38+
{
39+
RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread: doing work");
40+
std::this_thread::sleep_for(std::chrono::milliseconds(500));
41+
}
42+
43+
RCLCPP_INFO(get_logger(), "SimpleNavigator::workerThread: sending cancels");
44+
planner_->cancel();
45+
controller_->cancel();
2746
}

src/planning/include/planning/PlanningTask.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#ifndef PLANNING__PLANNINGTASK_HPP_
55
#define PLANNING__PLANNINGTASK_HPP_
66

7-
#include "task/Task.hpp"
7+
#include "task/TaskServer.hpp"
88
#include "geometry_msgs/msg/pose_stamped.hpp"
99

10-
class PlanningTask : public Task
10+
class PlanningTask : public TaskServer
1111
{
1212
public:
1313
PlanningTask(const std::string & name);

src/planning/src/AStarPlanner.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Copyright 2018 Intel Corporation. All Rights Reserved.
33

44
#include "planning/AStarPlanner.hpp"
5+
#include <chrono>
56

67
AStarPlanner::AStarPlanner(const std::string & name)
78
: PlanningTask(name)
@@ -25,4 +26,11 @@ void
2526
AStarPlanner::workerThread()
2627
{
2728
RCLCPP_INFO(get_logger(), "AStarPlanner::workerThread");
29+
30+
while (!stopWorkerThread_)
31+
{
32+
std::this_thread::sleep_for(std::chrono::milliseconds(500));
33+
RCLCPP_INFO(get_logger(), "AStarPlanner::workerThread: doing work");
34+
}
2835
}
36+

src/planning/src/PlanningTask.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "planning/PlanningTask.hpp"
55

66
PlanningTask::PlanningTask(const std::string & name)
7-
: Task(name)
7+
: TaskServer(name)
88
{
99
RCLCPP_INFO(get_logger(), "PlanningTask::PlanningTask");
1010
}

src/task/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "../libs/")
2323

2424
add_library(task STATIC
2525
src/RobotTask.cpp
26-
src/Task.cpp
26+
src/TaskServer.cpp
27+
src/TaskClient.cpp
2728
)
2829

2930
ament_target_dependencies(task

src/task/include/task/AStarPlanner.hpp

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/task/include/task/DwaController.hpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)