Skip to content

Commit 5a7307d

Browse files
committed
adding jp_servo and refactor p_servo to cp_servo
1 parent dd2c953 commit 5a7307d

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

roboticstoolbox/tools/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from roboticstoolbox.tools.null import null
2-
from roboticstoolbox.tools.p_servo import p_servo, angle_axis, angle_axis_python
2+
from roboticstoolbox.tools.p_servo import cp_servo, jp_servo, angle_axis, angle_axis_python
33
from roboticstoolbox.tools.Ticker import Ticker
44
from roboticstoolbox.tools.urdf import * # noqa
55
from roboticstoolbox.tools.trajectory import (
@@ -26,7 +26,8 @@
2626

2727
__all__ = [
2828
"null",
29-
"p_servo",
29+
"cp_servo",
30+
"jp_servo",
3031
"angle_axis_python",
3132
"angle_axis",
3233
"Ticker",

roboticstoolbox/tools/p_servo.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ def angle_axis_python(T, Td):
4242
return e
4343

4444

45-
def p_servo(
45+
def cp_servo(
4646
wTe, wTep, gain: Union[float, ArrayLike] = 1.0, threshold=0.1, method="rpy"
4747
):
4848
"""
49-
Position-based servoing.
49+
Cartesian position-based servoing.
5050
5151
Returns the end-effector velocity which will cause the robot to approach
5252
the desired pose.
@@ -104,6 +104,40 @@ def p_servo(
104104

105105
return v, arrived
106106

107+
def jp_servo(q, q_dest, gain: Union[float, ArrayLike] = 1.0, threshold=0.1):
108+
"""
109+
joint space position-based servoing.
110+
111+
Returns the joint velocities which will cause the robot to approach the desired joint positions.
112+
113+
:param q: The current joint positions of the robot.
114+
:type q: ndarray
115+
:param qd: The desired joint positions of the robot.
116+
:type qd: ndarray
117+
:param gain: The gain for the controller. Can be a scalar or a vector corresponding to each joint.
118+
:type gain: float, or array-like
119+
:param threshold: The threshold or tolerance of the final error between the robot's joint positions and desired joint positions.
120+
:type threshold: float
121+
:returns qdd: The joint velocities which will cause the robot to approach qd.
122+
:rtype qdd: ndarray(n)
123+
:returns arrived: True if the robot is within the threshold of the final joint positions.
124+
:rtype arrived: bool
125+
"""
126+
# Joint position error
127+
e = q_dest - q
128+
129+
if base.isscalar(gain):
130+
k = gain * np.eye(len(q))
131+
else:
132+
k = np.diag(gain)
133+
134+
# Joint velocities
135+
qdd = k @ e
136+
137+
arrived = True if np.sum(np.abs(e)) < threshold else False
138+
139+
return qdd, arrived
140+
107141
def pid_servo(wTe, wTep, prev_error, integral_error, dt, gains, threshold=0.1, method="rpy"):
108142
"""
109143
Position-based servoing with PID control.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy