2018-03-07 21:25:44 -04:00
|
|
|
/*
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
simple particle sensor simulation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "SIM_Aircraft.h"
|
|
|
|
|
2018-03-25 23:54:05 -03:00
|
|
|
#include <SITL/SITL.h>
|
|
|
|
|
2018-03-07 21:25:44 -04:00
|
|
|
#include <AP_HAL/utility/RingBuffer.h>
|
|
|
|
|
2019-09-27 08:17:52 -03:00
|
|
|
#include "SIM_SerialDevice.h"
|
|
|
|
|
2018-03-07 21:25:44 -04:00
|
|
|
namespace SITL {
|
|
|
|
|
2019-09-27 08:17:52 -03:00
|
|
|
class Vicon : public SerialDevice {
|
2018-03-07 21:25:44 -04:00
|
|
|
public:
|
|
|
|
|
|
|
|
Vicon();
|
|
|
|
|
|
|
|
// update state
|
2020-05-14 23:14:00 -03:00
|
|
|
void update(const Location &loc, const Vector3f &position, const Vector3f &velocity, const Quaternion &attitude);
|
2018-03-07 21:25:44 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// TODO: make these parameters:
|
|
|
|
const uint8_t system_id = 17;
|
|
|
|
const uint8_t component_id = 18;
|
|
|
|
|
|
|
|
// we share channels with the ArduPilot binary!
|
2020-04-21 00:29:26 -03:00
|
|
|
// Beware: the mavlink rangefinder shares this channel.
|
2018-03-31 06:05:23 -03:00
|
|
|
const mavlink_channel_t mavlink_ch = (mavlink_channel_t)(MAVLINK_COMM_0+5);
|
2018-03-07 21:25:44 -04:00
|
|
|
|
2020-05-14 23:14:00 -03:00
|
|
|
uint64_t last_observation_usec; // time last observation was sent
|
|
|
|
uint64_t time_offset_us; // simulated timeoffset between external system and autopilot
|
2018-05-14 00:53:32 -03:00
|
|
|
|
2020-05-14 23:14:00 -03:00
|
|
|
// buffer of messages to send
|
|
|
|
struct {
|
|
|
|
uint64_t time_send_us; // system time this message should be sent or 0 if no message to send
|
|
|
|
mavlink_message_t obs_msg; // message to be sent
|
|
|
|
} msg_buf[3];
|
|
|
|
|
|
|
|
// SIM_VICON_TYPE parameter bit values
|
|
|
|
enum class ViconTypeMask : uint8_t {
|
|
|
|
VISION_POSITION_ESTIMATE = (1 << 0),
|
|
|
|
VISION_SPEED_ESTIMATE = (1 << 1),
|
2021-02-09 04:45:41 -04:00
|
|
|
VICON_POSITION_ESTIMATE = (1 << 2),
|
|
|
|
VISION_POSITION_DELTA = (1 << 3)
|
2020-05-14 23:14:00 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
// return true if the given message type should be sent
|
|
|
|
bool should_send(ViconTypeMask type_mask) const { return (((uint8_t)type_mask & _sitl->vicon_type_mask.get()) > 0); }
|
|
|
|
|
|
|
|
// get unused index in msg_buf
|
|
|
|
bool get_free_msg_buf_index(uint8_t &index);
|
2018-03-07 21:25:44 -04:00
|
|
|
|
|
|
|
void update_vicon_position_estimate(const Location &loc,
|
|
|
|
const Vector3f &position,
|
2020-05-14 23:14:00 -03:00
|
|
|
const Vector3f &velocity,
|
2018-03-07 21:25:44 -04:00
|
|
|
const Quaternion &attitude);
|
|
|
|
|
|
|
|
void maybe_send_heartbeat();
|
|
|
|
uint32_t last_heartbeat_ms;
|
2021-02-09 04:45:41 -04:00
|
|
|
|
|
|
|
// position delta message
|
|
|
|
Quaternion _attitude_prev; // Rotation to previous MAV_FRAME_BODY_FRD from MAV_FRAME_LOCAL_NED
|
|
|
|
Vector3f _position_prev; // previous position from origin (m) MAV_FRAME_LOCAL_NED
|
2018-03-07 21:25:44 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|