Skip to content

Commit a7e51ba

Browse files
committed
Change plugin ros2_control classic to gazebo
1 parent 5916f09 commit a7e51ba

4 files changed

Lines changed: 128 additions & 56 deletions

File tree

Industrial/ros2_SimRealRobotControl_gz/packages/ur5/ros2srrc_ur5_gazebo/urdf/ur5_robotiq_2f85.urdf.xacro

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,10 @@
7979
<xacro:unless value="${bringup}">
8080

8181
<gazebo>
82-
<plugin filename="libgazebo_ros2_control.so" name="gazebo_ros2_control">
83-
<robot_sim_type>gazebo_ros2_control/GazeboSystem</robot_sim_type>
84-
85-
<!-- UR5 Controller -->
82+
<plugin filename="libgz_ros2_control-system.so" name="gz_ros2_control">
83+
8684
<parameters>/home/ws/src/Industrial/ros2_SimRealRobotControl_gz/ros2srrc_robots/ur5/config/controller.yaml</parameters>
8785

88-
<!-- End-Effector Controller (if needed) -->
8986
<parameters>/home/ws/src/Industrial/ros2_SimRealRobotControl_gz/ros2srrc_endeffectors/${EE_name}/config/controller.yaml</parameters>
9087

9188
</plugin>

Industrial/ros2_SimRealRobotControl_gz/ros2srrc_execution/src/move.cpp

Lines changed: 66 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ActionServer : public rclcpp::Node
172172

173173
action_server_ = rclcpp_action::create_server<Move>(
174174
this,
175-
"/Move",
175+
"/move",
176176
std::bind(&ActionServer::handle_goal, this, std::placeholders::_1, std::placeholders::_2),
177177
std::bind(&ActionServer::handle_cancel, this, std::placeholders::_1),
178178
std::bind(&ActionServer::handle_accepted, this, std::placeholders::_1));
@@ -430,73 +430,107 @@ class ActionServer : public rclcpp::Node
430430

431431
int main(int argc, char ** argv)
432432
{
433-
// Initialise MAIN NODE:
433+
// ================= INIT =================
434434
rclcpp::init(argc, argv);
435435
auto const logger = rclcpp::get_logger("MOVE_INTERFACE");
436436

437-
// Obtain ROBOT + END-EFFECTOR + ENVIRONMENT parameters:
437+
// ================= PARAMETERS =================
438438
auto node_PARAM_ROB = std::make_shared<ros2_RobotParam>();
439439
rclcpp::spin_some(node_PARAM_ROB);
440+
440441
auto node_PARAM_EE = std::make_shared<ros2_EEParam>();
441442
rclcpp::spin_some(node_PARAM_EE);
442443

443-
// DEFINE -> RobotSPECS + eeSPECS variables:
444-
// Robot SPECIFICATIONS:
444+
// ================= LOAD SPECS =================
445445
if (param_ROB != "none"){
446-
std::string pkgPATH_R = ament_index_cpp::get_package_share_directory("ros2srrc_robots");
447-
std::string PATH_R = pkgPATH_R + "/" + param_ROB + "/config/joint_specifications.yaml";
446+
std::string pkgPATH_R =
447+
ament_index_cpp::get_package_share_directory("ros2srrc_robots");
448+
std::string PATH_R =
449+
pkgPATH_R + "/" + param_ROB + "/config/joint_specifications.yaml";
450+
448451
YAML::Node SPECIFICATIONS_R = YAML::LoadFile(PATH_R);
449-
robotSPECS.robot_max = SPECIFICATIONS_R["Limits"]["Max"].as<std::vector<double>>();
450-
robotSPECS.robot_min = SPECIFICATIONS_R["Limits"]["Min"].as<std::vector<double>>();
451-
};
452-
// End-Effector SPECIFICATIONS:
452+
453+
robotSPECS.robot_max =
454+
SPECIFICATIONS_R["Limits"]["Max"].as<std::vector<double>>();
455+
robotSPECS.robot_min =
456+
SPECIFICATIONS_R["Limits"]["Min"].as<std::vector<double>>();
457+
}
458+
453459
if (param_EE != "none"){
454-
std::string pkgPATH = ament_index_cpp::get_package_share_directory("ros2srrc_endeffectors");
455-
std::string PATH = pkgPATH + "/" + param_EE + "/config/joint_specifications.yaml";
460+
std::string pkgPATH =
461+
ament_index_cpp::get_package_share_directory("ros2srrc_endeffectors");
462+
std::string PATH =
463+
pkgPATH + "/" + param_EE + "/config/joint_specifications.yaml";
464+
456465
YAML::Node SPECIFICATIONS = YAML::LoadFile(PATH);
466+
457467
eeSPECS.ee_max = SPECIFICATIONS["Limits"]["Max"].as<double>();
458468
eeSPECS.ee_min = SPECIFICATIONS["Limits"]["Min"].as<double>();
459-
eeSPECS.ee_vector = SPECIFICATIONS["JointsVector"].as<std::vector<double>>();
460-
};
469+
eeSPECS.ee_vector =
470+
SPECIFICATIONS["JointsVector"].as<std::vector<double>>();
471+
}
461472

