mirror of https://github.com/ArduPilot/ardupilot
SITL: add terarangertower simulator
This commit is contained in:
parent
5e2bd6d9ec
commit
e5423a3cf6
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
Simulator for the TeraRangerTower proximity sensor
|
||||
*/
|
||||
|
||||
#include "SIM_PS_TeraRangerTower.h"
|
||||
|
||||
#include <GCS_MAVLink/GCS.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
using namespace SITL;
|
||||
|
||||
uint32_t PS_TeraRangerTower::packet_for_location(const Location &location,
|
||||
uint8_t *data,
|
||||
uint8_t buflen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PS_TeraRangerTower::update_output(const Location &location)
|
||||
{
|
||||
const uint32_t now = AP_HAL::millis();
|
||||
if (last_output_time_ms == 0) {
|
||||
last_output_time_ms = now;
|
||||
return;
|
||||
}
|
||||
const uint32_t time_delta = now - last_output_time_ms;
|
||||
if (time_delta < 200) { // 5Hz update
|
||||
return;
|
||||
}
|
||||
last_output_time_ms = now;
|
||||
|
||||
struct PACKED {
|
||||
uint8_t HEADER1{'T'};
|
||||
uint8_t HEADER2{'H'};
|
||||
uint16_t measurements[8];
|
||||
uint8_t checksum;
|
||||
} send_buffer;
|
||||
|
||||
for (uint8_t i=0; i<8; i++) {
|
||||
const uint16_t bf_angle = (360 - (i * 45)) % 360;
|
||||
float distance = measure_distance_at_angle_bf(location, bf_angle);
|
||||
// ::fprintf(stderr, "SIM: %f=%fm\n", current_degrees_bf, distance);
|
||||
if (distance > MAX_RANGE) {
|
||||
send_buffer.measurements[i] = 0xffff;
|
||||
} else {
|
||||
send_buffer.measurements[i] = htobe16(distance * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
send_buffer.checksum = crc_crc8((uint8_t*)&send_buffer, 18);
|
||||
|
||||
const ssize_t ret = write_to_autopilot((const char*)&send_buffer, sizeof(send_buffer));
|
||||
if (ret != sizeof(send_buffer)) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
void PS_TeraRangerTower::update(const Location &location)
|
||||
{
|
||||
update_output(location);
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/*
|
||||
Simulator for the TeraRangerTower proximity sensor
|
||||
|
||||
./Tools/autotest/sim_vehicle.py --gdb --debug -v ArduCopter -A --uartF=sim:terarangertower --speedup=1 -l 51.8752066,14.6487840,0,0
|
||||
|
||||
param set SERIAL5_PROTOCOL 11
|
||||
param set PRX_TYPE 3 # terarangertower
|
||||
reboot
|
||||
|
||||
arm throttle
|
||||
rc 3 1600
|
||||
|
||||
# for avoidance:
|
||||
param set DISARM_DELAY 0
|
||||
param set AVOID_ENABLE 2 # use proximity sensor
|
||||
param set AVOID_MARGIN 2.00 # 2m
|
||||
param set AVOID_BEHAVE 0 # slide
|
||||
reboot
|
||||
mode loiter
|
||||
script /tmp/post-locations.scr
|
||||
arm throttle
|
||||
rc 3 1600
|
||||
rc 3 1500
|
||||
rc 2 1450
|
||||
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "SIM_SerialProximitySensor.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
namespace SITL {
|
||||
|
||||
class PS_TeraRangerTower : public SerialProximitySensor {
|
||||
public:
|
||||
|
||||
uint32_t packet_for_location(const Location &location,
|
||||
uint8_t *data,
|
||||
uint8_t buflen) override;
|
||||
|
||||
void update(const Location &location) override;
|
||||
void update_output(const Location &location);
|
||||
void update_output_scan(const Location &location);
|
||||
|
||||
private:
|
||||
const float MAX_RANGE = 4.5; // metres
|
||||
|
||||
uint32_t last_output_time_ms;
|
||||
};
|
||||
|
||||
};
|
Loading…
Reference in New Issue