Skip to content

Commit 6cca2a3

Browse files
authored
Creation of sm_nav2_unit_test_1 (#687)
* Update to smacc2_client_library/CLAUDE.md reflecting migration to pure component based architecture * Few formatting moves * Refactoring boost signals usage to pure smacc signals - SmaccSignalConnection * Cleaned up a few dangling boost signal references * Creation of sm_nav2_unit_test_1 gazebo example in sm_reference_library * Pre-commit format fixes
1 parent ae1a4cc commit 6cca2a3

File tree

16 files changed

+837
-0
lines changed

16 files changed

+837
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(sm_nav2_unit_test_1)
3+
4+
# Default to C++17
5+
if(NOT CMAKE_CXX_STANDARD)
6+
set(CMAKE_CXX_STANDARD 17)
7+
endif()
8+
9+
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
10+
add_compile_options(-Wall -Wextra -Wpedantic)
11+
endif()
12+
13+
# Find dependencies
14+
find_package(ament_cmake REQUIRED)
15+
find_package(smacc2 REQUIRED)
16+
find_package(cl_ros2_timer REQUIRED)
17+
find_package(cl_keyboard REQUIRED)
18+
find_package(cl_nav2z REQUIRED)
19+
find_package(geometry_msgs REQUIRED)
20+
find_package(Boost COMPONENTS thread REQUIRED)
21+
22+
# Include directories
23+
include_directories(
24+
include
25+
${smacc2_INCLUDE_DIRS}
26+
${cl_ros2_timer_INCLUDE_DIRS}
27+
${cl_keyboard_INCLUDE_DIRS}
28+
${cl_nav2z_INCLUDE_DIRS}
29+
)
30+
31+
# Executable
32+
add_executable(${PROJECT_NAME}_node
33+
src/sm_nav2_unit_test_1/sm_nav2_unit_test_1_node.cpp
34+
)
35+
36+
target_link_libraries(${PROJECT_NAME}_node
37+
${smacc2_LIBRARIES}
38+
${cl_ros2_timer_LIBRARIES}
39+
${cl_keyboard_LIBRARIES}
40+
${cl_nav2z_LIBRARIES}
41+
${Boost_LIBRARIES}
42+
)
43+
44+
ament_target_dependencies(${PROJECT_NAME}_node
45+
smacc2
46+
cl_ros2_timer
47+
cl_keyboard
48+
cl_nav2z
49+
geometry_msgs
50+
)
51+
52+
# Install
53+
install(DIRECTORY include/ DESTINATION include)
54+
install(DIRECTORY launch config DESTINATION share/${PROJECT_NAME})
55+
install(TARGETS ${PROJECT_NAME}_node DESTINATION lib/${PROJECT_NAME})
56+
57+
ament_package()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<h2>State Machine Diagram</h2>
2+
3+
![sm_nav2_unit_test_1](docs/SmNav2UnitTest1.svg)
4+
5+
<h2>Description</h2> A Nav2 unit test state machine demonstrating basic navigation and rotation behaviors using the Nav2 stack with TurtleBot3 simulation. The state machine navigates to a waypoint, rotates 180 degrees, then navigates to a second waypoint.<br></br>
6+
7+
<h2>Build Instructions</h2>
8+
9+
First, source your ros2 installation.
10+
```
11+
source /opt/ros/jazzy/setup.bash
12+
```
13+
14+
Before you build, make sure you've installed all the dependencies...
15+
16+
```
17+
rosdep install --ignore-src --from-paths src -y -r
18+
```
19+
20+
Then build with colcon build...
21+
22+
```
23+
colcon build
24+
```
25+
<h2>Operating Instructions</h2>
26+
After you build, remember to source the workspace...
27+
28+
```
29+
source install/setup.bash
30+
```
31+
32+
And then run the launch file...
33+
34+
```
35+
ros2 launch sm_nav2_unit_test_1 sm_nav2_unit_test_1.launch.py
36+
```
37+
38+
<h2>Viewer Instructions</h2>
39+
If you have the SMACC2 Runtime Analyzer installed then type...
40+
41+
```
42+
ros2 run smacc2_rta smacc2_rta
43+
```
44+
45+
If you don't have the SMACC2 Runtime Analyzer click <a href="https://robosoft.ai/product-category/smacc2-runtime-analyzer/">here</a>.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Configuration for sm_nav2_unit_test_1
2+
sm_nav2_unit_test_1:
3+
ros__parameters:
4+
use_sim_time: true
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2024 RobosoftAI Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <cl_keyboard/cl_keyboard.hpp>
18+
#include <smacc2/smacc_orthogonal.hpp>
19+
20+
namespace sm_nav2_unit_test_1
21+
{
22+
23+
class OrKeyboard : public smacc2::Orthogonal<OrKeyboard>
24+
{
25+
public:
26+
void onInitialize() override
27+
{
28+
auto client = this->createClient<cl_keyboard::ClKeyboard>();
29+
}
30+
};
31+
32+
} // namespace sm_nav2_unit_test_1
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2024 RobosoftAI Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <cl_nav2z/cl_nav2z.hpp>
18+
#include <cl_nav2z/components/pose/cp_pose.hpp>
19+
#include <cl_nav2z/components/odom_tracker/cp_odom_tracker.hpp>
20+
#include <cl_nav2z/components/planner_switcher/cp_planner_switcher.hpp>
21+
#include <cl_nav2z/components/goal_checker_switcher/cp_goal_checker_switcher.hpp>
22+
#include <cl_nav2z/components/amcl/cp_amcl.hpp>
23+
#include <smacc2/smacc_orthogonal.hpp>
24+
25+
namespace sm_nav2_unit_test_1
26+
{
27+
28+
class OrNavigation : public smacc2::Orthogonal<OrNavigation>
29+
{
30+
public:
31+
void onInitialize() override
32+
{
33+
auto client = this->createClient<cl_nav2z::ClNav2Z>();
34+
35+
// Create required components for navigation behaviors
36+
// CpPose: provides robot pose from TF
37+
client->createComponent<cl_nav2z::CpPose>("base_link", "map");
38+
39+
// CpOdomTracker: tracks odometry path for undo operations
40+
client->createComponent<cl_nav2z::odom_tracker::CpOdomTracker>();
41+
42+
// CpPlannerSwitcher: switches between planners/controllers
43+
client->createComponent<cl_nav2z::CpPlannerSwitcher>();
44+
45+
// CpGoalCheckerSwitcher: switches goal checker algorithms
46+
client->createComponent<cl_nav2z::CpGoalCheckerSwitcher>();
47+
48+
// CpAmcl: provides initial pose setting for AMCL localization
49+
client->createComponent<cl_nav2z::CpAmcl>();
50+
}
51+
};
52+
53+
} // namespace sm_nav2_unit_test_1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2024 RobosoftAI Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <chrono>
18+
#include <cl_ros2_timer/cl_ros2_timer.hpp>
19+
#include <smacc2/smacc.hpp>
20+
21+
using namespace std::chrono_literals;
22+
23+
namespace sm_nav2_unit_test_1
24+
{
25+
26+
class OrTimer : public smacc2::Orthogonal<OrTimer>
27+
{
28+
public:
29+
void onInitialize() override
30+
{
31+
auto client = this->createClient<cl_ros2_timer::ClRos2Timer>(1s);
32+
}
33+
};
34+
35+
} // namespace sm_nav2_unit_test_1
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2024 RobosoftAI Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <smacc2/smacc.hpp>
18+
19+
// CLIENTS
20+
#include <cl_ros2_timer/cl_ros2_timer.hpp>
21+
#include <cl_keyboard/cl_keyboard.hpp>
22+
#include <cl_nav2z/cl_nav2z.hpp>
23+
24+
// CLIENT BEHAVIORS
25+
#include <cl_ros2_timer/client_behaviors/cb_timer_countdown_once.hpp>
26+
#include <cl_keyboard/client_behaviors/cb_default_keyboard_behavior.hpp>
27+
#include <cl_nav2z/client_behaviors/cb_navigate_global_position.hpp>
28+
#include <cl_nav2z/client_behaviors/cb_wait_nav2_nodes.hpp>
29+
#include <cl_nav2z/client_behaviors/cb_wait_transform.hpp>
30+
#include <cl_nav2z/client_behaviors/cb_pure_spinning.hpp>
31+
#include <cl_nav2z/components/amcl/cp_amcl.hpp>
32+
33+
// ORTHOGONALS
34+
#include "orthogonals/or_timer.hpp"
35+
#include "orthogonals/or_keyboard.hpp"
36+
#include "orthogonals/or_navigation.hpp"
37+
38+
using namespace boost;
39+
using namespace smacc2;
40+
using namespace cl_ros2_timer;
41+
using namespace cl_keyboard;
42+
using namespace cl_nav2z;
43+
44+
namespace sm_nav2_unit_test_1
45+
{
46+
47+
// FORWARD DECLARATIONS
48+
class StAllSensorsGo;
49+
class StSetInitialPose;
50+
class StNavigateToWaypoint1;
51+
class StRotate;
52+
class StNavigateToWaypoint2;
53+
class StFinalState;
54+
55+
//--------------------------------------------------------------------
56+
// STATE MACHINE
57+
struct SmNav2UnitTest1 : public smacc2::SmaccStateMachineBase<SmNav2UnitTest1, StAllSensorsGo>
58+
{
59+
using SmaccStateMachineBase::SmaccStateMachineBase;
60+
61+
void onInitialize() override
62+
{
63+
this->createOrthogonal<OrTimer>();
64+
this->createOrthogonal<OrKeyboard>();
65+
this->createOrthogonal<OrNavigation>();
66+
}
67+
};
68+
69+
} // namespace sm_nav2_unit_test_1
70+
71+
// STATE INCLUDES (must be after state machine definition)
72+
#include "states/st_all_sensors_go.hpp"
73+
#include "states/st_set_initial_pose.hpp"
74+
#include "states/st_navigate_to_waypoint_1.hpp"
75+
#include "states/st_rotate.hpp"
76+
#include "states/st_navigate_to_waypoint_2.hpp"
77+
#include "states/st_final_state.hpp"
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Copyright 2024 RobosoftAI Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#pragma once
16+
17+
#include <smacc2/smacc.hpp>
18+
19+
namespace sm_nav2_unit_test_1
20+
{
21+
22+
using namespace cl_ros2_timer;
23+
using namespace cl_keyboard;
24+
using namespace cl_nav2z;
25+
using namespace smacc2::default_transition_tags;
26+
27+
// STATE DECLARATION
28+
struct StAllSensorsGo : smacc2::SmaccState<StAllSensorsGo, SmNav2UnitTest1>
29+
{
30+
using SmaccState::SmaccState;
31+
32+
// CUSTOM TRANSITION TAGS
33+
struct NEXT : SUCCESS {};
34+
struct NAV2_READY : SUCCESS {};
35+
36+
// TRANSITION TABLE
37+
typedef mpl::list<
38+
Transition<EvCbSuccess<CbWaitNav2Nodes, OrNavigation>, StSetInitialPose, NAV2_READY>,
39+
Transition<EvTimer<CbTimerCountdownOnce, OrTimer>, StSetInitialPose, SUCCESS>,
40+
Transition<EvKeyPressN<CbDefaultKeyboardBehavior, OrKeyboard>, StSetInitialPose, NEXT>
41+
> reactions;
42+
43+
// STATE FUNCTIONS
44+
static void staticConfigure()
45+
{
46+
// Wait for Nav2 nodes to be ready (PlannerServer, ControllerServer, BtNavigator)
47+
configure_orthogonal<OrNavigation, CbWaitNav2Nodes>();
48+
49+
// Timer countdown: triggers EvTimer after 15 seconds (backup if Nav2 ready signal not received)
50+
configure_orthogonal<OrTimer, CbTimerCountdownOnce>(15);
51+
52+
// Keyboard behavior: allows manual state advancement with 'N' key
53+
configure_orthogonal<OrKeyboard, CbDefaultKeyboardBehavior>();
54+
}
55+
56+
void runtimeConfigure()
57+
{
58+
RCLCPP_INFO(getLogger(), "StAllSensorsGo: runtimeConfigure()");
59+
}
60+
61+
void onEntry()
62+
{
63+
RCLCPP_INFO(getLogger(), "StAllSensorsGo: onEntry() - Waiting for Nav2 nodes to be ready...");
64+
}
65+
66+
void onExit()
67+
{
68+
RCLCPP_INFO(getLogger(), "StAllSensorsGo: onExit()");
69+
}
70+
};
71+
72+
} // namespace sm_nav2_unit_test_1

0 commit comments

Comments
 (0)