462-
// Launch and spin (EXECUTOR) MoveIt!2 Interface node:
463-
auto name = "ros2srrc_move";
464-
auto const node2 = std::make_shared<rclcpp::Node>(name, rclcpp::NodeOptions().automatically_declare_parameters_from_overrides(true));
465-
rclcpp::executors::SingleThreadedExecutor executor;
473+
// ================= ACTION SERVER (CLAVE) =================
474+
auto action_server = std::make_shared<ActionServer>();
475+
476+
auto node2 = std::make_shared<rclcpp::Node>(
477+
"moveit_client_node",
478+
rclcpp::NodeOptions()
479+
.automatically_declare_parameters_from_overrides(true)
480+
);
481+
482+
rclcpp::executors::SingleThreadedExecutor executor;
466483
executor.add_node(node2);
467484
std::thread([&executor]() { executor.spin(); }).detach();
468485

469-
// CREATE -> MoveGroupInterface(s):
486+
// Esperar a que MoveIt publique parámetros
487+
rclcpp::sleep_for(std::chrono::seconds(2));
488+
489+
490+
// ================= MOVEIT =================
470491
using moveit::planning_interface::MoveGroupInterface;
471-
// 1. ROBOT:
492+
493+
// ROBOT
472494
if (param_ROB != "none"){
473-
auto name = param_ROB + "_arm";
474-
475-
move_group_interface_ROB = MoveGroupInterface(node2, name);
495+
std::string group_name = "manipulator";
496+
497+
move_group_interface_ROB = MoveGroupInterface(node2, group_name);
476498
move_group_interface_ROB.setPlanningPipelineId("move_group");
477499

478500
move_group_interface_ROB.setMaxVelocityScalingFactor(1.0);
479501
move_group_interface_ROB.setMaxAccelerationScalingFactor(1.0);
480502

481-
joint_model_group_ROB = move_group_interface_ROB.getCurrentState()->getJointModelGroup(name);
482-
RCLCPP_INFO(logger, "MoveGroupInterface object created for ROBOT: %s", param_ROB.c_str());
503+
joint_model_group_ROB =
504+
move_group_interface_ROB.getCurrentState()
505+
->getJointModelGroup(group_name);
506+
507+
RCLCPP_INFO(logger,
508+
"MoveGroupInterface created for ROBOT group: %s",
509+
group_name.c_str());
483510
}
484-
// 2. END-EFFECTOR:
511+
512+
// END EFFECTOR
485513
if (param_EE != "none"){
486514
move_group_interface_EE = MoveGroupInterface(node2, param_EE);
487515
move_group_interface_EE.setPlanningPipelineId("move_group");
516+
488517
move_group_interface_EE.setMaxVelocityScalingFactor(1.0);
489518
move_group_interface_EE.setMaxAccelerationScalingFactor(1.0);
490-
joint_model_group_EE = move_group_interface_EE.getCurrentState()->getJointModelGroup(param_EE);
491-
RCLCPP_INFO(logger, "MoveGroupInterface object created for END-EFFECTOR: %s", param_EE.c_str());
519+
520+
joint_model_group_EE =
521+
move_group_interface_EE.getCurrentState()
522+
->getJointModelGroup(param_EE);
523+
524+
RCLCPP_INFO(logger,
525+
"MoveGroupInterface created for EE: %s",
526+
param_EE.c_str());
492527
}
493528

494-
// CREATE -> PlanningSceneInterface:
529+
// ================= PLANNING SCENE =================
495530
using moveit::planning_interface::PlanningSceneInterface;
496531
auto planning_scene_interface = PlanningSceneInterface();
497532

498-
// Declare and spin ACTION SERVER:
499-
auto action_server = std::make_shared<ActionServer>();
533+
// ================= SPIN =================
500534
rclcpp::spin(action_server);
501535

502536
rclcpp::shutdown();

Industrial/ros2_SimRealRobotControl_gz/ros2srrc_robots/ur5/urdf/ur5_ros2control.xacro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
<!-- A. GAZEBO SIMULATION: -->
145145
<xacro:unless value="${bringup}">
146146
<hardware>
147-
<plugin>gazebo_ros2_control/GazeboSystem</plugin>
147+
<plugin>gz_ros2_control/GazeboSimSystem</plugin>
148148
</hardware>
149149
</xacro:unless>
150150

Launchers/pick_place_harmonic/pick_place_harmonic.launch.py

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def generate_launch_description():
3737

3838
gz = ExecuteProcess(
3939
cmd=["gz", "sim", "-r", "-v", "4", world_path],
40-
output="screen"
40+
output="both"
4141
)
4242

4343
# =========================
@@ -89,16 +89,21 @@ def generate_launch_description():
8989
robot_state_publisher = Node(
9090
package="robot_state_publisher",
9191
executable="robot_state_publisher",
92-
output="screen",
92+
output="both",
93+
arguments=["--ros-args", "--log-level", "debug"],
9394
parameters=[robot_description, {"use_sim_time": True}],
9495
)
9596

