姿态和航向参考系统。
AHRS的Python项目详细描述
AHRS:姿态和航向参考系统
ahrs是一个用python编写的函数和对象的动物园,帮助您估计机器人系统的方向和位置。
最初,一个AHRS被定义为一组正交传感器,提供飞机的姿态信息。这一领域现在正扩展到更小的设备,如可穿戴设备、自动化运输和各种移动机器人。
模块ahrs的开发重点是快速原型和简单的模块化。
ahrs与python 3.6及以上版本兼容。
安装
ahrs可以使用pip:
pip install ahrs
或者使用存储库中的最新版本:
git clone https://github.com/Mayitzin/ahrs.git
cd ahrs
python setup.py install
ahrs依赖于最分布式的python包。如果你没有,他们将自动下载和安装。
使用AHRS
例如,要使用方向,我们可以使用orientation
模块。
>>>importahrs>>># Rotation matrix of 30.0 degrees around X-axis...ahrs.common.orientation.rotation('x',30.0)array([[1.,0.,0.],[0.,0.8660254,-0.5],[0.,0.5,0.8660254]])>>># Rotation sequence of the form: R_y(10.0)@R_x(20.0)@R_z(30.0)...ahrs.common.orientation.rot_seq('yXy',[10.0,20.0,30.0])array([[0.77128058,0.05939117,0.63371836],[0.17101007,0.93969262,-0.29619813],[-0.61309202,0.33682409,0.71461018]])
它也能很好地处理四元数。
>>>importnumpyasnp>>>q=np.random.random(4)>>># It automatically normalizes any given vector...ahrs.common.orientation.q2R(q)array([[0.76811067,0.3546719,0.53311709],[0.55044928,0.05960693,-0.83273802],[-0.32712625,0.93308888,-0.14944417]])
ahrs
还包括一个简化数据加载和可视化的模块
>>>data=ahrs.utils.io.load("ExampleData.mat")>>>ahrs.utils.plot_sensors(data.gyr,data.acc,data.mag)
如果要使用传感器数据来估计姿态,请使用filters
模块,该模块包含各种(更多)算法。
>>>madgwick=ahrs.filters.Madgwick()>>>Q=np.tile([1.,0.,0.,0.],(data.num_samples,1))# Allocate an array for all quaternions>>>d2g=ahrs.common.DEG2RAD# Constant to convert degrees to radians>>>fortinrange(1,data.num_samples):...Q[t]=madgwick.updateMARG(d2g*data.gyr[t],data.acc[t],data.mag[t],Q[t-1])...>>>ahrs.utils.plot_quaternions(Q)
文档
一个全面的文档和示例将很快出现在Read the Docs。