2018-12-02 03:34:59 -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/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
simulator connection for morse simulator http://morse-simulator.github.io/
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_HAL/utility/Socket.h>
|
|
|
|
#include "SIM_Aircraft.h"
|
|
|
|
|
|
|
|
namespace SITL {
|
|
|
|
|
|
|
|
/*
|
|
|
|
simulation interface
|
|
|
|
*/
|
|
|
|
class Morse : public Aircraft {
|
|
|
|
public:
|
2019-08-15 01:01:24 -03:00
|
|
|
Morse(const char *frame_str);
|
2018-12-02 03:34:59 -04:00
|
|
|
|
|
|
|
/* update model by one time step */
|
2019-02-21 19:12:05 -04:00
|
|
|
void update(const struct sitl_input &input) override;
|
2018-12-02 03:34:59 -04:00
|
|
|
|
|
|
|
/* static object creator */
|
2019-08-15 01:01:24 -03:00
|
|
|
static Aircraft *create(const char *frame_str) {
|
|
|
|
return new Morse(frame_str);
|
2018-12-02 03:34:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-07-10 15:34:05 -03:00
|
|
|
|
|
|
|
// loopback to convert inbound Morse lidar data into inbound mavlink msgs
|
|
|
|
const char *mavlink_loopback_address = "127.0.0.1";
|
|
|
|
const uint16_t mavlink_loopback_port = 5762;
|
|
|
|
SocketAPM mav_socket { false };
|
|
|
|
struct {
|
|
|
|
// socket to telem2 on aircraft
|
|
|
|
bool connected;
|
|
|
|
mavlink_message_t rxmsg;
|
|
|
|
mavlink_status_t status;
|
|
|
|
uint8_t seq;
|
|
|
|
} mavlink {};
|
|
|
|
|
|
|
|
void send_report(void);
|
|
|
|
uint32_t send_report_last_ms;
|
|
|
|
|
2018-12-02 03:34:59 -04:00
|
|
|
const char *morse_ip = "127.0.0.1";
|
|
|
|
|
|
|
|
// assume sensors are streamed on port 60000
|
|
|
|
uint16_t morse_sensors_port = 60000;
|
|
|
|
|
2018-12-03 03:56:04 -04:00
|
|
|
// assume we control vehicle on port 60001
|
|
|
|
uint16_t morse_control_port = 60001;
|
|
|
|
|
|
|
|
enum {
|
2020-02-02 06:21:29 -04:00
|
|
|
OUTPUT_ROVER_REGULAR=1,
|
|
|
|
OUTPUT_ROVER_SKID=2,
|
|
|
|
OUTPUT_QUAD=3,
|
|
|
|
OUTPUT_PWM=4
|
2018-12-03 03:56:04 -04:00
|
|
|
} output_type;
|
2018-12-02 03:34:59 -04:00
|
|
|
|
|
|
|
bool connect_sockets(void);
|
|
|
|
bool parse_sensors(const char *json);
|
|
|
|
bool sensors_receive(void);
|
2020-02-02 06:21:29 -04:00
|
|
|
void output_rover_regular(const struct sitl_input &input);
|
|
|
|
void output_rover_skid(const struct sitl_input &input);
|
2018-12-03 03:56:04 -04:00
|
|
|
void output_quad(const struct sitl_input &input);
|
2018-12-06 03:11:43 -04:00
|
|
|
void output_pwm(const struct sitl_input &input);
|
2018-12-02 03:34:59 -04:00
|
|
|
void report_FPS();
|
|
|
|
|
|
|
|
// buffer for parsing pose data in JSON format
|
2018-12-04 01:53:15 -04:00
|
|
|
uint8_t sensor_buffer[50000];
|
2018-12-02 03:34:59 -04:00
|
|
|
uint32_t sensor_buffer_len;
|
|
|
|
|
2018-12-03 18:04:21 -04:00
|
|
|
SocketAPM *sensors_sock;
|
|
|
|
SocketAPM *control_sock;
|
2018-12-02 03:34:59 -04:00
|
|
|
|
2018-12-03 18:04:21 -04:00
|
|
|
uint32_t no_data_counter;
|
2018-12-02 03:34:59 -04:00
|
|
|
uint32_t connect_counter;
|
|
|
|
|
|
|
|
double initial_time_s;
|
|
|
|
double last_time_s;
|
|
|
|
double extrapolated_s;
|
|
|
|
double average_frame_time_s;
|
|
|
|
|
|
|
|
uint64_t socket_frame_counter;
|
|
|
|
uint64_t last_socket_frame_counter;
|
|
|
|
uint64_t frame_counter;
|
|
|
|
double last_frame_count_s;
|
|
|
|
|
2018-12-04 00:06:53 -04:00
|
|
|
enum data_type {
|
|
|
|
DATA_FLOAT,
|
|
|
|
DATA_DOUBLE,
|
|
|
|
DATA_VECTOR3F,
|
|
|
|
DATA_VECTOR3F_ARRAY,
|
|
|
|
DATA_FLOAT_ARRAY,
|
|
|
|
};
|
|
|
|
|
2018-12-02 03:34:59 -04:00
|
|
|
struct {
|
|
|
|
double timestamp;
|
|
|
|
struct {
|
2018-12-04 00:06:53 -04:00
|
|
|
Vector3f angular_velocity;
|
|
|
|
Vector3f linear_acceleration;
|
|
|
|
Vector3f magnetic_field;
|
2018-12-02 03:34:59 -04:00
|
|
|
} imu;
|
|
|
|
struct {
|
2018-12-04 00:06:53 -04:00
|
|
|
float x, y, z;
|
2018-12-02 03:34:59 -04:00
|
|
|
} gps;
|
|
|
|
struct {
|
2018-12-04 00:06:53 -04:00
|
|
|
float roll, pitch, yaw;
|
2018-12-02 03:34:59 -04:00
|
|
|
} pose;
|
|
|
|
struct {
|
2018-12-04 00:06:53 -04:00
|
|
|
Vector3f world_linear_velocity;
|
2018-12-02 03:34:59 -04:00
|
|
|
} velocity;
|
2018-12-04 00:06:53 -04:00
|
|
|
struct {
|
|
|
|
struct vector3f_array points;
|
|
|
|
struct float_array ranges;
|
|
|
|
} scanner;
|
2018-12-02 03:34:59 -04:00
|
|
|
} state, last_state;
|
|
|
|
|
|
|
|
// table to aid parsing of JSON sensor data
|
|
|
|
struct keytable {
|
|
|
|
const char *section;
|
|
|
|
const char *key;
|
2018-12-04 00:06:53 -04:00
|
|
|
void *ptr;
|
|
|
|
enum data_type type;
|
|
|
|
} keytable[13] = {
|
|
|
|
{ "", "timestamp", &state.timestamp, DATA_DOUBLE },
|
2018-12-06 02:48:36 -04:00
|
|
|
{ ".imu", "angular_velocity", &state.imu.angular_velocity, DATA_VECTOR3F },
|
|
|
|
{ ".imu", "linear_acceleration", &state.imu.linear_acceleration, DATA_VECTOR3F },
|
|
|
|
{ ".imu", "magnetic_field", &state.imu.magnetic_field, DATA_VECTOR3F },
|
|
|
|
{ ".gps", "x", &state.gps.x, DATA_FLOAT },
|
|
|
|
{ ".gps", "y", &state.gps.y, DATA_FLOAT },
|
|
|
|
{ ".gps", "z", &state.gps.z, DATA_FLOAT },
|
|
|
|
{ ".pose", "roll", &state.pose.roll, DATA_FLOAT },
|
|
|
|
{ ".pose", "pitch", &state.pose.pitch, DATA_FLOAT },
|
|
|
|
{ ".pose", "yaw", &state.pose.yaw, DATA_FLOAT },
|
|
|
|
{ ".velocity", "world_linear_velocity", &state.velocity.world_linear_velocity, DATA_VECTOR3F },
|
|
|
|
{ ".scan", "point_list", &state.scanner.points, DATA_VECTOR3F_ARRAY },
|
|
|
|
{ ".scan", "range_list", &state.scanner.ranges, DATA_FLOAT_ARRAY },
|
2018-12-02 03:34:59 -04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace SITL
|