Compare commits
56 Commits
Author | SHA1 | Date |
---|---|---|
那个Zeng | ea323b879f | 3 years ago |
那个Zeng | 5a73c704b4 | 3 years ago |
NageZeng | 1000eeb66e | 3 years ago |
那个Zeng | c5c62eb4cf | 3 years ago |
那个Zeng | 8dba3972fa | 3 years ago |
NageZeng | caf954570e | 3 years ago |
那个Zeng | 5262b4c097 | 3 years ago |
那个Zeng | 9a3c323fcc | 3 years ago |
NageZeng | ed0e799cab | 3 years ago |
那个Zeng | 63344b04ca | 3 years ago |
那个Zeng | 4454121ebc | 3 years ago |
那个Zeng | b306a1dfa5 | 3 years ago |
那个Zeng | 0b62a6339f | 3 years ago |
那个Zeng | d3a241928d | 3 years ago |
那个Zeng | 055f3563e4 | 3 years ago |
那个Zeng | 200d4b33dd | 3 years ago |
那个Zeng | bdf33f23e3 | 3 years ago |
那个Zeng | 724a0dc9ed | 3 years ago |
honglang | 55374fe589 | 3 years ago |
Daniel Agar | 2e8918da66 | 3 years ago |
Daniel Agar | 5def17b1af | 3 years ago |
Daniel Agar | 1daf0654ff | 3 years ago |
Daniel Agar | 6e3a2314cb | 3 years ago |
Sander Swart | 6121b287f1 | 3 years ago |
Sander Swart | c0980bd273 | 3 years ago |
Sander Swart | 42d14e6072 | 3 years ago |
Daniel Agar | ba0b512f0d | 3 years ago |
Daniel Agar | 7476a2953e | 3 years ago |
Lorenz Meier | 15e6ca9e1e | 3 years ago |
Daniel Agar | b9e7063237 | 3 years ago |
Daniel Agar | 0a6045367f | 3 years ago |
Daniel Agar | 3f88a6d0bf | 3 years ago |
Jukka Laitinen | d1c09ec358 | 3 years ago |
Daniel Agar | ca744626cd | 3 years ago |
Daniel Agar | ea577f15b9 | 3 years ago |
Daniel Agar | d9f3c820ab | 4 years ago |
David Sidrane | 8e57a62c9d | 4 years ago |
David Sidrane | b961f6a1e1 | 4 years ago |
David Sidrane | 09140c01bf | 4 years ago |
David Sidrane | 822ae46235 | 4 years ago |
David Sidrane | f70381dfdd | 4 years ago |
David Sidrane | 84066f574d | 4 years ago |
David Sidrane | c8426da50d | 4 years ago |
David Sidrane | 6bab917a3d | 4 years ago |
David Sidrane | 531301e176 | 4 years ago |
David Sidrane | 04f4157828 | 4 years ago |
Daniel Agar | c5f82ed838 | 4 years ago |
Daniel Agar | 99501b4c38 | 4 years ago |
Daniel Agar | 9e4a04f58a | 4 years ago |
Daniel Agar | 1682fd5671 | 4 years ago |
bresch | a8572f0fdd | 4 years ago |
Daniel Agar | a299a3bbd0 | 4 years ago |
Julian Oes | 349dd63072 | 4 years ago |
David Sidrane | 6b51c6390a | 4 years ago |
David Sidrane | 4f7909ee8e | 4 years ago |
David Sidrane | cbb48f9af3 | 4 years ago |
76 changed files with 1948 additions and 318 deletions
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
Subproject commit 483193d9b8b89211c3b970c735b4fbb5f724b63a |
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
date -R |
||||
starttime=`date +'%Y-%m-%d %H:%M:%S'` |
||||
make px4_fmu-v3_default upload |
||||
endtime=`date +'%Y-%m-%d %H:%M:%S'` |
||||
date -R |
||||
start_seconds=$(date --date="$starttime" +%s); |
||||
end_seconds=$(date --date="$endtime" +%s); |
||||
echo "本次运行时间: "$((end_seconds-start_seconds))"s" |
||||
cp ./build/px4_fmu-v3_default/px4_fmu-v3_default.px4 /mnt/f/_02-work/100_data/Firmware/px4/px4_fmu-v3_tfiic-12.px4 |
@ -1 +1 @@
@@ -1 +1 @@
|
||||
Subproject commit 76bb42f3ebd902102e844084b564274bf215ec9f |
||||
Subproject commit bf660cba2af81f055002b3817c87b1f63a78fd09 |
@ -1,7 +1,27 @@
@@ -1,7 +1,27 @@
|
||||
module_name: Benewake TFmini Rangefinder |
||||
serial_config: |
||||
- command: tfmini start -d ${SERIAL_DEV} |
||||
- command: tfmini start -d ${SERIAL_DEV} -R SENS_TF_SER_ROT |
||||
port_config_param: |
||||
name: SENS_TFMINI_CFG |
||||
group: Sensors |
||||
|
||||
|
||||
parameters: |
||||
- group: Sensors |
||||
definitions: |
||||
SENS_TF_S1_ROT: |
||||
description: |
||||
short: Distance Sensor Rotation |
||||
long: | |
||||
Distance Sensor Rotation as MAV_SENSOR_ORIENTATION enum |
||||
|
||||
type: enum |
||||
values: |
||||
25: ROTATION_DOWNWARD_FACING |
||||
24: ROTATION_UPWARD_FACING |
||||
12: ROTATION_BACKWARD_FACING |
||||
0: ROTATION_FORWARD_FACING |
||||
6: ROTATION_LEFT_FACING |
||||
2: ROTATION_RIGHT_FACING |
||||
reboot_required: true |
||||
default: 25 |
||||
|
@ -0,0 +1,85 @@
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* Copyright (c) 2017 PX4 Development Team. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* 3. Neither the name PX4 nor the names of its contributors may be |
||||
* used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
* POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
/**
|
||||
* Benewake TFmini Sensor 0 Rotation |
||||
* |
||||
* This parameter defines the rotation of the sensor relative to the platform. |
||||
* |
||||
* @reboot_required true |
||||
* @min 0 |
||||
* @max 25 |
||||
* @group Sensors |
||||
* |
||||
* @value 0 No rotation |
||||
* @value 1 Yaw 45° |
||||
* @value 2 Yaw 90° |
||||
* @value 3 Yaw 135° |
||||
* @value 4 Yaw 180° |
||||
* @value 5 Yaw 225° |
||||
* @value 6 Yaw 270° |
||||
* @value 7 Yaw 315° |
||||
* @value 0 ROTATION_FORWARD_FACING |
||||
* @value 2 ROTATION_RIGHT_FACING |
||||
* @value 4 ROTATION_BACKWARD_FACING |
||||
* @value 6 ROTATION_LEFT_FACING |
||||
* @value 24 ROTATION_UPWARD_FACING |
||||
* @value 25 ROTATION_DOWNWARD_FACING |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_S_ROT, 0); |
||||
|
||||
/**
|
||||
* Benewake TFmini Sensor S Max Distance |
||||
* |
||||
* This parameter defines maximum measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_S_MAXD, 1200); |
||||
|
||||
/**
|
||||
* Benewake TFmini Sensor S Min Distance |
||||
* |
||||
* This parameter defines min measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_S_MIND, 10); |
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
############################################################################ |
||||
# |
||||
# Copyright (c) 2015 PX4 Development Team. All rights reserved. |
||||
# |
||||
# Redistribution and use in source and binary forms, with or without |
||||
# modification, are permitted provided that the following conditions |
||||
# are met: |
||||
# |
||||
# 1. Redistributions of source code must retain the above copyright |
||||
# notice, this list of conditions and the following disclaimer. |
||||
# 2. Redistributions in binary form must reproduce the above copyright |
||||
# notice, this list of conditions and the following disclaimer in |
||||
# the documentation and/or other materials provided with the |
||||
# distribution. |
||||
# 3. Neither the name PX4 nor the names of its contributors may be |
||||
# used to endorse or promote products derived from this software |
||||
# without specific prior written permission. |
||||
# |
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
# POSSIBILITY OF SUCH DAMAGE. |
||||
# |
||||
############################################################################ |
||||
px4_add_module( |
||||
MODULE drivers__tfmini_i2c |
||||
MAIN tfmini_i2c |
||||
COMPILE_FLAGS |
||||
-Wno-cast-align # TODO: fix and enable |
||||
SRCS |
||||
tfmini_i2c.cpp |
||||
DEPENDS |
||||
drivers_rangefinder |
||||
) |
@ -0,0 +1,445 @@
@@ -0,0 +1,445 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* Copyright (c) 2017 PX4 Development Team. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* 3. Neither the name PX4 nor the names of its contributors may be |
||||
* used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
* POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
/**
|
||||
* Benewake TF Rangefinder Sonar (tf i2c) |
||||
* |
||||
* @reboot_required true |
||||
* |
||||
* @boolean |
||||
* @group Sensors |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_EN_TFI2C, 0); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 0 Address |
||||
* |
||||
* This parameter defines the address of the TFi2c sensor. |
||||
* |
||||
* @reboot_required true |
||||
* @min 1 |
||||
* @max 255 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
|
||||
PARAM_DEFINE_INT32(SENS_TF_0_ADDR, 16); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 0 Rotation |
||||
* |
||||
* This parameter defines the rotation of the sensor relative to the platform. |
||||
* |
||||
* @reboot_required true |
||||
* @min 0 |
||||
* @max 25 |
||||
* @group Sensors |
||||
* |
||||
* @value 0 No rotation |
||||
* @value 1 Yaw 45° |
||||
* @value 2 Yaw 90° |
||||
* @value 3 Yaw 135° |
||||
* @value 4 Yaw 180° |
||||
* @value 5 Yaw 225° |
||||
* @value 6 Yaw 270° |
||||
* @value 7 Yaw 315° |
||||
* @value 0 ROTATION_FORWARD_FACING |
||||
* @value 2 ROTATION_RIGHT_FACING |
||||
* @value 4 ROTATION_BACKWARD_FACING |
||||
* @value 6 ROTATION_LEFT_FACING |
||||
* @value 24 ROTATION_UPWARD_FACING |
||||
* @value 25 ROTATION_DOWNWARD_FACING |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_0_ROT, 0); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 0 Max Distance |
||||
* |
||||
* This parameter defines maximum measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_0_MAXD, 1200); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 0 Min Distance |
||||
* |
||||
* This parameter defines min measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_0_MIND, 10); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 1 Address |
||||
* |
||||
* This parameter defines the address of the TFi2c sensor. |
||||
* |
||||
* @reboot_required true |
||||
* @min 1 |
||||
* @max 255 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
|
||||
PARAM_DEFINE_INT32(SENS_TF_1_ADDR, 17); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 1 Rotation |
||||
* |
||||
* This parameter defines the rotation of the sensor relative to the platform. |
||||
* |
||||
* @reboot_required true |
||||
* @min 0 |
||||
* @max 25 |
||||
* @group Sensors |
||||
* |
||||
* @value 0 No rotation |
||||
* @value 1 Yaw 45° |
||||
* @value 2 Yaw 90° |
||||
* @value 3 Yaw 135° |
||||
* @value 4 Yaw 180° |
||||
* @value 5 Yaw 225° |
||||
* @value 6 Yaw 270° |
||||
* @value 7 Yaw 315° |
||||
* @value 0 ROTATION_FORWARD_FACING |
||||
* @value 2 ROTATION_RIGHT_FACING |
||||
* @value 4 ROTATION_BACKWARD_FACING |
||||
* @value 6 ROTATION_LEFT_FACING |
||||
* @value 24 ROTATION_UPWARD_FACING |
||||
* @value 25 ROTATION_DOWNWARD_FACING |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_1_ROT, 0); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 1 Max Distance |
||||
* |
||||
* This parameter defines maximum measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_1_MAXD, 1200); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 1 Min Distance |
||||
* |
||||
* This parameter defines min measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_1_MIND, 10); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 2 Address |
||||
* |
||||
* This parameter defines the address of the TFi2c sensor. |
||||
* |
||||
* @reboot_required true |
||||
* @min 1 |
||||
* @max 255 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
|
||||
PARAM_DEFINE_INT32(SENS_TF_2_ADDR, 18); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 2 Rotation |
||||
* |
||||
* This parameter defines the rotation of the sensor relative to the platform. |
||||
* |
||||
* @reboot_required true |
||||
* @min 0 |
||||
* @max 25 |
||||
* @group Sensors |
||||
* |
||||
* @value 0 No rotation |
||||
* @value 1 Yaw 45° |
||||
* @value 2 Yaw 90° |
||||
* @value 3 Yaw 135° |
||||
* @value 4 Yaw 180° |
||||
* @value 5 Yaw 225° |
||||
* @value 6 Yaw 270° |
||||
* @value 7 Yaw 315° |
||||
* @value 0 ROTATION_FORWARD_FACING |
||||
* @value 2 ROTATION_RIGHT_FACING |
||||
* @value 4 ROTATION_BACKWARD_FACING |
||||
* @value 6 ROTATION_LEFT_FACING |
||||
* @value 24 ROTATION_UPWARD_FACING |
||||
* @value 25 ROTATION_DOWNWARD_FACING |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_2_ROT, 0); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 2 Max Distance |
||||
* |
||||
* This parameter defines maximum measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_2_MAXD, 1200); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 2 Min Distance |
||||
* |
||||
* This parameter defines min measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_2_MIND, 10); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 3 Address |
||||
* |
||||
* This parameter defines the address of the TFi2c sensor. |
||||
* |
||||
* @reboot_required true |
||||
* @min 1 |
||||
* @max 255 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
|
||||
PARAM_DEFINE_INT32(SENS_TF_3_ADDR, 19); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 3 Rotation |
||||
* |
||||
* This parameter defines the rotation of the sensor relative to the platform. |
||||
* |
||||
* @reboot_required true |
||||
* @min 0 |
||||
* @max 25 |
||||
* @group Sensors |
||||
* |
||||
* @value 0 No rotation |
||||
* @value 1 Yaw 45° |
||||
* @value 2 Yaw 90° |
||||
* @value 3 Yaw 135° |
||||
* @value 4 Yaw 180° |
||||
* @value 5 Yaw 225° |
||||
* @value 6 Yaw 270° |
||||
* @value 7 Yaw 315° |
||||
* @value 0 ROTATION_FORWARD_FACING |
||||
* @value 2 ROTATION_RIGHT_FACING |
||||
* @value 4 ROTATION_BACKWARD_FACING |
||||
* @value 6 ROTATION_LEFT_FACING |
||||
* @value 24 ROTATION_UPWARD_FACING |
||||
* @value 25 ROTATION_DOWNWARD_FACING |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_3_ROT, 0); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 3 Max Distance |
||||
* |
||||
* This parameter defines maximum measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_3_MAXD, 1200); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 3 Min Distance |
||||
* |
||||
* This parameter defines min measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_3_MIND, 10); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 4 Address |
||||
* |
||||
* This parameter defines the address of the TFi2c sensor. |
||||
* |
||||
* @reboot_required true |
||||
* @min 1 |
||||
* @max 255 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
|
||||
PARAM_DEFINE_INT32(SENS_TF_4_ADDR, 20); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 4 Rotation |
||||
* |
||||
* This parameter defines the rotation of the sensor relative to the platform. |
||||
* |
||||
* @reboot_required true |
||||
* @min 0 |
||||
* @max 25 |
||||
* @group Sensors |
||||
* |
||||
* @value 0 No rotation |
||||
* @value 1 Yaw 45° |
||||
* @value 2 Yaw 90° |
||||
* @value 3 Yaw 135° |
||||
* @value 4 Yaw 180° |
||||
* @value 5 Yaw 225° |
||||
* @value 6 Yaw 270° |
||||
* @value 7 Yaw 315° |
||||
* @value 0 ROTATION_FORWARD_FACING |
||||
* @value 2 ROTATION_RIGHT_FACING |
||||
* @value 4 ROTATION_BACKWARD_FACING |
||||
* @value 6 ROTATION_LEFT_FACING |
||||
* @value 24 ROTATION_UPWARD_FACING |
||||
* @value 25 ROTATION_DOWNWARD_FACING |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_4_ROT, 0); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 4 Max Distance |
||||
* |
||||
* This parameter defines maximum measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_4_MAXD, 1200); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 4 Min Distance |
||||
* |
||||
* This parameter defines min measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_4_MIND, 10); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 5 Address |
||||
* |
||||
* This parameter defines the address of the TFi2c sensor. |
||||
* |
||||
* @reboot_required true |
||||
* @min 1 |
||||
* @max 255 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
|
||||
PARAM_DEFINE_INT32(SENS_TF_5_ADDR, 21); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 5 Rotation |
||||
* |
||||
* This parameter defines the rotation of the sensor relative to the platform. |
||||
* |
||||
* @reboot_required true |
||||
* @min 0 |
||||
* @max 25 |
||||
* @group Sensors |
||||
* |
||||
* @value 0 No rotation |
||||
* @value 1 Yaw 45° |
||||
* @value 2 Yaw 90° |
||||
* @value 3 Yaw 135° |
||||
* @value 4 Yaw 180° |
||||
* @value 5 Yaw 225° |
||||
* @value 6 Yaw 270° |
||||
* @value 7 Yaw 315° |
||||
* @value 0 ROTATION_FORWARD_FACING |
||||
* @value 2 ROTATION_RIGHT_FACING |
||||
* @value 4 ROTATION_BACKWARD_FACING |
||||
* @value 6 ROTATION_LEFT_FACING |
||||
* @value 24 ROTATION_UPWARD_FACING |
||||
* @value 25 ROTATION_DOWNWARD_FACING |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_5_ROT, 0); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 5 Max Distance |
||||
* |
||||
* This parameter defines maximum measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_5_MAXD, 1200); |
||||
|
||||
/**
|
||||
* Benewake TF Sensor 5 Min Distance |
||||
* |
||||
* This parameter defines min measuring distance. |
||||
* |
||||
* @reboot_required false |
||||
* @min 5 |
||||
* @max 20000 |
||||
* @group Sensors |
||||
* |
||||
*/ |
||||
PARAM_DEFINE_INT32(SENS_TF_5_MIND, 10); |
||||
|
@ -0,0 +1,686 @@
@@ -0,0 +1,686 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* Copyright (c) 2013-2015 PX4 Development Team. All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions |
||||
* are met: |
||||
* |
||||
* 1. Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* 2. Redistributions in binary form must reproduce the above copyright |
||||
* notice, this list of conditions and the following disclaimer in |
||||
* the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* 3. Neither the name PX4 nor the names of its contributors may be |
||||
* used to endorse or promote products derived from this software |
||||
* without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||
* POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
/**
|
||||
* @file tfmini_i2c.cpp |
||||
* @author Greg Hulands |
||||
* @author Jon Verbeke <jon.verbeke@kuleuven.be> |
||||
* |
||||
* Driver for the Maxbotix sonar range finders connected via I2C. |
||||
*/ |
||||
|
||||
#include <fcntl.h> |
||||
#include <math.h> |
||||
#include <poll.h> |
||||
#include <semaphore.h> |
||||
#include <stdbool.h> |
||||
#include <stdint.h> |
||||
#include <stdio.h> |
||||
#include <stdlib.h> |
||||
#include <string.h> |
||||
#include <sys/types.h> |
||||
#include <termios.h> |
||||
#include <unistd.h> |
||||
|
||||
#include <board_config.h> |
||||
#include <containers/Array.hpp> |
||||
#include <drivers/device/device.h> |
||||
#include <drivers/device/i2c.h> |
||||
#include <drivers/drv_hrt.h> |
||||
#include <perf/perf_counter.h> |
||||
#include <px4_platform_common/px4_config.h> |
||||
#include <px4_platform_common/getopt.h> |
||||
#include <px4_platform_common/module_params.h> |
||||
#include <px4_platform_common/module.h> |
||||
#include <px4_platform_common/i2c_spi_buses.h> |
||||
#include <uORB/uORB.h> |
||||
#include <uORB/topics/distance_sensor.h> |
||||
|
||||
#include <systemlib/mavlink_log.h> |
||||
using namespace time_literals; |
||||
|
||||
#define ARRAY_SIZE(_arr) (sizeof(_arr) / sizeof(_arr[0])) |
||||
|
||||
/* Configuration Constants */ |
||||
#define TFMINI_I2C_BASE_ADDR 0x10 // 7-bit address is 0x70 = 112. 8-bit address is 0xE0 = 224.
|
||||
#define TFMINI_I2C_MAX_ADDR 0x16 // 7-bit address is 0x5A = 90. 8-bit address is 0xB4 = 180.
|
||||
#define TFMINI_I2C_BUS_SPEED 100000 // 100kHz bus speed.
|
||||
|
||||
/* TF_I2Cxx Registers addresses */ |
||||
#define TFMINI_I2C_TAKE_RANGE_REG 0x51 // Measure range Register.
|
||||
#define TFMINI_I2C_SET_ADDRESS_1 0xAA // Change address 1 Register.
|
||||
#define TFMINI_I2C_SET_ADDRESS_2 0xA5 // Change address 2 Register.
|
||||
|
||||
/* Device limits */ |
||||
#define TFMINI_I2C_MIN_DISTANCE (0.10f) |
||||
#define TFMINI_I2C_MAX_DISTANCE (12.00f) |
||||
|
||||
#define TFMINI_I2C_MEASURE_INTERVAL 20_ms // 60ms minimum for one sonar.
|
||||
#define TFMINI_I2C_INTERVAL_BETWEEN_SUCCESIVE_FIRES 10_ms // 30ms minimum between each sonar measurement (watch out for interference!).
|
||||
|
||||
class TFMINI_I2C : public device::I2C, public ModuleParams, public I2CSPIDriver<TFMINI_I2C> |
||||
{ |
||||
public: |
||||
TFMINI_I2C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address); |
||||
virtual ~TFMINI_I2C(); |
||||
|
||||
static I2CSPIDriverBase *instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator, |
||||
int runtime_instance); |
||||
static void print_usage(); |
||||
|
||||
virtual int init() override; |
||||
|
||||
/**
|
||||
* Diagnostics - print some basic information about the driver. |
||||
*/ |
||||
void print_status() override; |
||||
|
||||
/**
|
||||
* Sets a new device address. |
||||
* @param address The new sensor address to be set: 200-224 even addresses only. |
||||
* @return Returns PX4_OK iff successful, PX4_ERROR otherwise. |
||||
*/ |
||||
int set_address(const uint8_t address = TFMINI_I2C_BASE_ADDR); |
||||
|
||||
/**
|
||||
* Initialise the automatic measurement state machine and start it. |
||||
* |
||||
* @note This function is called at open and error time. It might make sense |
||||
* to make it more aggressive about resetting the bus in case of errors. |
||||
*/ |
||||
void start(); |
||||
|
||||
/**
|
||||
* Perform a poll cycle; collect from the previous measurement |
||||
* and start a new one. |
||||
*/ |
||||
void RunImpl(); |
||||
|
||||
protected: |
||||
void custom_method(const BusCLIArguments &cli) override; |
||||
|
||||
private: |
||||
|
||||
/**
|
||||
* Collects the most recent sensor measurement data from the i2c bus. |
||||
*/ |
||||
int collect(); |
||||
|
||||
/**
|
||||
* Gets the current sensor rotation value. |
||||
*/ |
||||
int get_sensor_rotation(const size_t index); |
||||
|
||||
/**
|
||||
* Sends an i2c measure command to start the next sonar ping. |
||||
*/ |
||||
int measure(); |
||||
int tfi2c_transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len); |
||||
int check_checksum(uint8_t *arr, int pkt_len); |
||||
|
||||
int set_param(); |
||||
|
||||
static constexpr uint8_t RANGE_FINDER_MAX_SENSORS = 6; |
||||
px4::Array<uint8_t, RANGE_FINDER_MAX_SENSORS> _sensor_addresses {}; |
||||
px4::Array<uint8_t, RANGE_FINDER_MAX_SENSORS> _sensor_rotations {}; |
||||
|
||||
int _measure_interval{TFMINI_I2C_MEASURE_INTERVAL}; // Initialize the measure interval for a single sensor.
|
||||
|
||||
int _sensor_index{0}; // Initialize counter for cycling i2c adresses to zero.
|
||||
|
||||
int _sensor_count{0}; |
||||
|
||||
orb_advert_t _distance_sensor_topic{nullptr}; |
||||
|
||||
perf_counter_t _comms_error{perf_alloc(PC_ELAPSED, "tfmini_i2c_comms_error")}; |
||||
perf_counter_t _sample_perf{perf_alloc(PC_COUNT, "tfmini_i2c_sample_perf")}; |
||||
|
||||
uint8_t crc_clc; |
||||
struct max_min_dist |
||||
{ |
||||
int32_t max; |
||||
int32_t min; |
||||
}; |
||||
max_min_dist dist_range[6]; |
||||
DEFINE_PARAMETERS( |
||||
(ParamInt<px4::params::SENS_EN_TFI2C>) _p_sensor_enabled, |
||||
(ParamInt<px4::params::SENS_TF_0_ADDR>) _p_sensor0_addr, |
||||
(ParamInt<px4::params::SENS_TF_1_ADDR>) _p_sensor1_addr, |
||||
(ParamInt<px4::params::SENS_TF_2_ADDR>) _p_sensor2_addr, |
||||
(ParamInt<px4::params::SENS_TF_3_ADDR>) _p_sensor3_addr, |
||||
(ParamInt<px4::params::SENS_TF_4_ADDR>) _p_sensor4_addr, |
||||
(ParamInt<px4::params::SENS_TF_5_ADDR>) _p_sensor5_addr, |
||||
(ParamInt<px4::params::SENS_TF_0_ROT>) _p_sensor0_rot, |
||||
(ParamInt<px4::params::SENS_TF_1_ROT>) _p_sensor1_rot, |
||||
(ParamInt<px4::params::SENS_TF_2_ROT>) _p_sensor2_rot, |
||||
(ParamInt<px4::params::SENS_TF_3_ROT>) _p_sensor3_rot, |
||||
(ParamInt<px4::params::SENS_TF_4_ROT>) _p_sensor4_rot, |
||||
(ParamInt<px4::params::SENS_TF_5_ROT>) _p_sensor5_rot, |
||||
(ParamInt<px4::params::SENS_TF_0_MAXD>) _p_tf_0_max_dist, |
||||
(ParamInt<px4::params::SENS_TF_1_MAXD>) _p_tf_1_max_dist, |
||||
(ParamInt<px4::params::SENS_TF_2_MAXD>) _p_tf_2_max_dist, |
||||
(ParamInt<px4::params::SENS_TF_3_MAXD>) _p_tf_3_max_dist, |
||||
(ParamInt<px4::params::SENS_TF_4_MAXD>) _p_tf_4_max_dist, |
||||
(ParamInt<px4::params::SENS_TF_5_MAXD>) _p_tf_5_max_dist, |
||||
(ParamInt<px4::params::SENS_TF_0_MIND>) _p_tf_0_min_dist, |
||||
(ParamInt<px4::params::SENS_TF_1_MIND>) _p_tf_1_min_dist, |
||||
(ParamInt<px4::params::SENS_TF_2_MIND>) _p_tf_2_min_dist, |
||||
(ParamInt<px4::params::SENS_TF_3_MIND>) _p_tf_3_min_dist, |
||||
(ParamInt<px4::params::SENS_TF_4_MIND>) _p_tf_4_min_dist, |
||||
(ParamInt<px4::params::SENS_TF_5_MIND>) _p_tf_5_min_dist, |
||||
(ParamFloat<px4::params::CP_DIST>) _p_cp_dist, |
||||
(ParamInt<px4::params::MPC_POS_MODE>) _param_mpc_pos_mode |
||||
|
||||
); |
||||
orb_advert_t _mavlink_log_pub{nullptr}; ///< mavlink log pub
|
||||
float avoid_distance; |
||||
int entra_avoid_area{0}; |
||||
uint8_t get_a_data; |
||||
}; |
||||
|
||||
TFMINI_I2C::TFMINI_I2C(I2CSPIBusOption bus_option, const int bus, int bus_frequency, int address) : |
||||
I2C(DRV_DIST_DEVTYPE_TFMINI_I2C, MODULE_NAME, bus, address, bus_frequency), |
||||
ModuleParams(nullptr), |
||||
I2CSPIDriver(MODULE_NAME, px4::device_bus_to_wq(get_device_id()), bus_option, bus, address) |
||||
{ |
||||
set_device_type(DRV_DIST_DEVTYPE_TFMINI_I2C); |
||||
} |
||||
|
||||
TFMINI_I2C::~TFMINI_I2C() |
||||
{ |
||||
// Unadvertise the distance sensor topic.
|
||||
if (_distance_sensor_topic != nullptr) { |
||||
orb_unadvertise(_distance_sensor_topic); |
||||
} |
||||
|
||||
// Free perf counters.
|
||||
perf_free(_comms_error); |
||||
perf_free(_sample_perf); |
||||
} |
||||
|
||||
int |
||||
TFMINI_I2C::init() |
||||
{ |
||||
if (_p_sensor_enabled.get() == 0) { |
||||
PX4_WARN("disabled"); |
||||
return PX4_ERROR; |
||||
} |
||||
|
||||
// Initialize the I2C device
|
||||
if (I2C::init() != OK) { |
||||
return PX4_ERROR; |
||||
} |
||||
printf("\n--------------------\n"); |
||||
const uint8_t param_total_addr[6] = { (uint8_t)_p_sensor0_addr.get(), (uint8_t)_p_sensor1_addr.get(), (uint8_t)_p_sensor2_addr.get(), \
|
||||
(uint8_t)_p_sensor3_addr.get(),(uint8_t)_p_sensor4_addr.get(),(uint8_t)_p_sensor5_addr.get() }; |
||||
const uint8_t param_total_rot[6] = { (uint8_t)_p_sensor0_rot.get(), (uint8_t)_p_sensor1_rot.get(), (uint8_t)_p_sensor2_rot.get(), \
|
||||
(uint8_t)_p_sensor3_rot.get(),(uint8_t)_p_sensor4_rot.get(),(uint8_t)_p_sensor5_rot.get() }; |
||||
// Check for connected rangefinders on each i2c port by decrementing from the base address,
|
||||
// (TFMINI_I2C_BASE_ADDR = 112, TFMINI_I2C_MAX_ADDR = 90).
|
||||
uint8_t address; |
||||
for (uint8_t index = 0; index < RANGE_FINDER_MAX_SENSORS ; index++) { |
||||
address = param_total_addr[index]; |
||||
set_device_address(address); |
||||
px4_usleep(_measure_interval); |
||||
if (measure() == PX4_OK) { |
||||
px4_usleep(_measure_interval); |
||||
// Store I2C address
|
||||
_sensor_addresses[_sensor_count] = address; |
||||
_sensor_rotations[_sensor_count] = param_total_rot[index]; |
||||
_sensor_count++; |
||||
int set_ret = set_param(); |
||||
printf("tf[%i]: address 0x%02X ,rototion %d, set param:%d\n", _sensor_count, get_device_address(),_sensor_rotations[_sensor_count],set_ret); |
||||
mavlink_log_info(&_mavlink_log_pub, "sensor %i at address 0x%02X ,rotation:%d", _sensor_count, get_device_address(),_sensor_rotations[_sensor_count]); |
||||
if (_sensor_count >= RANGE_FINDER_MAX_SENSORS) { |
||||
break; |
||||
} |
||||
}else{ |
||||
|
||||
printf("\nerr tf[%d]:address:%02x",_sensor_count,address); |
||||
} |
||||
px4_usleep(_measure_interval); |
||||
} |
||||
printf("\n--------------------\n"); |
||||
|
||||
// if(avoid_dist > 0.5f){
|
||||
|
||||
|
||||
// _p_cp_dist.set(avoid_dist);
|
||||
// _param_mpc_pos_mode.set(avoid_mode);
|
||||
// printf("set avoid distance:%.2fm,mode:%d",(double)avoid_dist,avoid_mode);
|
||||
avoid_distance = _p_cp_dist.get(); |
||||
printf("get avoid distance:%.2fm,mode:%d\n",(double)avoid_distance,(uint8_t)_param_mpc_pos_mode.get()); |
||||
// }
|
||||
|
||||
dist_range[0].max = _p_tf_0_max_dist.get(); |
||||
dist_range[1].max = _p_tf_1_max_dist.get(); |
||||
dist_range[2].max = _p_tf_2_max_dist.get(); |
||||
dist_range[3].max = _p_tf_3_max_dist.get(); |
||||
dist_range[4].max = _p_tf_4_max_dist.get(); |
||||
dist_range[5].max = _p_tf_5_max_dist.get(); |
||||
dist_range[0].min = _p_tf_0_min_dist.get(); |
||||
dist_range[1].min = _p_tf_1_min_dist.get(); |
||||
dist_range[2].min = _p_tf_2_min_dist.get(); |
||||
dist_range[3].min = _p_tf_3_min_dist.get(); |
||||
dist_range[4].min = _p_tf_4_min_dist.get(); |
||||
dist_range[5].min = _p_tf_5_min_dist.get(); |
||||
|
||||
get_a_data = 0; |
||||
// Return an error if no sensors were detected.
|
||||
if (_sensor_count == 0) { |
||||
PX4_ERR("no sensors discovered"); |
||||
return PX4_ERROR; |
||||
} |
||||
|
||||
// If more than one sonar is detected, adjust the meaure interval to avoid sensor interference.
|
||||
if (_sensor_count > 1) { |
||||
_measure_interval = TFMINI_I2C_INTERVAL_BETWEEN_SUCCESIVE_FIRES; |
||||
} |
||||
|
||||
PX4_INFO("Total sensors connected: %i", _sensor_count); |
||||
return PX4_OK; |
||||
} |
||||
int |
||||
TFMINI_I2C::set_param() |
||||
{ |
||||
int ret; |
||||
|
||||
// const uint8_t CMD_SYSTEM_RESET[] = { 0x5A , 0x05 , 0x0B , 0x20 , 0x8a }; // 修改地址
|
||||
// const uint8_t CMD_OUTPUT_FORMAT_CM[] = { 0x5A, 0x04, 0x11, 0x6F }; // 保存配置
|
||||
const uint8_t CMD_SYSTEM_RESET[] = { 0x5A, 0x04, 0x04, 0x62 }; |
||||
const uint8_t CMD_OUTPUT_FORMAT_CM[] = { 0x5A, 0x05, 0x05, 0x01, 0x65 }; |
||||
const uint8_t CMD_ENABLE_DATA_OUTPUT[] = { 0x5A, 0x05, 0x07, 0x01, 0x67 }; |
||||
const uint8_t CMD_FRAME_RATE_100HZ[] = { 0x5A, 0x06, 0x03, 0x64, 0x00, 0xC7 }; |
||||
const uint8_t CMD_SAVE_SETTINGS[] = { 0x5A, 0x04, 0x11, 0x6F }; |
||||
const uint8_t *cmds[] = { |
||||
CMD_OUTPUT_FORMAT_CM, |
||||
CMD_FRAME_RATE_100HZ, |
||||
CMD_ENABLE_DATA_OUTPUT, |
||||
CMD_SAVE_SETTINGS, |
||||
}; |
||||
for (uint8_t i = 0; i < ARRAY_SIZE(cmds); i++) { |
||||
ret = tfi2c_transfer(cmds[i], cmds[i][1], nullptr, 0); |
||||
if (!ret) { |
||||
PX4_INFO(": Unable to set configuration register %u\n",cmds[i][2]); |
||||
return ret; |
||||
} |
||||
px4_usleep(100_ms); |
||||
} |
||||
tfi2c_transfer(CMD_SYSTEM_RESET, sizeof(CMD_SYSTEM_RESET), nullptr, 0); |
||||
|
||||
return PX4_OK; |
||||
} |
||||
int |
||||
TFMINI_I2C::measure() |
||||
{ |
||||
// Send the command to take a measurement.
|
||||
// const uint8_t CMD_FW_VERSION[] = { 0x5A, 0x04, 0x01, 0x5F };
|
||||
// const uint8_t CMD_FW_VERSION[] = { 0x5A, 0x04, 0x01, 0x5F };
|
||||
const uint8_t CMD_READ_MEASUREMENT[] = {0x5A,0x05,0x00,0x01,0x60 }; |
||||
|
||||
// uint8_t cmd = TFMINI_I2C_TAKE_RANGE_REG;
|
||||
int ret_val = transfer(CMD_READ_MEASUREMENT, 5, nullptr, 0); |
||||
|
||||
return ret_val; |
||||
} |
||||
|
||||
int |
||||
TFMINI_I2C::collect() |
||||
{ |
||||
|
||||
uint16_t distance = 0; |
||||
// uint16_t strength;
|
||||
// uint32_t timestamp;
|
||||
static uint32_t err_cnt; |
||||
const uint8_t Data_Len = 11; |
||||
static uint64_t last_us ; |
||||
perf_begin(_sample_perf); |
||||
|
||||
static uint8_t raw_data[Data_Len]; |
||||
|
||||
// Increment i2c adress to next sensor.
|
||||
_sensor_index++; |
||||
_sensor_index %= _sensor_count; |
||||
|
||||
// Set the sensor i2c adress for the active cycle.
|
||||
set_device_address(_sensor_addresses[_sensor_index]); |
||||
|
||||
// Transfer data from the bus.
|
||||
// int ret_val = transfer(CMD_READ_MEASUREMENT, 5, raw_data, 11);
|
||||
int ret_val; |
||||
if (1) |
||||
{ |
||||
uint8_t CMD_READ_MEASUREMENT[] = { 0x5A, 0x05, 0x00, 0x07, 0x66 }; |
||||
ret_val = tfi2c_transfer(CMD_READ_MEASUREMENT, 5, raw_data, Data_Len); |
||||
}else |
||||
{ |
||||
ret_val = tfi2c_transfer(nullptr, 0, raw_data, Data_Len); |
||||
} |
||||
|
||||
|
||||
if (ret_val < 0) { |
||||
// PX4_ERR("sensor %i read failed, address: 0x%02X", _sensor_index, get_device_address());
|
||||
perf_count(_comms_error); |
||||
perf_end(_sample_perf); |
||||
// if (measure() != PX4_OK) {
|
||||
// PX4_INFO("sensor %i measurement error, address 0x%02X", _sensor_index, get_device_address());
|
||||
// perf_count(_comms_error);
|
||||
// perf_end(_sample_perf);
|
||||
// return ret_val;
|
||||
// }
|
||||
return ret_val; |
||||
} |
||||
/////////////////////
|
||||
|
||||
/**
|
||||
* |
||||
uint8_t header1; |
||||
uint8_t header2; |
||||
le16_t distance; |
||||
le16_t strength; |
||||
le32_t timestamp; |
||||
uint8_t checksum; |
||||
*/ |
||||
if(raw_data[0] == 0x59 && raw_data[1] == 0x59) |
||||
{ |
||||
if(check_checksum(raw_data,Data_Len)){ |
||||
distance = ((uint16_t)raw_data[3] << 8) | raw_data[2]; |
||||
// strength = ((uint16_t)raw_data[5] << 8) | raw_data[4];
|
||||
// timestamp = ((uint32_t)raw_data[9] << 8) | ((uint32_t)raw_data[8] << 8) | ((uint32_t)raw_data[7] << 8) | raw_data[6];
|
||||
} |
||||
|
||||
}else{ |
||||
err_cnt += 1; |
||||
if(hrt_absolute_time() - last_us > 2 * 1_s){ |
||||
printf("{%d}err arr\n",__LINE__); |
||||
for (size_t i = 0; i < Data_Len; i++) |
||||
{ |
||||
printf("%02x ",raw_data[i]); |
||||
} |
||||
printf("\n"); |
||||
|
||||
printf("{%d}errcnt:%d, head %02x,%02x,crc: %02x ,clc:%02x\n",__LINE__,err_cnt,raw_data[0],raw_data[1],raw_data[Data_Len - 1],crc_clc); |
||||
last_us = hrt_absolute_time(); |
||||
err_cnt = 0; |
||||
} |
||||
// return -EAGAIN;
|
||||
} |
||||
///////////////////////
|
||||
uint16_t distance_cm = distance; |
||||
if (distance_cm > dist_range[_sensor_index].max || distance_cm < dist_range[_sensor_index].min ) // 超出距离范围
|
||||
{ |
||||
distance_cm = dist_range[_sensor_index].max ; |
||||
} |
||||
|
||||
float distance_m = static_cast<float>(distance_cm) * 1e-2f; |
||||
|
||||
distance_sensor_s report; |
||||
report.current_distance = distance_m; |
||||
report.device_id = get_device_id(); |
||||
report.max_distance = dist_range[_sensor_index].max / 100.0f; |
||||
report.min_distance = dist_range[_sensor_index].min / 100.0f; |
||||
report.orientation = _sensor_rotations[_sensor_index]; |
||||
report.signal_quality = -1; |
||||
report.timestamp = hrt_absolute_time(); |
||||
report.type = distance_sensor_s::MAV_DISTANCE_SENSOR_LASER; |
||||
report.variance = 0.0f; |
||||
report.h_fov = math::radians(1.15f); |
||||
report.v_fov = math::radians(1.15f); |
||||
|
||||
int instance_id; |
||||
orb_publish_auto(ORB_ID(distance_sensor), &_distance_sensor_topic, &report, &instance_id); |
||||
if (!get_a_data) |
||||
{ |
||||
get_a_data = 1; |
||||
} |
||||
|
||||
// Begin the next measurement.
|
||||
// if (measure() != PX4_OK) {
|
||||
// PX4_INFO("sensor %i measurement error, address 0x%02X", _sensor_index, get_device_address());
|
||||
// perf_count(_comms_error);
|
||||
// perf_end(_sample_perf);
|
||||
// return ret_val;
|
||||
// }
|
||||
// if(avoid_distance - distance_m > 0.1f && !entra_avoid_area){
|
||||
// mavlink_log_info(&_mavlink_log_pub, "(%d)Enter obstacle avoidance range : %.2f\n",_sensor_index,(double)distance_m);
|
||||
// printf("(%d)Enter obstacle avoidance range : %.2f\n",_sensor_index,(double)distance_m);
|
||||
// entra_avoid_area = 1;
|
||||
// }else if(distance_m - avoid_distance > 0.1f && entra_avoid_area){
|
||||
// entra_avoid_area = 0;
|
||||
// printf("(%d)Out obstacle avoidance range : %.2f\n",_sensor_index,(double)distance_m);
|
||||
|
||||
// }
|
||||
|
||||
// static double dist_arr[6]={0.01,0.01,0.01,0.01,0.01,0.01};
|
||||
// dist_arr[_sensor_index] = (double)distance_m;
|
||||
// if(hrt_absolute_time() - last_us > 100 * 1_ms){
|
||||
// printf("dist:%.2f,%.2f,%.2f,%.2f,%.2f,%.2f\n",dist_arr[0],dist_arr[1],dist_arr[2],dist_arr[3],dist_arr[4],dist_arr[5]);
|
||||
// last_us = hrt_absolute_time();
|
||||
// }
|
||||
|
||||
perf_end(_sample_perf); |
||||
return PX4_OK; |
||||
} |
||||
|
||||
|
||||
int |
||||
TFMINI_I2C::check_checksum(uint8_t *arr, int pkt_len) |
||||
{ |
||||
uint8_t checksum = 0; |
||||
int i; |
||||
|
||||
/* sum them all except the last (the checksum) */ |
||||
for (i = 0; i < pkt_len - 1; i++) { |
||||
checksum += arr[i]; |
||||
} |
||||
crc_clc = checksum; |
||||
return checksum == arr[pkt_len - 1]; |
||||
} |
||||
|
||||
int |
||||
TFMINI_I2C::get_sensor_rotation(const size_t index) |
||||
{ |
||||
switch (index) { |
||||
case 0: return _p_sensor0_rot.get(); |
||||
|
||||
case 1: return _p_sensor1_rot.get(); |
||||
|
||||
case 2: return _p_sensor2_rot.get(); |
||||
|
||||
case 3: return _p_sensor3_rot.get(); |
||||
|
||||
case 4: return _p_sensor4_rot.get(); |
||||
|
||||
case 5: return _p_sensor5_rot.get(); |
||||
|
||||
|
||||
default: return PX4_ERROR; |
||||
} |
||||
} |
||||
|
||||
|
||||
int |
||||
TFMINI_I2C::tfi2c_transfer(const uint8_t *send, const unsigned send_len, uint8_t *recv, const unsigned recv_len) |
||||
{ |
||||
bool send_and_receive = false; |
||||
if (send != nullptr && send_len > 0) { |
||||
|
||||
int ret = transfer(send, send_len, nullptr, 0); |
||||
send_and_receive = true; |
||||
if (ret != PX4_OK) { |
||||
return ret; |
||||
} |
||||
} |
||||
|
||||
if (recv != nullptr && recv_len > 0) { |
||||
if(send_and_receive){ |
||||
px4_usleep(500_us); |
||||
} |
||||
return transfer(nullptr, 0, recv, recv_len); |
||||
} |
||||
|
||||
return PX4_ERROR; |
||||
} |
||||
|
||||
|
||||
void |
||||
TFMINI_I2C::print_status() |
||||
{ |
||||
I2CSPIDriverBase::print_status(); |
||||
perf_print_counter(_sample_perf); |
||||
perf_print_counter(_comms_error); |
||||
PX4_INFO("poll interval: %ums", _measure_interval / 1000); |
||||
|
||||
for (int i = 0; i < _sensor_count; i++) { |
||||
PX4_INFO("sensor: %i, address %u", i, _sensor_addresses[i]); |
||||
} |
||||
} |
||||
|
||||
void |
||||
TFMINI_I2C::RunImpl() |
||||
{ |
||||
// Collect the sensor data.
|
||||
if (collect() != PX4_OK) { |
||||
PX4_INFO("collection error"); |
||||
px4_usleep(1_s); |
||||
|
||||
} |
||||
} |
||||
|
||||
int |
||||
TFMINI_I2C::set_address(const uint8_t address) |
||||
{ |
||||
if (_sensor_count > 1) { |
||||
PX4_INFO("multiple sensors are connected"); |
||||
return PX4_ERROR; |
||||
} |
||||
|
||||
|
||||
PX4_INFO("requested address: %u", address); |
||||
|
||||
uint8_t shifted_address = address ; |
||||
uint8_t cmd[5] = {0x5A, 0x05, 0x0B, shifted_address,0}; |
||||
cmd[4] = 0x5A + 0x05 + 0x0B + shifted_address; // 最后一位和校验
|
||||
if (transfer(cmd, sizeof(cmd), nullptr, 0) != PX4_OK) { |
||||
PX4_INFO("could not set the address"); |
||||
} |
||||
|
||||
set_device_address(address); |
||||
PX4_INFO("device address: %u", get_device_address()); |
||||
return PX4_OK; |
||||
} |
||||
|
||||
void |
||||
TFMINI_I2C::start() |
||||
{ |
||||
// Fetch parameter values.
|
||||
ModuleParams::updateParams(); |
||||
|
||||
// Schedule the driver cycle at regular intervals.
|
||||
ScheduleOnInterval(_measure_interval); |
||||
} |
||||
|
||||
void |
||||
TFMINI_I2C::custom_method(const BusCLIArguments &cli) |
||||
{ |
||||
set_address(cli.i2c_address); |
||||
} |
||||
|
||||
I2CSPIDriverBase *TFMINI_I2C::instantiate(const BusCLIArguments &cli, const BusInstanceIterator &iterator, |
||||
int runtime_instance) |
||||
{ |
||||
TFMINI_I2C *instance = new TFMINI_I2C(iterator.configuredBusOption(), iterator.bus(), cli.bus_frequency, cli.i2c_address); |
||||
|
||||
if (instance == nullptr) { |
||||
PX4_ERR("alloc failed"); |
||||
return nullptr; |
||||
} |
||||
|
||||
if (instance->init() != PX4_OK) { |
||||
delete instance; |
||||
return nullptr; |
||||
} |
||||
|
||||
instance->start(); |
||||
return instance; |
||||
} |
||||
|
||||
|
||||
void |
||||
TFMINI_I2C::print_usage() |
||||
{ |
||||
PRINT_MODULE_USAGE_NAME("tfmini_i2c", "driver"); |
||||
PRINT_MODULE_USAGE_SUBCATEGORY("distance_sensor"); |
||||
PRINT_MODULE_USAGE_COMMAND("start"); |
||||
PRINT_MODULE_USAGE_PARAMS_I2C_SPI_DRIVER(true, false); |
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x70); |
||||
PRINT_MODULE_USAGE_COMMAND("set_address"); |
||||
PRINT_MODULE_USAGE_PARAMS_I2C_ADDRESS(0x70); |
||||
PRINT_MODULE_USAGE_DEFAULT_COMMANDS(); |
||||
} |
||||
|
||||
extern "C" __EXPORT int tfmini_i2c_main(int argc, char *argv[]) |
||||
{ |
||||
using ThisDriver = TFMINI_I2C; |
||||
BusCLIArguments cli{true, false}; |
||||
cli.i2c_address = TFMINI_I2C_BASE_ADDR; |
||||
cli.default_i2c_frequency = TFMINI_I2C_BUS_SPEED; |
||||
|
||||
const char *verb = cli.parseDefaultArguments(argc, argv); |
||||
|
||||
if (!verb) { |
||||
ThisDriver::print_usage(); |
||||
return -1; |
||||
} |
||||
|
||||
BusInstanceIterator iterator(MODULE_NAME, cli, DRV_DIST_DEVTYPE_TFMINI_I2C); |
||||
|
||||
if (!strcmp(verb, "start")) { |
||||
return ThisDriver::module_start(cli, iterator); |
||||
} |
||||
|
||||
if (!strcmp(verb, "stop")) { |
||||
return ThisDriver::module_stop(iterator); |
||||
} |
||||
|
||||
if (!strcmp(verb, "status")) { |
||||
return ThisDriver::module_status(iterator); |
||||
} |
||||
|
||||
if (!strcmp(verb, "set_address")) { |
||||
return ThisDriver::module_custom_method(cli, iterator); |
||||
} |
||||
|
||||
ThisDriver::print_usage(); |
||||
return -1; |
||||
} |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
Subproject commit 673f5ce29015a9bba3c96792920a10601b5b0718 |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
Subproject commit fd73d7630b9d3ed5a79d613ff680a549e9780de7 |
@ -1 +1 @@
@@ -1 +1 @@
|
||||
Subproject commit 71fc1b81612fa9b5184d5abb93b69d109e9d0e4b |
||||
Subproject commit b3fed06fe822d08d19ab1d2c2f8daf7b7d21951c |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
Subproject commit 6329c909a7b16bb6f97c94cbb598815635b94982 |
@ -0,0 +1 @@
@@ -0,0 +1 @@
|
||||
Subproject commit b568a60fca42599d9998434e606f6e38e0b5e298 |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
date -R |
||||
starttime=`date +'%Y-%m-%d %H:%M:%S'` |
||||
make px4_fmu-v2_default |
||||
endtime=`date +'%Y-%m-%d %H:%M:%S'` |
||||
date -R |
||||
start_seconds=$(date --date="$starttime" +%s); |
||||
end_seconds=$(date --date="$endtime" +%s); |
||||
echo "本次运行时间: "$((end_seconds-start_seconds))"s" |
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
date -R |
||||
starttime=`date +'%Y-%m-%d %H:%M:%S'` |
||||
make px4_fmu-v5_default |
||||
endtime=`date +'%Y-%m-%d %H:%M:%S'` |
||||
date -R |
||||
start_seconds=$(date --date="$starttime" +%s); |
||||
end_seconds=$(date --date="$endtime" +%s); |
||||
echo "本次运行时间: "$((end_seconds-start_seconds))"s" |
Loading…
Reference in new issue