Skip to content

Commit 6d41610

Browse files
committed
Integrate monicas code
1 parent 89d91bd commit 6d41610

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

constants.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
Place all tunable "magic numbers" here so they are easy to discover and tweak.
44
"""
55
from typing import Tuple
6+
import numpy as np
67

78
# Sampling (table / cube placement)
8-
DEFAULT_TABLE_Z_RANGE: Tuple[float, float] = (0.93, 1.3)
9+
DEFAULT_TABLE_Z_RANGE: Tuple[float, float] = (0.93, 1.4)
910
DEFAULT_CHECK_COLLISIONS: bool = True
1011

1112
# RRT / planning
1213
DEFAULT_NUM_ITER: int = 500
13-
DEFAULT_DISCRETISATION_STEPS: int = 8
14+
DEFAULT_DISCRETISATION_STEPS: int = 100
1415
DEFAULT_CHECK_EDGE_STEPS: int = 1000
1516
EDGE_DISTANCE_TOL: float = 1e-3
1617

@@ -28,27 +29,37 @@
2829
DEFAULT_MAX_IK_ATTEMPTS: int = 3
2930
DEFAULT_MAX_TIME_S: float = 30.0
3031

32+
# Control gains
33+
Kp = 1000 # proportional gain (P of PD)
34+
Kv = 30 * np.sqrt(Kp) # derivative gain (D of PD)
35+
36+
Kx_lin = 1000 # Very stiff position control
37+
Dx_lin = 5 * np.sqrt(Kx_lin)
38+
39+
Kx_rot = 1000
40+
Dx_rot = 1 * np.sqrt(Kx_rot)
41+
3142
# Preset bundles for convenience: 'fast', 'default', 'robust'
3243
PRESETS = {
3344
'fast': {
34-
'num_iter': 200,
35-
'discretisation': 8,
45+
'num_iter': 500,
46+
'discretisation': 100,
3647
'repair_attempts': 3,
3748
'goal_bias': 0.02,
3849
'max_ik_attempts': 3,
3950
'max_time_s': 15.0,
4051
},
4152
'default': {
42-
'num_iter': 500,
43-
'discretisation': 8,
53+
'num_iter': 1000,
54+
'discretisation': 100,
4455
'repair_attempts': 5,
4556
'goal_bias': 0.03,
4657
'max_ik_attempts': 3,
4758
'max_time_s': 30.0,
4859
},
4960
'robust': {
5061
'num_iter': 1000,
51-
'discretisation': 10,
62+
'discretisation': 100,
5263
'repair_attempts': 8,
5364
'goal_bias': 0.05,
5465
'max_ik_attempts': 5,

control.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,9 @@
1515
from cube_trajectory_wrapper import GlobalMinJerkLinearJTraj
1616
from tools import setcubeplacement
1717
from config import LEFT_HAND, RIGHT_HAND
18+
from constants import Kp, Kv, Kx_lin, Dx_lin, Kx_rot, Dx_rot
1819

1920
import pybullet as pyb
20-
21-
# in my solution these gains were good enough for all joints but you might want to tune this.
22-
Kp = 1000 # proportional gain (P of PD)
23-
Kv = 30 * np.sqrt(Kp) # derivative gain (D of PD)
24-
25-
Kx_lin = 2000 # Very stiff position control
26-
Dx_lin = 5 * np.sqrt(Kx_lin)
27-
28-
Kx_rot = 1000
29-
Dx_rot = 10
3021

3122
def controllaw(sim, robot, trajs, tcurrent):
3223
"""Joint trajectory tracking with end-effector force correction"""
@@ -118,7 +109,7 @@ def controllaw(sim, robot, trajs, tcurrent):
118109
from inverse_geometry import computeqgrasppose
119110
from path import computepath
120111

121-
robot, sim, table, cube = setupwithpybullet()
112+
robot, sim, cube = setupwithpybullet()
122113

123114
q0, successinit = computeqgrasppose(robot, robot.q0, cube, CUBE_PLACEMENT, None)
124115
qe, successend = computeqgrasppose(robot, robot.q0, cube, CUBE_PLACEMENT_TARGET, None)
@@ -162,6 +153,8 @@ def maketraj_with_joint_space_linear(
162153

163154
total_time=10.
164155

156+
print(path, len(path))
157+
165158
trajs = maketraj_with_joint_space_linear(
166159
waypoints=path,
167160
T=total_time

inverse_geometry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
from numpy.linalg import pinv,inv,norm,svd,eig
1212
import time
13-
from tools import collision, getcubeplacement, setcubeplacement, projecttojointlimits
13+
from tools import collision, getcubeplacement, setcubeplacement, projecttojointlimits, jointlimitsviolated
1414
from config import LEFT_HOOK, RIGHT_HOOK, LEFT_HAND, RIGHT_HAND, EPSILON
1515
from config import CUBE_PLACEMENT, CUBE_PLACEMENT_TARGET
1616

@@ -82,7 +82,7 @@ def computeqgrasppose(robot, qcurrent, cube, cubetarget, viz=None, max_attempts:
8282
if viz_sleep:
8383
time.sleep(0.1)
8484

85-
if lerror < EPSILON and rerror < EPSILON and not collision(robot, q):
85+
if lerror < EPSILON and rerror < EPSILON and not collision(robot, q) and not jointlimitsviolated(robot, q):
8686
success = True
8787
break
8888

0 commit comments

Comments
 (0)