Skip to content

Commit feef390

Browse files
Merge branch 'moveit:jazzy' into jazzy
2 parents a54da9e + 7853b8c commit feef390

File tree

4 files changed

+121
-17
lines changed

4 files changed

+121
-17
lines changed

moveit_core/robot_state/src/robot_state.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,14 +1217,24 @@ void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bo
12171217
attached_bodies.clear();
12181218
attached_bodies.reserve(attached_body_map_.size());
12191219
for (const auto& it : attached_body_map_)
1220-
attached_bodies.push_back(it.second.get());
1220+
{
1221+
if (it.second)
1222+
{
1223+
attached_bodies.push_back(it.second.get());
1224+
}
1225+
}
12211226
}
12221227

12231228
void RobotState::getAttachedBodies(std::map<std::string, const AttachedBody*>& attached_bodies) const
12241229
{
12251230
attached_bodies.clear();
12261231
for (const auto& it : attached_body_map_)
1227-
attached_bodies[it.first] = it.second.get();
1232+
{
1233+
if (it.second && !it.first.empty())
1234+
{
1235+
attached_bodies[it.first] = it.second.get();
1236+
}
1237+
}
12281238
}
12291239

12301240
void RobotState::getAttachedBodies(std::vector<const AttachedBody*>& attached_bodies, const JointModelGroup* group) const
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*********************************************************************
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2022, Shobin Vinod
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* * Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
* * Neither the name of the copyright holder nor the names of its
18+
* contributors may be used to endorse or promote products derived
19+
* from this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*********************************************************************/
34+
35+
/* Author: Shobin Vinod */
36+
37+
#include <pybind11/pybind11.h>
38+
#include <rclcpp/rclcpp.hpp>
39+
#include <rclcpp/serialization.hpp>
40+
#include <rclcpp/duration.hpp>
41+
42+
namespace py = pybind11;
43+
44+
namespace pybind11
45+
{
46+
namespace detail
47+
{
48+
template <>
49+
struct type_caster<rclcpp::Time>
50+
{
51+
PYBIND11_TYPE_CASTER(rclcpp::Time, _("rclcpp::Time"));
52+
53+
// convert from rclpy::Time to rclcpp::Time
54+
bool load(py::handle src, bool)
55+
{
56+
if (src.is_none())
57+
return false;
58+
59+
// check to validate if the object is a rclcpp::Time object
60+
if (!py::hasattr(src, "nanoseconds") || !py::hasattr(src, "clock_type"))
61+
{
62+
return false;
63+
}
64+
65+
// Extract the value for constructing the rclcpp::Time object
66+
int64_t nanoseconds = src.attr("nanoseconds").cast<int64_t>();
67+
int clock_type = src.attr("clock_type").cast<int>();
68+
69+
// Construct the rclcpp::Time object
70+
value = rclcpp::Time(nanoseconds, static_cast<rcl_clock_type_t>(clock_type));
71+
return true;
72+
}
73+
74+
// convert from rclcpp::Time to rclpy::Time
75+
static py::handle cast(const rclcpp::Time& src, return_value_policy /* policy */, py::handle /* parent */)
76+
{
77+
py::module rclpy_time = py::module::import("rclpy.time");
78+
py::object Time = rclpy_time.attr("Time");
79+
80+
int64_t nanoseconds = src.nanoseconds();
81+
int clock_type = static_cast<int>(src.get_clock_type());
82+
83+
return Time(py::arg("nanoseconds") = nanoseconds,
84+
py::arg("clock_type") = clock_type)
85+
.release(); // release the ownership of the object
86+
}
87+
};
88+
} // namespace detail
89+
} // namespace pybind11

moveit_py/src/moveit/moveit_ros/planning_scene_monitor/planning_scene_monitor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <moveit_msgs/msg/planning_scene.hpp>
4545
#include <moveit_msgs/srv/apply_planning_scene.hpp>
4646
#include <moveit/planning_scene_monitor/planning_scene_monitor.hpp>
47+
#include <moveit_py/moveit_py_utils/rclpy_time_typecaster.hpp>
4748

4849
namespace py = pybind11;
4950

