@@ -1217,7 +1217,6 @@ def joint_velocity_damper(self, ps=0.05, pi=0.1, n=None, gain=1.0):
12171217 make it impossible for the robot to run into joint limits. Requires
12181218 the joint limits of the robot to be specified. See examples/mmc.py
12191219 for use case
1220-
12211220 :param ps: The minimum angle (in radians) in which the joint is
12221221 allowed to approach to its limit
12231222 :type ps: float
@@ -1228,7 +1227,6 @@ def joint_velocity_damper(self, ps=0.05, pi=0.1, n=None, gain=1.0):
12281227 :type n: int
12291228 :param gain: The gain for the velocity damper
12301229 :type gain: float
1231-
12321230 :returns: Ain, Bin as the inequality contraints for an optisator
12331231 :rtype: ndarray(6), ndarray(6)
12341232 '''
@@ -1251,39 +1249,69 @@ def joint_velocity_damper(self, ps=0.05, pi=0.1, n=None, gain=1.0):
12511249
12521250 return Ain , Bin
12531251
1254- # def link_collision_damper(self, links=None, col, ob, q):
1255- # dii = 5
1256- # di = 0.3
1257- # ds = 0.05
1252+ def link_collision_damper (
1253+ self , shape , q = None , di = 0.3 , ds = 0.05 , xi = 1.0 ,
1254+ from_link = None , to_link = None ):
1255+
1256+ if from_link is None :
1257+ from_link = self .base_link
1258+
1259+ if to_link is None :
1260+ to_link = self .ee_link
1261+
1262+ links , n = self .get_path (from_link , to_link )
1263+
1264+ if q is None :
1265+ q = np .copy (self .q )
1266+ else :
1267+ q = getvector (q , n )
12581268
1259- # if links is None:
1260- # links = self.links[1:]
1269+ j = 0
1270+ Ain = None
1271+ bin = None
1272+
1273+ def indiv_calculation (link , link_col , q ):
1274+ d , wTlp , wTcp = link_col .closest_point (shape , di )
1275+
1276+ if d is not None :
1277+ lpTcp = wTlp .inv () * wTcp
1278+ norm = lpTcp .t / d
1279+ norm_h = np .expand_dims (np .r_ [norm , 0 , 0 , 0 ], axis = 0 )
1280+
1281+ Je = self .jacobe (
1282+ q , from_link = self .base_link , to_link = link ,
1283+ offset = link_col .base )
1284+ n_dim = Je .shape [1 ]
1285+ dp = norm_h @ shape .v
1286+ l_Ain = np .zeros ((1 , n ))
1287+ l_Ain [0 , :n_dim ] = norm_h @ Je
1288+ l_bin = (xi * (d - ds ) / (di - ds )) + dp
1289+ else :
1290+ l_Ain = None
1291+ l_bin = None
12611292
1262- # ret = p.getClosestPoints(col.co, ob.co, dii)
1293+ return l_Ain , l_bin , d , wTcp
12631294
1264- # if len(ret) > 0:
1265- # ret = ret[0]
1266- # wTlp = sm.SE3(ret[5])
1267- # wTcp = sm.SE3(ret[6])
1268- # lpTcp = wTlp.inv() * wTcp
1295+ for link in links :
1296+ if link .jtype == link .VARIABLE :
1297+ j += 1
12691298
1270- # d = ret[8]
1299+ for link_col in link .collision :
1300+ l_Ain , l_bin , d , wTcp = indiv_calculation (
1301+ link , link_col , q [:j ])
12711302
1272- # if d < di:
1273- # n = lpTcp.t / d
1274- # nh = np.expand_dims(np.r_[n, 0, 0, 0], axis=0)
1303+ if l_Ain is not None and l_bin is not None :
1304+ if Ain is None :
1305+ Ain = l_Ain
1306+ else :
1307+ Ain = np .r_ [Ain , l_Ain ]
12751308
1276- # Je = r.jacobe(q, from_link=r.base_link, to_link=link, offset=col.base)
1277- # n = Je.shape[1]
1278- # dp = nh @ ob.v
1279- # l_Ain = np.zeros((1, 13))
1280- # l_Ain[0, :n] = nh @ Je
1281- # l_bin = (0.8 * (d - ds) / (di - ds)) + dp
1282- # else:
1283- # l_Ain = None
1284- # l_bin = None
1309+ if bin is None :
1310+ bin = np .array (l_bin )
1311+ else :
1312+ bin = np .r_ [bin , l_bin ]
12851313
1286- # return l_Ain, l_bin, d, wTcp
1314+ return Ain , bin
12871315
12881316 def closest_point (self , shape , inf_dist = 1.0 ):
12891317 '''
@@ -1292,7 +1320,6 @@ def closest_point(self, shape, inf_dist=1.0):
12921320 inf_dist. It will also return the points on self and shape in the
12931321 world frame which connect the line of length distance between the
12941322 shapes. If the distance is negative then the shapes are collided.
1295-
12961323 :param shape: The shape to compare distance to
12971324 :type shape: Shape
12981325 :param inf_dist: The minimum distance within which to consider
@@ -1324,7 +1351,6 @@ def closest_point(self, shape, inf_dist=1.0):
13241351 def collided (self , shape ):
13251352 '''
13261353 collided(shape) checks if this robot and shape have collided
1327-
13281354 :param shape: The shape to compare distance to
13291355 :type shape: Shape
13301356 :returns: True if shapes have collided
0 commit comments