-
Notifications
You must be signed in to change notification settings - Fork 0
/
cca_robot_package_creator.sh
executable file
·252 lines (207 loc) · 8.6 KB
/
cca_robot_package_creator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/bin/bash
# ========================================================================
# Script Name: cc_affordance_description_package_creator.sh
# Description: Automates the creation of a ROS2 cca_<robot> package,
# generating templates for essential configuration
# files in the format required for CC Affordance planning.
# Author: Crasun Jans
# ========================================================================
# Check if ROS2 is sourced
if [[ -z "$ROS_DISTRO" ]]; then # Check if the ROS_DISTRO environment variable is not set
echo "Please source ROS2 before running this script."
exit 1
fi
# Get robot name
read -p "Enter robot name: " robot_name
# Construct package name
package_name="cca_${robot_name}"
# Create package
ros2 pkg create $package_name --build-type ament_cmake --dependencies rclcpp cc_affordance_planner_ros
# Create config and launch folders
mkdir $package_name/config
mkdir $package_name/launch
# Remove unnecessary folders
rm -rf $package_name/include
# Create the description file
cat << EOF > $package_name/config/cca_${robot_name}_description.yaml
# **Description of the ${robot_name} robot
# Define the reference frame, joint axes, their locations, and the tool's position.
# Add or remove joint fields as needed to accurately represent the robot
ref_frame:
- name: # Reference frame name, example: arm0_base_link
joints:
- name: # Joint name, example: arm0_shoulder_yaw
w: # Joint axis, example: [0, 0, 1]
q: # Joint location, example: [0, 0, 0]
- name:
w:
q:
- name:
w:
q:
- name:
w:
q:
- name:
w:
q:
- name:
w:
q:
tool:
- name: # Tool frame name, example: arm0_tool0. This is usually at the center of the palm
q: # Tool frame location, example: [0.9383, 0.0005, 0.0664]
EOF
# Create the ROS setup file
cat << EOF > $package_name/config/cca_${robot_name}_ros_setup.yaml
# *** ROS-related attributes pertaining to ${robot_name} *** #
cc_affordance_planner_ros:
ros__parameters:
# --- Robot Name ---
cca_robot: "${robot_name}" # This package must be named cca_<cca_robot>
# --- Action Server ---
cca_robot_as: "" # Follow joint trajectory action server to execute trajectory on the robot
# --- Topics ---
cca_joint_states_topic: "" # Joint states topic name
# --- Robot Description ---
cca_robot_description_parameter: "" # Robot description parameter name
# --- Planning Group ---
cca_planning_group: "" # MoveIt planning group name
EOF
# Create the launch file
cat << EOF > $package_name/launch/cca_${robot_name}.launch.py
import os
from ament_index_python.packages import get_package_share_directory
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
ld = LaunchDescription()
# Define LaunchConfiguration arguments with clear descriptions
cca_${robot_name}_ros_setup = os.path.join(
get_package_share_directory('cca_${robot_name}'),
'config',
'cca_${robot_name}_ros_setup.yaml'
)
# Create a Node instance for the cc_affordance_spot_description node
cc_affordance_planner_ros_node_with_params = Node(
package="cca_${robot_name}",
executable="cc_${robot_name}_node",
name="cc_affordance_planner_ros",
emulate_tty=True,
output='screen',
prefix='xterm -e', # to receive input from user
parameters=[
cca_${robot_name}_ros_setup
],
)
ld.add_action(cc_affordance_planner_ros_node_with_params)
return ld
EOF
# Create the affordance planner src file
cat << EOF > $package_name/src/cca_${robot_name}_node.cpp
#include "rclcpp/rclcpp.hpp"
#include <Eigen/Core>
#include <cc_affordance_planner_ros/cc_affordance_planner_ros.hpp>
int main(int argc, char **argv)
{
rclcpp::init(argc, argv);
rclcpp::NodeOptions node_options;
node_options.automatically_declare_parameters_from_overrides(true);
auto node = std::make_shared<CcAffordancePlannerRos>("cc_affordance_planner_ros", node_options);
// Start spinning the node in a separate thread so we could do things like reading parameters and joint states
// inside the node
std::thread spinner_thread([&node]() { rclcpp::spin(node); });
/*------------------------------------------------------------*/
// Specify affordance screw
const Eigen::Vector3d aff_screw_axis(0, 0, 1); // screw axis
const Eigen::Vector3d aff_screw_axis_location(0, 0, 0); // location vector
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
// Set affordance goal
const double aff_goal = 0.5 * M_PI; // Code
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
// Optionally set planner parameters
/* const double &aff_step = 0.3; */
/* const int &gripper_control_par_tau = 1; */
/* const double &accuracy = 10.0 / 100.0; */
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
// Run the planner
bool success = node->run_cc_affordance_planner(aff_screw_axis, aff_screw_axis_location, aff_goal);
// Or if getting affordance screw location from apriltag
/* const std::string apriltag_frame_name = "affordance_frame"; */
/*bool success = node->run_cc_affordance_planner(aff_screw_axis, apriltag_frame_name, aff_goal); Note screw axis is
* manually set in this case as aff_screw_axis above. Just the location is gotten from Apriltag*/
/*------------------------------------------------------------*/
/*------------------------------------------------------------*/
// Optionally, with planner parameters call:
/*bool success = node->run_cc_affordance_planner(aff_screw_axis, aff_screw_axis_location, aff_goal, aff_step,
* gripper_control_par_tau, accuracy); */
// or
/*bool success = node->run_cc_affordance_planner(aff_screw_axis, apriltag_frame_name, aff_goal, aff_step,
* gripper_control_par_tau, accuracy); */
/*------------------------------------------------------------*/
// Call the function again with new (or old) aff_screw_axis, aff_screw_axis_location and aff_goal to execute
// another affordance in series
/*bool success = node->run_cc_affordance_planner(aff_screw_axis, aff_screw_axis_location, aff_goal); */
// or
/*bool success = node->run_cc_affordance_planner(aff_screw_axis, apriltag_frame_name, aff_goal); */
if (success) // If trajectory was successfully executed wait until, goal response callback is invoked and ros is
// shutdown from there
{
spinner_thread.join(); // join the spinning thread and exit
}
else
{
rclcpp::shutdown(); // shutdown ROS on failure
spinner_thread.join(); // join the spinner thread
}
return 0;
}
EOF
# Create the CMakeLists file
cat << EOF > $package_name/src/cca_${robot_name}_node.cpp
cmake_minimum_required(VERSION 3.8)
project(cca_${robot_name})
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# Find and link required packages
find_package(Eigen3 REQUIRED) # Linear algebra library
# ROS packages
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(cc_affordance_planner_ros REQUIRED)
# Specify the node executables
add_executable(${PROJECT_NAME}_node src/${PROJECT_NAME}_node.cpp)
# Specify ROS dependencies for the target
ament_target_dependencies(${PROJECT_NAME}_node rclcpp cc_affordance_planner_ros)
# Link Eigen libraries against this project library
target_link_libraries(${PROJECT_NAME}_node Eigen3::Eigen)
install(TARGETS
${PROJECT_NAME}_node
DESTINATION lib/${PROJECT_NAME}
)
install(DIRECTORY config launch
DESTINATION share/${PROJECT_NAME}
)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
# the following line skips the linter which checks for copyrights
# uncomment the line when a copyright and license is not present in all source files
#set(ament_cmake_copyright_FOUND TRUE)
# the following line skips cpplint (only works in a git repo)
# uncomment the line when this package is not in a git repo
#set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
EOF
# Notify user
echo "Package created successfully!"
echo "Package name: $package_name"
echo "CMakeLists.txt created in $package_name"
echo "YAML files created in $package_name/config"
echo "Launch file created in $package_name/launch"
echo "Cpp file created in $package_name/src"