moveit_ros/planning/plan_execution/src/plan_execution.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,20 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
283283
collision_detection::CollisionRequest req;
284284
req.group_name = t.getGroupName();
285285
req.pad_environment_collisions = false;
286-
moveit::core::RobotState state = plan.planning_scene->getCurrentState();
286+
moveit::core::RobotState start_state = plan.planning_scene->getCurrentState();
287287
std::map<std::string, const moveit::core::AttachedBody*> current_attached_objects, waypoint_attached_objects;
288-
state.getAttachedBodies(current_attached_objects);
289-
waypoint_attached_objects = plan_components_attached_objects_[path_segment.first];
288+
start_state.getAttachedBodies(current_attached_objects);
289+
if (plan_components_attached_objects_.size() > static_cast<size_t>(path_segment.first))
290+
waypoint_attached_objects = plan_components_attached_objects_[path_segment.first];
291+
moveit::core::RobotState waypoint_state(start_state);
290292
for (std::size_t i = std::max(path_segment.second - 1, 0); i < wpc; ++i)
291293
{
292294
collision_detection::CollisionResult res;
293-
state = t.getWayPoint(i);
295+
waypoint_attached_objects.clear(); // clear out the last waypoints attached objects
296+
waypoint_state = t.getWayPoint(i);
294297
if (plan_components_attached_objects_[path_segment.first].empty())
295298
{
296-
state.getAttachedBodies(waypoint_attached_objects);
299+
waypoint_state.getAttachedBodies(waypoint_attached_objects);
297300
}
298301

299302
// If sample state has attached objects that are not in the current state, remove them from the sample state
@@ -302,7 +305,7 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
302305
if (current_attached_objects.find(name) == current_attached_objects.end())
303306
{
304307
RCLCPP_DEBUG(logger_, "Attached object '%s' is not in the current scene. Removing it.", name.c_str());
305-
state.clearAttachedBody(name);
308+
waypoint_state.clearAttachedBody(name);
306309
}
307310
}
308311

@@ -312,35 +315,35 @@ bool plan_execution::PlanExecution::isRemainingPathValid(const ExecutableMotionP
312315
if (waypoint_attached_objects.find(name) == waypoint_attached_objects.end())
313316
{
314317
RCLCPP_DEBUG(logger_, "Attached object '%s' is not in the robot state. Adding it.", name.c_str());
315-
state.attachBody(std::make_unique<moveit::core::AttachedBody>(*object));
318+
waypoint_state.attachBody(std::make_unique<moveit::core::AttachedBody>(*object));
316319
}
317320
}
318321

319322
if (acm)
320323
{
321-
plan.planning_scene->checkCollision(req, res, state, *acm);
324+
plan.planning_scene->checkCollision(req, res, waypoint_state, *acm);
322325
}
323326
else
324327
{
325-
plan.planning_scene->checkCollision(req, res, state);
328+
plan.planning_scene->checkCollision(req, res, waypoint_state);
326329
}
327330

328-
if (res.collision || !plan.planning_scene->isStateFeasible(state, false))
331+
if (res.collision || !plan.planning_scene->isStateFeasible(waypoint_state, false))
329332
{
330333
RCLCPP_INFO(logger_, "Trajectory component '%s' is invalid for waypoint %ld out of %ld",
331334
plan.plan_components[path_segment.first].description.c_str(), i, wpc);
332335

333336
// call the same functions again, in verbose mode, to show what issues have been detected
334-
plan.planning_scene->isStateFeasible(state, true);
337+
plan.planning_scene->isStateFeasible(waypoint_state, true);
335338
req.verbose = true;
336339
res.clear();
337340
if (acm)
338341
{
339-
plan.planning_scene->checkCollision(req, res, state, *acm);
342+
plan.planning_scene->checkCollision(req, res, waypoint_state, *acm);
340343
}
341344
else
342345
{
343-
plan.planning_scene->checkCollision(req, res, state);
346+
plan.planning_scene->checkCollision(req, res, waypoint_state);
344347
}
345348
return false;
346349
}
@@ -469,7 +472,7 @@ moveit_msgs::msg::MoveItErrorCodes plan_execution::PlanExecution::executeAndMoni
469472
{
470473
const auto& trajectory = component.trajectory;
471474
std::map<std::string, const moveit::core::AttachedBody*> trajectory_attached_objects;
472-
if (trajectory)
475+
if (trajectory && trajectory->getWayPointCount() > 0)
473476
{
474477
std::map<std::string, const moveit::core::AttachedBody*> attached_objects;
475478
trajectory->getWayPoint(0).getAttachedBodies(trajectory_attached_objects);
@@ -483,7 +486,8 @@ moveit_msgs::msg::MoveItErrorCodes plan_execution::PlanExecution::executeAndMoni
483486
}
484487
}
485488
}
486-
plan_components_attached_objects_.push_back(trajectory_attached_objects);
489+
if (!trajectory_attached_objects.empty())
490+
plan_components_attached_objects_.push_back(trajectory_attached_objects);
487491
}
488492

489493
while (rclcpp::ok() && !execution_complete_ && !path_became_invalid_)

0 commit comments

Comments
 (0)