8
8
import tempfile
9
9
import subprocess
10
10
import webbrowser
11
- from numpy import array , ndarray , isnan , zeros , eye , expand_dims , empty , concatenate
11
+ from numpy import (
12
+ array ,
13
+ ndarray ,
14
+ isnan ,
15
+ zeros ,
16
+ eye ,
17
+ expand_dims ,
18
+ empty ,
19
+ concatenate ,
20
+ cross ,
21
+ arccos ,
22
+ dot ,
23
+ )
24
+ from numpy .linalg import norm as npnorm , inv
12
25
from spatialmath import SE3 , SE2
13
26
from spatialgeometry import Cylinder
14
27
from spatialmath .base .argcheck import getvector , islistof
@@ -2019,7 +2032,6 @@ def vision_collision_damper(
2019
2032
:returns: Ain, Bin as the inequality contraints for an omptimisor
2020
2033
:rtype: ndarray(6), ndarray(6)
2021
2034
"""
2022
- import numpy as np
2023
2035
2024
2036
if start is None :
2025
2037
start = self .base_link
@@ -2034,11 +2046,11 @@ def vision_collision_damper(
2034
2046
bin = None
2035
2047
2036
2048
def rotation_between_vectors (a , b ):
2037
- a = a / np . linalg . norm (a )
2038
- b = b / np . linalg . norm (b )
2049
+ a = a / npnorm (a )
2050
+ b = b / npnorm (b )
2039
2051
2040
- angle = np . arccos (np . dot (a , b ))
2041
- axis = np . cross (a , b )
2052
+ angle = arccos (dot (a , b ))
2053
+ axis = cross (a , b )
2042
2054
2043
2055
return SE3 .AngleAxis (angle , axis )
2044
2056
@@ -2051,13 +2063,11 @@ def rotation_between_vectors(a, b):
2051
2063
2052
2064
# Create line of sight object
2053
2065
los_mid = SE3 ((wTcp + wTtp ) / 2 )
2054
- los_orientation = rotation_between_vectors (
2055
- np .array ([0.0 , 0.0 , 1.0 ]), wTcp - wTtp
2056
- )
2066
+ los_orientation = rotation_between_vectors (array ([0.0 , 0.0 , 1.0 ]), wTcp - wTtp )
2057
2067
2058
2068
los = Cylinder (
2059
2069
radius = 0.001 ,
2060
- length = np . linalg . norm (wTcp - wTtp ),
2070
+ length = npnorm (wTcp - wTtp ),
2061
2071
base = (los_mid * los_orientation ),
2062
2072
)
2063
2073
@@ -2068,11 +2078,9 @@ def indiv_calculation(link, link_col, q):
2068
2078
lpTvp = - wTlp + wTvp
2069
2079
2070
2080
norm = lpTvp / d
2071
- norm_h = np . expand_dims (np . r_ [ norm , 0 , 0 , 0 ], axis = 0 )
2081
+ norm_h = expand_dims (concatenate (( norm , [ 0 , 0 , 0 ])) , axis = 0 )
2072
2082
2073
- tool = SE3 (
2074
- (np .linalg .inv (self .fkine (q , end = link ).A ) @ SE3 (wTlp ).A )[:3 , 3 ]
2075
- )
2083
+ tool = SE3 ((inv (self .fkine (q , end = link ).A ) @ SE3 (wTlp ).A )[:3 , 3 ])
2076
2084
2077
2085
Je = self .jacob0 (q , end = link , tool = tool .A )
2078
2086
Je [:3 , :] = self ._T [:3 , :3 ] @ Je [:3 , :]
@@ -2082,21 +2090,23 @@ def indiv_calculation(link, link_col, q):
2082
2090
Jv = camera .jacob0 (camera .q )
2083
2091
Jv [:3 , :] = self ._T [:3 , :3 ] @ Jv [:3 , :]
2084
2092
2085
- Jv *= np . linalg . norm (wTvp - shape .T [:3 , - 1 ]) / los .length
2093
+ Jv *= npnorm (wTvp - shape .T [:3 , - 1 ]) / los .length
2086
2094
2087
2095
dpc = norm_h @ Jv
2088
- dpc = np .r_ [
2089
- dpc [0 , :- camera_n ],
2090
- np .zeros (self .n - (camera .n - camera_n )),
2091
- dpc [0 , - camera_n :],
2092
- ]
2096
+ dpc = concatenate (
2097
+ (
2098
+ dpc [0 , :- camera_n ],
2099
+ zeros (self .n - (camera .n - camera_n )),
2100
+ dpc [0 , - camera_n :],
2101
+ )
2102
+ )
2093
2103
else :
2094
- dpc = np . zeros ((1 , self .n + camera_n ))
2104
+ dpc = zeros ((1 , self .n + camera_n ))
2095
2105
2096
2106
dpt = norm_h @ shape .v
2097
- dpt *= np . linalg . norm (wTvp - wTcp ) / los .length
2107
+ dpt *= npnorm (wTvp - wTcp ) / los .length
2098
2108
2099
- l_Ain = np . zeros ((1 , self .n + camera_n ))
2109
+ l_Ain = zeros ((1 , self .n + camera_n ))
2100
2110
l_Ain [0 , :n_dim ] = norm_h @ Je
2101
2111
l_Ain -= dpc
2102
2112
l_bin = (xi * (d - ds ) / (di - ds )) + dpt
0 commit comments