# Tutorial 7: Getting Sensors Data
This tutorial shows how to use retrieve sensor data from ZED Mini and ZED2. It will loop until 100 data samples are grabbed, printing the updated values on console.<br/>
We assume that you have followed previous tutorials.
## Prerequisites
- Windows 10, Ubuntu LTS, L4T
- [ZED SDK](https://www.stereolabs.com/developers/) and its dependencies ([CUDA](https://developer.nvidia.com/cuda-downloads))
- [ZED SDK Python API](https://www.stereolabs.com/docs/app-development/python/install/)
## Code overview
### Create a ZED camera object
```python
# Create a Camera object
zed = sl.Camera()
init_params = sl.InitParameters()
init_params.depth_mode = sl.DEPTH_MODE.NONE
# Open the camera
err = zed.open(init_params)
if err != sl.ERROR_CODE.SUCCESS :
print(repr(err))
zed.close()
exit(1)
```
### Device Informations
We first display some informations about the sensors
```python
# Display camera information (model,S/N, fw version)
print("Camera Model: " + str(cam_model))
print("Serial Number: " + str(info.serial_number))
print("Camera Firmware: " + str(info.camera_configuration.firmware_version))
print("Sensors Firmware: " + str(info.sensors_configuration.firmware_version))
# Display sensors parameters (imu,barometer,magnetometer)
printSensorParameters(info.sensors_configuration.accelerometer_parameters) # accelerometer configuration
printSensorParameters(info.sensors_configuration.gyroscope_parameters) # gyroscope configuration
printSensorParameters(info.sensors_configuration.magnetometer_parameters) # magnetometer configuration
printSensorParameters(info.sensors_configuration.barometer_parameters) # barometer configuration
```
### Capture data
The sensor data can be retrieved in two ways: synchronized or not synchronized to the image frames<br/>
In this tutorial, we grab 100 not synchronized data
```python
# Used to store the sensors timestamp to know if the sensors_data is a new one or not
ts_handler = TimestampHandler()
# Get Sensor Data for 5 seconds
i = 0
sensors_data = sl.SensorsData()
while i < 100 :
# retrieve the current sensors sensors_data
# Depending on your Camera model or its firmware, differents sensors are presents.
# They do not run at the same rate: Therefore, to do not miss samples we iterate as fast as we can and compare timestamp to know when a sensors_data is a new one
# NOTE: There is no need to acquire images with grab() function. Sensors sensors_data are running in a separated internal capture thread.
if zed.get_sensors_data(sensors_data, sl.TIME_REFERENCE.CURRENT) == sl.ERROR_CODE.SUCCESS :
[...]
```
### Process data
To be sure that data are updated, since they are not synchronized to camera frames, we must check that the
timestamp as changed from the previous retrieved values. We use the timestamp of the IMU sensor as main value
since it's the sensor that runs at higher frequency. We defined a small utility class that will handle this. <br/>
```python
# Check if the data has been updated since the last time
# IMU is the sensor with the highest rate
if ts_handler.is_new(sensors_data.get_imu_data()):
```
If the data are updated we can extract and use them:
```python
print(" - IMU:")
# Filtered orientation quaternion
quaternion = sensors_data.get_imu_data().get_pose().get_orientation().get()
print(" \t Orientation: [ Ox: {0}, Oy: {1}, Oz {2}, Ow: {3} ]".format(quaternion[0], quaternion[1], quaternion[2], quaternion[3]))
# linear acceleration
linear_acceleration = sensors_data.get_imu_data().get_linear_acceleration()
print(" \t Acceleration: [ {0} {1} {2} ] [m/sec^2]".format(linear_acceleration[0], linear_acceleration[1], linear_acceleration[2]))
# angular velocities
angular_velocity = sensors_data.get_imu_data().get_angular_velocity()
print(" \t Angular Velocities: [ {0} {1} {2} ] [deg/sec]".format(angular_velocity[0], angular_velocity[1], angular_velocity[2]))
# Check if Magnetometer data has been updated (not the same frequency than IMU)
if ts_handler.is_new(sensors_data.get_magnetometer_data()):
magnetic_field_calibrated = sensors_data.get_magnetometer_data().get_magnetic_field_calibrated()
print(" - Magnetometer\n \t Magnetic Field: [ {0} {1} {2} ] [uT]".format(magnetic_field_calibrated[0], magnetic_field_calibrated[1], magnetic_field_calibrated[2]))
# Check if Barometer data has been updated
if ts_handler.is_new(sensors_data.get_barometer_data()):
magnetic_field_calibrated = sensors_data.get_barometer_data().pressure
print(" - Barometer\n \t Atmospheric pressure: {0} [hPa]".format(sensors_data.get_barometer_data().pressure))
```
If we are using a ZED2 we have more sensor data to be acquired.
IMU:
```python
# Filtered orientation quaternion
quaternion = sensors_data.get_imu_data().get_pose().get_orientation().get()
print(" \t Orientation: [ Ox: {0}, Oy: {1}, Oz {2}, Ow: {3} ]".format(quaternion[0], quaternion[1], quaternion[2], quaternion[3]))
# linear acceleration
linear_acceleration = sensors_data.get_imu_data().get_linear_acceleration()
print(" \t Acceleration: [ {0} {1} {2} ] [m/sec^2]".format(linear_acceleration[0], linear_acceleration[1], linear_acceleration[2]))
# angular velocities
angular_velocity = sensors_data.get_imu_data().get_angular_velocity()
print(" \t Angular Velocities: [ {0} {1} {2} ] [deg/sec]".format(angular_velocity[0], angular_velocity[1], angular_velocity[2]))
```
Magnetic fields:
```python
# Check if Magnetometer data has been updated (not the same frequency than IMU)
if ts_handler.is_new(sensors_data.get_magnetometer_data()):
magnetic_field_calibrated = sensors_data.get_magnetometer_data().get_magnetic_field_calibrated()
print(" - Magnetometer\n \t Magnetic Field: [ {0} {1} {2} ] [uT]".format(magnetic_field_calibrated[0], magnetic_field_calibrated[1], magnetic_field_calibrated[2]))
```
Barometer data:
```python
# Check if Barometer data has been updated
if ts_handler.is_new(sensors_data.get_barometer_data()):
magnetic_field_calibrated = sensors_data.get_barometer_data().pressure
print(" - Barometer\n \t Atmospheric pressure: {0} [hPa]".format(sensors_data.get_barometer_data().pressure))
```
### Close camera and exit
Once the data are extracted, don't forget to close the camera before exiting the program.<br/>
```python
# Close camera
zed.close()
return 0
```
And this is it!<br/>
You can now get all the sensor data from ZED-M and ZED2 cameras.
没有合适的资源?快使用搜索试试~ 我知道了~
zed相机官方例程,zed-example
共435个文件
md:98个
cs:73个
txt:58个
需积分: 14 11 下载量 142 浏览量
2023-04-07
12:02:45
上传
评论 1
收藏 3.01MB ZIP 举报
温馨提示
zed相机的功能实现的官方例程,含python、c++、c#代码,帮助那些打不开官网的兄弟们!1个积分意思意思哈哈,真心想要的私聊看到就会发给你。
资源推荐
资源详情
资源评论
收起资源包目录
zed相机官方例程,zed-example (435个子文件)
main.c 5KB
main.c 5KB
main.c 5KB
main.c 5KB
main.c 5KB
main.c 4KB
main.c 3KB
main.c 2KB
yolov4.cfg 12KB
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
App.config 180B
packages.config 150B
packages.config 149B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 148B
packages.config 147B
packages.config 147B
GLViewer.cpp 37KB
GLViewer.cpp 34KB
GLViewer.cpp 34KB
GLViewer.cpp 34KB
GLViewer.cpp 32KB
GLViewer.cpp 31KB
yolov5.cpp 26KB
yolov5.cpp 26KB
GLViewer.cpp 23KB
GLViewer.cpp 21KB
GLViewer.cpp 21KB
TrackingViewer.cpp 20KB
GLViewer.cpp 19KB
GLViewer.cpp 19KB
main.cpp 14KB
main.cpp 13KB
main.cpp 11KB
main.cpp 10KB
BatchSystemHandler.cpp 10KB
main.cpp 10KB
main.cpp 9KB
main.cpp 9KB
main.cpp 9KB
main.cpp 9KB
main.cpp 9KB
main.cpp 7KB
main.cpp 7KB
main.cpp 7KB
main.cpp 7KB
main.cpp 6KB
main.cpp 6KB
main.cpp 5KB
main.cpp 5KB
main.cpp 5KB
main.cpp 5KB
main.cpp 5KB
main.cpp 4KB
main.cpp 4KB
TrackingViewer.cpp 3KB
main.cpp 3KB
calibrator.cpp 3KB
calibrator.cpp 3KB
main.cpp 2KB
main.cpp 2KB
ZEDModel.cs 81KB
GLViewer.cs 58KB
GLViewer.cs 47KB
GLViewer.cs 44KB
GLViewer.cs 43KB
GLViewer.cs 38KB
GLViewer.cs 28KB
TrackingViewer.cs 22KB
GLViewer.cs 19KB
共 435 条
- 1
- 2
- 3
- 4
- 5
资源评论
小帅爱智能
- 粉丝: 259
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- alu.v
- H21-282学习参考.pdf
- QuestionTwo.java
- QuestionOne.java
- AWS Certified Solutions Architect Study Guide -SAA-C03 .docx
- 校园小情书微信小程序源码 社区小程序前后端开源 校园表白墙交友小程序.rar
- OA办公自动化管理系统(Struts1.2+Hibernate3.0+Spring2+DWR).rar
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 简历-求职简历-word-文件-简历模版免费分享-应届生-高颜值简历模版-个人简历模版-简约大气-大学生在校生-求职-实习
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功