96-
static_tf = Node(
97+
"""static_tf = Node(
9798
package="tf2_ros",
9899
executable="static_transform_publisher",
99-
arguments=["0", "0", "0.9", "0", "0", "0", "world", "base_link"],
100+
arguments=[
101+
"0", "0", "0.9", "0", "0", "0", "world", "base_link",
102+
"--ros-args", "--log-level", "debug",
103+
],
104+
output="both",
100105
parameters=[{"use_sim_time": True}],
101-
)
106+
)"""
102107

103108
# =========================
104109
# SPAWN ROBOT (HARMONIC)
@@ -108,13 +113,14 @@ def generate_launch_description():
108113
package="ros_gz_sim",
109114
executable="create",
110115
arguments=[
111-
"-topic", "robot_description",
116+
"-param", "robot_description",
112117
"-name", "ur5",
113118
"-x", "0.0",
114119
"-y", "0.0",
115120
"-z", "0.9",
116121
],
117-
output="screen",
122+
parameters=[robot_description],
123+
output="both",
118124
)
119125

120126
# =========================
@@ -153,15 +159,32 @@ def generate_launch_description():
153159
# =========================
154160
# MOVE GROUP (IGUAL QUE CLASSIC)
155161
# =========================
162+
163+
164+
moveit_controllers = {
165+
"moveit_simple_controller_manager": load_yaml(
166+
"ur5_gripper_moveit_config",
167+
"config/moveit_controllers.yaml"
168+
)
169+
}
170+
171+
print("===== DEBUG MOVEIT =====")
172+
print(robot_description.keys())
173+
print(robot_description_semantic.keys())
174+
print(moveit_controllers)
175+
print("========================")
156176

157177
move_group = Node(
158178
package="moveit_ros_move_group",
159179
executable="move_group",
160-
output="screen",
180+
output="both",
181+
arguments=["--ros-args", "--log-level", "debug"],
161182
parameters=[
162183
robot_description,
163184
robot_description_semantic,
164185
kinematics_yaml,
186+
moveit_controllers,
187+
{"moveit_controller_manager": "moveit_simple_controller_manager/MoveItSimpleControllerManager"},
165188
{"use_sim_time": True},
166189
],
167190
)
@@ -183,21 +206,24 @@ def generate_launch_description():
183206
move_node = Node(
184207
package="ros2srrc_execution",
185208
executable="move",
186-
output="screen",
209+
output="both",
210+
arguments=["--ros-args", "--log-level", "debug"],
187211
parameters=common_params,
188212
)
189213

190214
robmove_node = Node(
191215
package="ros2srrc_execution",
192216
executable="robmove",
193-
output="screen",
217+
output="both",
218+
arguments=["--ros-args", "--log-level", "debug"],
194219
parameters=common_params,
195220
)
196221

197222
robpose_node = Node(
198223
package="ros2srrc_execution",
199224
executable="robpose",
200-
output="screen",
225+
output="both",
226+
arguments=["--ros-args", "--log-level", "debug"],
201227
parameters=common_params,
202228
)
203229

@@ -209,29 +235,44 @@ def generate_launch_description():
209235

210236
gz,
211237
robot_state_publisher,
212-
static_tf,
238+
# static_tf,
213239
clock_bridge,
214240

215241
spawn_robot,
216242

217243
RegisterEventHandler(
218244
OnProcessExit(
219245
target_action=spawn_robot,
220-
on_exit=[joint_state_broadcaster],
246+
on_exit=[
247+
TimerAction(
248+
period=3.0,
249+
actions=[joint_state_broadcaster],
250+
)
251+
],
221252
)
222253
),
223254

224255
RegisterEventHandler(
225256
OnProcessExit(
226257
target_action=joint_state_broadcaster,
227-
on_exit=[joint_trajectory_controller],
258+
on_exit=[
259+
TimerAction(
260+
period=2.0,
261+
actions=[joint_trajectory_controller],
262+
)
263+
],
228264
)
229265
),
230266

231267
RegisterEventHandler(
232268
OnProcessExit(
233269
target_action=joint_trajectory_controller,
234-
on_exit=[gripper_controller],
270+
on_exit=[
271+
TimerAction(
272+
period=2.0,
273+
actions=[gripper_controller],
274+
)
275+
],
235276
)
236277
),
237278

@@ -240,7 +281,7 @@ def generate_launch_description():
240281
target_action=spawn_robot,
241282
on_exit=[
242283
TimerAction(
243-
period=2.0,
284+
period=5.0,
244285
actions=[move_group],
245286
)
246287
],
@@ -249,10 +290,10 @@ def generate_launch_description():
249290

250291
RegisterEventHandler(
251292
OnProcessExit(
252-
target_action=spawn_robot,
293+
target_action=move_group,
253294
on_exit=[
254295
TimerAction(
255-
period=4.0,
296+
period=5.0,
256297
actions=[move_node, robmove_node, robpose_node],
257298
)
258299
],

0 commit comments

Comments
 (0)