Skip to content

Velocity scaling factor when using cartesian trajectories #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion pymoveit2/moveit2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

from pymoveit2.utils import enum_to_str

from builtin_interfaces.msg import Duration as DurationMsg


class MoveIt2State(Enum):
"""
Expand All @@ -60,6 +62,21 @@ class MoveIt2State(Enum):
EXECUTING = 2


def scale_duration(duration_msg: DurationMsg, factor: float) -> DurationMsg:
# Convert original Duration to total nanoseconds
total_nanoseconds = duration_msg.sec * 1_000_000_000 + duration_msg.nanosec

# Multiply
scaled_nanoseconds = int(total_nanoseconds * factor)

# Convert back to Duration message
scaled_msg = DurationMsg()
scaled_msg.sec = scaled_nanoseconds // 1_000_000_000
scaled_msg.nanosec = scaled_nanoseconds % 1_000_000_000

return scaled_msg


class MoveIt2:
"""
Python interface for MoveIt 2 that enables planning and execution of trajectories.
Expand Down Expand Up @@ -512,6 +529,7 @@ def plan(
cartesian: bool = False,
max_step: float = 0.0025,
cartesian_fraction_threshold: float = 0.0,
cartesian_velocity_scaling_factor: float = 4.0,
) -> Optional[JointTrajectory]:
"""
Call plan_async and wait on future
Expand All @@ -532,12 +550,26 @@ def plan(
while not future.done():
rclpy.spin_once(self._node, timeout_sec=1.0)

return self.get_trajectory(
traj = self.get_trajectory(
future,
cartesian=cartesian,
cartesian_fraction_threshold=cartesian_fraction_threshold,
)

if cartesian and traj is not None:
# Rescale trajectory time, velocities and accelerations for cartesian plans
for point in traj.points:
point.time_from_start = scale_duration(point.time_from_start, cartesian_velocity_scaling_factor)

for i, v in enumerate(point.velocities):
point.velocities[i] = v / cartesian_velocity_scaling_factor

for i, a in enumerate(point.accelerations):
point.accelerations[i] = a / (cartesian_velocity_scaling_factor ** 2)


return traj

def plan_async(
self,
pose: Optional[Union[PoseStamped, Pose]] = None,
Expand Down Expand Up @@ -2435,3 +2467,4 @@ def init_dummy_joint_trajectory_from_state(
joint_trajectory.points.append(point)

return joint_trajectory

2 changes: 1 addition & 1 deletion pymoveit2/robots/xarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def base_link_name(prefix: str = "") -> str:


def end_effector_name(prefix: str = "") -> str:
return prefix + "xarm_gripper"
return prefix + "link_tcp"


def gripper_joint_names(prefix: str = "") -> List[str]:
Expand Down