@@ -2026,6 +2026,8 @@ def link_collision_damper(
20262026 end = None ,
20272027 start = None ,
20282028 collision_list = None ,
2029+ wTcamp = None ,
2030+ wTtp = None
20292031 ):
20302032 """
20312033 Formulates an inequality contraint which, when optimised for will
@@ -2075,7 +2077,6 @@ def indiv_calculation(link, link_col, q):
20752077 lpTcp = - wTlp + wTcp
20762078
20772079 norm = lpTcp / d
2078- # norm = self.fkine(q, end=link, fast=True)[:3, :3] @ norm
20792080 norm_h = np .expand_dims (np .r_ [norm , 0 , 0 , 0 ], axis = 0 )
20802081
20812082 tool = SE3 ((np .linalg .inv (self .fkine (q , end = link , fast = True )) @ SE3 (wTlp ).A )[:3 , 3 ])
@@ -2085,11 +2086,13 @@ def indiv_calculation(link, link_col, q):
20852086 )
20862087 Je [:3 , :] = self ._base .A [:3 , :3 ] @ Je [:3 , :]
20872088
2088-
2089- # print(Je)
2090-
20912089 n_dim = Je .shape [1 ]
20922090 dp = norm_h @ shape .v
2091+ if wTcamp is not None and wTtp is not None :
2092+ length = np .linalg .norm (wTcp - wTcamp )
2093+ total_length = np .linalg .norm (wTtp - wTcamp )
2094+ dp *= length / total_length
2095+
20932096 l_Ain = np .zeros ((1 , self .n ))
20942097 l_Ain [0 , :n_dim ] = norm_h @ Je
20952098 l_bin = (xi * (d - ds ) / (di - ds )) + 0
@@ -2098,7 +2101,7 @@ def indiv_calculation(link, link_col, q):
20982101 l_bin = None
20992102
21002103 return l_Ain , l_bin , d , wTcp
2101-
2104+
21022105 for link in links :
21032106 if link .isjoint :
21042107 j += 1
@@ -2127,7 +2130,7 @@ def indiv_calculation(link, link_col, q):
21272130 else :
21282131 din = np .r_ [din , d ]
21292132
2130- return Ain , bin
2133+ return Ain , bin , din
21312134
21322135 def vision_collision_damper (
21332136 self ,
@@ -2139,13 +2142,12 @@ def vision_collision_damper(
21392142 end = None ,
21402143 start = None ,
21412144 collision_list = None ,
2142- camera = None ,
2143- obj = None
2145+ camera = None
21442146 ):
21452147 """
21462148 Formulates an inequality contraint which, when optimised for will
2147- make it impossible for the robot to self-occlude
2148- :param shape: The line of sight object.
2149+ make it impossible for the robot to run into a collision. Requires
2150+ See examples/neo.py for use case
21492151 :param ds: The minimum distance in which a joint is allowed to
21502152 approach the collision object shape
21512153 :type ds: float
@@ -2173,6 +2175,11 @@ def vision_collision_damper(
21732175
21742176 links , n , _ = self .get_path (start = start , end = end )
21752177
2178+ # if q is None:
2179+ # q = np.copy(self.q)
2180+ # else:
2181+ # q = getvector(q, n)
2182+
21762183 j = 0
21772184 Ain = None
21782185 bin = None
@@ -2185,34 +2192,27 @@ def indiv_calculation(link, link_col, q):
21852192 lpTcp = - wTlp + wTcp
21862193
21872194 norm = lpTcp / d
2188-
2189- norm_e = self .fkine (q , end = link , fast = True )[:3 , :3 ] @ norm
2190- norm_v = camera .fkine (camera .q , fast = True )[:3 , :3 ] @ norm
2191-
2192- norm_e = np .expand_dims (np .r_ [norm_e , 0 , 0 , 0 ], axis = 0 )
2193- norm_v = np .expand_dims (np .r_ [norm_v , 0 , 0 , 0 ], axis = 0 )
2194-
21952195 norm_h = np .expand_dims (np .r_ [norm , 0 , 0 , 0 ], axis = 0 )
21962196
21972197 tool = SE3 ((np .linalg .inv (self .fkine (q , end = link , fast = True )) @ SE3 (wTlp ).A )[:3 , 3 ])
21982198
2199- Je = self .jacobe (
2199+ Je = self .jacob0 (
22002200 q , end = link , tool = tool .A , fast = True
22012201 )
2202+ Je [:3 , :] = self ._base .A [:3 , :3 ] @ Je [:3 , :]
22022203
2203- Jv = camera .jacobe (camera .q , fast = True )
2204-
2205- total_length = shape . _length
2206- length = np . linalg . norm ( wTcp - obj )
2207- Jv *= length / total_length
2204+ wTc = camera .fkine (camera .q , fast = True )
2205+ Jv = camera . jacob0 (
2206+ camera . q , tool = SE3 ( np . linalg . inv ( wTc [: 3 , : 3 ]) @ ( wTcp - wTc [: 3 , - 1 ])). A , fast = True
2207+ )
2208+ Jv [: 3 , :] = self . _base . A [: 3 , : 3 ] @ Jv [: 3 , :]
22082209
22092210 n_dim = Je .shape [1 ]
2210- dp = norm_v @ Jv
2211+ dp = norm_h @ Jv
22112212 l_Ain = np .zeros ((1 , self .n + 2 + 10 ))
2212- l_Ain [0 , :n_dim ] = norm_e @ Je
2213+ l_Ain [0 , :n_dim ] = norm_h @ Je
22132214 l_Ain -= np .r_ [dp [0 , :3 ], np .zeros (7 ), dp [0 , 3 :], np .zeros (9 ), 1 ]
22142215 l_bin = (xi * (d - ds ) / (di - ds ))
2215-
22162216 else :
22172217 l_Ain = None
22182218 l_bin = None
0 commit comments