def get_power(self): max_power = 0.0 if self.audio_power_port.getInputCount(): power_matrix = yarp.Matrix() self.audio_power_port.read(power_matrix) power_values = [power_matrix[0, 1], power_matrix[0, 0]] max_power = np.max(power_values) info("Max power is {}".format(max_power)) return max_power
def test_vector_copy_costructor(self): vecSize = 10 vec = yarp.Vector(vecSize) self.assertEqual(vec.size(), vecSize) vecCheck = yarp.Vector(vec) self.assertEqual(vec.size(), vecCheck.size()) # Check copy constructor from a Vector # returned by a function mat = yarp.Matrix(3, 3) mat.eye() vecTest = yarp.Vector(mat.getRow(0)) self.assertEqual(vecTest.size(), 3)
def np_to_yarp(v): if len(v.shape) == 1: # Vector yarp_vec = yarp.Vector(v.shape[0]) for i in range(v.shape[0]): yarp_vec[i] = v[i] return yarp_vec elif len(v.shape) == 2: # Matrix yarp_mat = yarp.Matrix(v.shape[0], v.shape[1]) for i in range(v.shape[0]): for j in range(v.shape[1]): yarp_mat[i, j] = v[i, j] return yarp_mat else: raise Exception("Only 1D or 2D numpy arrays are supported")
def test_vector_copy_costructor(self): vecSize = 10 vec = yarp.Vector(vecSize) self.assertEqual(vec.size(), vecSize) vecCheck = yarp.Vector(vec) self.assertEqual(vec.size(), vecCheck.size()) # Check copy constructor from a Vector # returned by a function mat = yarp.Matrix(3, 3) mat.eye() vecTest = yarp.Vector(mat.getRow(0)) self.assertEqual(vecTest.size(), 3) # Initializer list constructor vec2 = yarp.Vector([1.0, 2.0, 3.0]) self.assertEqual(vec2.size(), 3) self.assertEqual(vec2.get(0), 1.0) self.assertEqual(vec2.get(1), 2.0) self.assertEqual(vec2.get(2), 3.0)
# And we assume that the standard deviation of the measurement noise is 0.1 V. # Measurement: z = [0.39, 0.50, 0.48, 0.29, 0.25, 0.32, 0.34, 0.48, 0.41, 0.45] # A=1, B=0, H=1, Q=0, R=0.1 from __future__ import (absolute_import, division, print_function) from future import standard_library standard_library.install_aliases() import yarp import icub log = yarp.Log() A = yarp.Matrix(1, 1) A[0, 0] = 1. H = yarp.Matrix(1, 1) H[0, 0] = 1. Q = yarp.Matrix(1, 1) Q[0, 0] = 0. R = yarp.Matrix(1, 1) R[0, 0] = 0.1 x0 = yarp.Vector(1, 0.) P0 = H kal = icub.Kalman(A, H, Q, R) kal.init(x0, P0) z = [0.39, 0.50, 0.48, 0.29, 0.25, 0.32, 0.34, 0.48, 0.41, 0.45]