You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to use the IMU cased motion capture in my application with the biorbd and I'd like to do it in python :D
So far I was able to augment my model with the IMUs and I was able to modify you example code for inverse kinematics (marker based) to use IMUs. And it works great!
This is the example code.
importnumpyasnpimportbiorbdtry:
importbiovizbiorbd_viz_found=TrueexceptModuleNotFoundError:
biorbd_viz_found=False# Load a predefined modelmodel=biorbd.Model("pyomeca_models/BrasCompletIMUS.bioMod")
nq=model.nbQ()
nb_mus=model.nbMuscles()
# Generate clapping gesture datan_frames=20qinit=np.array([ 0, -0.3, 0.35, 1.15, -0.35, 1.15, 0])
qmid=np.array([ -1, -0.3, 0.5, 0.8, -1.5, 1.15, 1])
qfinal=np.array([ 0, -0.3, 0.35, 1.15, -0.35, 1.15, 0 ])
target_q=np.concatenate((np.linspace(qinit, qmid, n_frames).T, np.linspace(qmid, qfinal, n_frames).T), axis=1)
# tranfsforming imu to imu dataimusOverFrames= []
fori, qinenumerate(target_q.T):
imusOverFrames.append([imuforimuinmodel.IMU(q)])
# Create a Kalman filter structurefreq=100# Hzparams=biorbd.KalmanParam(freq)
# kalman = biorbd.KalmanReconsMarkers(model, params)kalman=biorbd.KalmanReconsIMU(model, params)
# Perform the kalman filter for each frame (the first frame is much longer than the next)Q=biorbd.GeneralizedCoordinates(qinit)
Qdot=biorbd.GeneralizedVelocity(model)
Qddot=biorbd.GeneralizedAcceleration(model)
q_recons=np.ndarray((model.nbQ(), len(imusOverFrames)))
fori, targetIMUsinenumerate(imusOverFrames):
kalman.reconstructFrame(model, targetIMUs, Q, Qdot, Qddot)
q_recons[:, i] =Q.to_array()
# Print the kinematics to the consoleprint(f"Frame {i}\nExpected Q = {target_q[:, i]}\nCurrent Q = {q_recons[:, i]}\n")
# Animate the results if biorbd viz is installedifbiorbd_viz_found:
b=bioviz.Viz(loaded_model=model)
b.load_movement(q_recons)
b.exec()
However I'm having issues if I try to use the numpy array data as the target IMU data. The numpy array data will be the type of data that I'll be getting from my sensors. In the example above you can see that I'm providing the Kalman filter the IMU class instances :
# tranfsforming imu to imu dataimusOverFrames= []
fori, qinenumerate(target_q.T):
imusOverFrames.append([imuforimuinmodel.IMU(q)])
In your cpp code you've used just simple utils::Vector, for example:
imus=np.ndarray((3,3, model.nbIMUs(), 2*n_frames))
fori, qinenumerate(target_q.T):
imus[:, :, :, i] =np.array([imu.to_array()[:3,:3] forimuinmodel.IMU(q)]).T# Dispatch imus in biorbd structure so KF can use itimusOverFrames= []
foriinrange(imus.shape[3]):
imusOverFrames.append([imuforimuinimus[:, :, :, i].T])
But this results in the binding error:
TypeError: Wrong number or type of arguments for overloaded function'KalmanReconsIMU_reconstructFrame'.
Possible C/C++ prototypes are:
BiorbdEigen3::rigidbody::KalmanReconsIMU::reconstructFrame(BiorbdEigen3::Model &,std::vector< BiorbdEigen3::rigidbody::IMU,std::allocator< BiorbdEigen3::rigidbody::IMU >> const &,BiorbdEigen3::rigidbody::GeneralizedCoordinates *,BiorbdEigen3::rigidbody::GeneralizedVelocity *,BiorbdEigen3::rigidbody::GeneralizedAcceleration *)
BiorbdEigen3::rigidbody::KalmanReconsIMU::reconstructFrame(BiorbdEigen3::Model &,BiorbdEigen3::utils::Vector const &,BiorbdEigen3::rigidbody::GeneralizedCoordinates *,BiorbdEigen3::rigidbody::GeneralizedVelocity *,BiorbdEigen3::rigidbody::GeneralizedAcceleration *)
BiorbdEigen3::rigidbody::KalmanReconsIMU::reconstructFrame()
I've also tried the strategy to create the IMU instances for each rotation matrix received from the sensor but I've had issues there too. :D
Given a rotation matrix, by trying to create an instance of IMU class, I ended up doing something like this:
Hello!
I'd like to use the IMU cased motion capture in my application with the biorbd and I'd like to do it in python :D
So far I was able to augment my model with the IMUs and I was able to modify you example code for inverse kinematics (marker based) to use IMUs. And it works great!
This is the example code.
However I'm having issues if I try to use the numpy array data as the target IMU data. The numpy array data will be the type of data that I'll be getting from my sensors. In the example above you can see that I'm providing the Kalman filter the IMU class instances :
In your cpp code you've used just simple
utils::Vector
, for example:biorbd/binding/c/biorbd_c.cpp
Line 253 in 3a9f4aa
So I've tried something similar in python:
But this results in the binding error:
I've also tried the strategy to create the IMU instances for each rotation matrix received from the sensor but I've had issues there too. :D
Given a rotation matrix, by trying to create an instance of IMU class, I ended up doing something like this:
But I still got some binding errors:
So there is definitely something that I'm doing wrong, so I wanted to ask you:
KalmanReconsIMU
class in pythonThe text was updated successfully, but these errors were encountered: