Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create AP_GenericVehicle #26511

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6b4313e
GCS_MAVLink: cope with AHRS not being available
peterbarker Mar 16, 2024
351d342
AP_Common: provide ExampleFirmwareVersion for examples etc to use
peterbarker Mar 16, 2024
0e740bf
GCS_MAVLink: stop supplying FWVersion object as part of GCS_Dummy
peterbarker Mar 16, 2024
f6f8a68
Replay: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
5b388df
AP_AHRS: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
4b3ad23
AP_Airspeed: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
a715e03
AP_Baro: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
e97861c
AP_Common: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
e150e9d
AP_FlashIface: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
269b270
AP_GPS: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
30628d1
AP_GyroFFT: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
93452bd
AP_HAL: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
9d9b06f
AP_InertialSensor: examples: get firmware version object from diff AP…
peterbarker Mar 16, 2024
8897838
AP_Logger: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
2f26168
AP_Mission: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
84716aa
AP_Module: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
8faa25e
AP_NMEA_Output: examples: get firmware version object from diff AP_Co…
peterbarker Mar 16, 2024
07c6452
AP_RangeFinder: examples: get firmware version object from diff AP_Co…
peterbarker Mar 16, 2024
1ffcbdc
AP_RTC: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
d49af54
AP_Scheduler: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
1c1bbaf
GCS_MAVLink: examples: get firmware version object from diff AP_Common
peterbarker Mar 16, 2024
d93d264
AP_Vehicle: provide empty implementation of init_ardupilot
peterbarker Feb 13, 2024
b796efb
AP_Vehicle: add AP_GenericVehicle vehicle type
peterbarker Sep 5, 2023
eeb9d7e
AP_GenericVehicle: add AP_GenericVehicle directory
peterbarker Feb 13, 2024
dd04bd9
wscript: add genericvehicle vehicle target
peterbarker Sep 5, 2023
8ec6cd4
hwdef: add sample genericvehicles
peterbarker Jan 4, 2024
6bedece
AP_HAL_ChibiOS: add unenv directory to hwdef parsing
peterbarker Jan 4, 2024
2d9e172
AP_GyroFFT: correct compilation when AP_Arming is not compiled in
peterbarker Feb 23, 2024
3d4d3d3
AP_Vehicle: cope with AP_Scheduler not being available
peterbarker Mar 7, 2024
fccdb2f
GCS_MAVLink: correct defines around OSD param setting
peterbarker Mar 16, 2024
804b17e
AP_GenericVehicle: add GCS capabilities to genericvehicle
peterbarker Mar 8, 2024
e163ff7
AP_HAL_ChibiOS: add GCS capabilities to genericvehicle
peterbarker Mar 8, 2024
66746b4
AP_BoardConfig: add AP_BOARDCONFIG_ENABLED
peterbarker Mar 7, 2024
6da3d22
AP_Vehicle: correct compilation when AP_BoardConfig not available
peterbarker Mar 7, 2024
4b80d9a
AP_CANManager: stuff
peterbarker Mar 7, 2024
188e79a
AP_Scheduler: fixes for AP_SCHEDULER_ENABLED
peterbarker Mar 7, 2024
0e46384
GCS_MAVLink: adjust for AP_SCHEDULER_ENABLED being false
peterbarker Mar 7, 2024
da39f65
waf: add simulated sitl genericvehicle target
peterbarker Mar 15, 2024
c9a1d66
SRV_Channels: gate method on scripting being enabled
peterbarker Mar 7, 2024
bfbab2e
wscript: build only genericvehicle for genericvehicle boards
peterbarker Mar 16, 2024
f4e030b
AP_Periph: correct compilation when AP_CHECK_FIRMWARE_ENABLED is false
peterbarker Mar 16, 2024
34e2d14
AP_HAL_ChibiOS: add missing Math.h include
peterbarker Mar 16, 2024
43cf857
allow IOMCU to be turned off in includes
peterbarker Mar 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions AP_GenericVehicle/AP_GenericVehicle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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/>.
*/
#include "AP_GenericVehicle.h"

#define FORCE_VERSION_H_INCLUDE
#include "version.h"
#undef FORCE_VERSION_H_INCLUDE

const AP_HAL::HAL& hal = AP_HAL::get_HAL();

AP_GenericVehicle genericvehicle;
AP_Vehicle& vehicle = genericvehicle;

AP_GenericVehicle::AP_GenericVehicle()
{
}

#if AP_SCHEDULER_ENABLED
const AP_Scheduler::Task AP_GenericVehicle::scheduler_tasks[] {
#if HAL_GCS_ENABLED
SCHED_TASK_CLASS(GCS, (GCS*)&genericvehicle._gcs, update_receive, 300, 500, 57),
SCHED_TASK_CLASS(GCS, (GCS*)&genericvehicle._gcs, update_send, 300, 750, 60),
#endif // HAL_GCS_ENABLED
};
void AP_GenericVehicle::get_scheduler_tasks(const AP_Scheduler::Task *&tasks, uint8_t &task_count, uint32_t &log_bit) {
tasks = scheduler_tasks;
task_count = ARRAY_SIZE(scheduler_tasks);
log_bit = log_bitx;
}
#endif // AP_SCHEDULER_ENABLED

void AP_GenericVehicle::init_ardupilot()
{
#if AP_INERTIALSENSOR_ENABLED
#if AP_SCHEDULER_ENABLED
ins.init(scheduler.get_loop_rate_hz());
#else
ins.init(1000);
#endif // AP_SCHEDULER_ENABLED
#endif // AP_INERTIALSENSOR_ENABLED
}

AP_HAL_MAIN_CALLBACKS(&genericvehicle);
42 changes: 42 additions & 0 deletions AP_GenericVehicle/AP_GenericVehicle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <AP_Vehicle/AP_Vehicle.h>

#include "Parameters.h"
#include "GCS_GenericVehicle.h"

class AP_GenericVehicle : public AP_Vehicle {
public:
AP_GenericVehicle();

Parameters g;
static const AP_Param::Info var_info[];
AP_Param param_loader {var_info};

void load_parameters() override;

// begin stuff it would be nice not to have in the build:

// set_mode *must* set control_mode_reason
bool set_mode(const uint8_t new_mode, const ModeReason reason) override {
return false;
}
uint8_t get_mode() const override { return 0; }

void init_ardupilot() override;

#if AP_SCHEDULER_ENABLED
static const AP_Scheduler::Task scheduler_tasks[];
uint32_t log_bitx;
void get_scheduler_tasks(const AP_Scheduler::Task *&tasks, uint8_t &task_count, uint32_t &log_bit) override;
#endif

#if HAL_GCS_ENABLED
// GCS selection
GCS_GenericVehicle _gcs; // avoid using this; use gcs()
GCS_GenericVehicle &gcs() { return _gcs; }
#endif

};

extern AP_GenericVehicle genericvehicle;
22 changes: 22 additions & 0 deletions AP_GenericVehicle/GCS_GenericVehicle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <GCS_MAVLink/GCS_config.h>

#if HAL_GCS_ENABLED

#include "AP_GenericVehicle.h"
#include "GCS_GenericVehicle.h"

uint8_t GCS_GenericVehicle::sysid_this_mav() const
{
return genericvehicle.g.sysid_this_mav;
}

static const ap_message STREAM_PARAMS_msgs[] = {
MSG_NEXT_PARAM
};

const struct GCS_MAVLINK::stream_entries GCS_MAVLINK::all_stream_entries[] = {
MAV_STREAM_ENTRY(STREAM_PARAMS),
MAV_STREAM_TERMINATOR // must have this at end of stream_entries
};

#endif // HAL_GCS_ENABLED
35 changes: 35 additions & 0 deletions AP_GenericVehicle/GCS_GenericVehicle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <GCS_MAVLink/GCS_config.h>

#if HAL_GCS_ENABLED

#include <GCS_MAVLink/GCS.h>
#include "GCS_Mavlink.h"

class GCS_GenericVehicle : public GCS
{
friend class GenericVehicle; // for access to _chan in parameter declarations

public:

// the following define expands to a pair of methods to retrieve a
// pointer to an object of the correct subclass for the link at
// offset ofs. These are of the form:
// GCS_MAVLINK_XXXX *chan(const uint8_t ofs) override;
// const GCS_MAVLINK_XXXX *chan(const uint8_t ofs) override const;
GCS_MAVLINK_CHAN_METHOD_DEFINITIONS(GCS_MAVLINK_GenericVehicle);

protected:

uint8_t sysid_this_mav() const override;
uint32_t custom_mode() const override { return 0; }
MAV_TYPE frame_type() const override { return MAV_TYPE_GENERIC; }

GCS_MAVLINK_GenericVehicle *new_gcs_mavlink_backend(GCS_MAVLINK_Parameters &params,
AP_HAL::UARTDriver &uart) override {
return new GCS_MAVLINK_GenericVehicle(params, uart);
}
};

#endif // HAL_GCS_ENABLED
13 changes: 13 additions & 0 deletions AP_GenericVehicle/GCS_Mavlink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "GCS_Mavlink.h"

#if HAL_GCS_ENABLED

#include "AP_GenericVehicle.h"
/*
default stream rates to 1Hz
*/
const AP_Param::GroupInfo GCS_MAVLINK_Parameters::var_info[] = {
AP_GROUPEND
};

#endif // HAL_GCS_ENABLED
39 changes: 39 additions & 0 deletions AP_GenericVehicle/GCS_Mavlink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <GCS_MAVLink/GCS_config.h>

#if HAL_GCS_ENABLED

#ifndef MAV_SYSTEM_ID
#define MAV_SYSTEM_ID 4
#endif

#include <GCS_MAVLink/GCS.h>

class GCS_MAVLINK_GenericVehicle : public GCS_MAVLINK
{

public:

using GCS_MAVLINK::GCS_MAVLINK;

uint8_t sysid_my_gcs() const override { return 0; }

protected:

uint32_t telem_delay() const override { return 0; }

bool set_home_to_current_location(bool lock) override WARN_IF_UNUSED { return false; }
bool set_home(const Location& loc, bool lock) override WARN_IF_UNUSED { return false; }

void send_nav_controller_output() const override {}
void send_pid_tuning() override {}

private:

MAV_MODE base_mode() const override { return (MAV_MODE)MAV_MODE_FLAG_CUSTOM_MODE_ENABLED; }
MAV_STATE vehicle_system_status() const override { return MAV_STATE_ACTIVE; }

};

#endif // HAL_GCS_ENABLED
29 changes: 29 additions & 0 deletions AP_GenericVehicle/Parameters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "AP_GenericVehicle.h"

const AP_Param::Info AP_GenericVehicle::var_info[] = {
// @Param: FORMAT_VERSION
// @DisplayName: Eeprom format version number
// @Description: This value is incremented when changes are made to the eeprom format
// @User: Advanced
GSCALAR(format_version, "FORMAT_VERSION", 0),

// @Group:
// @Path: ../libraries/AP_Vehicle/AP_Vehicle.cpp
PARAM_VEHICLE_INFO,

#if HAL_GCS_ENABLED
// @Param: SYSID_THISMAV
// @DisplayName: MAVLink system ID of this vehicle
// @Description: Allows setting an individual MAVLink system id for this vehicle to distinguish it from others on the same network
// @Range: 1 255
// @User: Advanced
GSCALAR(sysid_this_mav, "SYSID_THISMAV", MAV_SYSTEM_ID),
#endif

AP_VAREND
};

void AP_GenericVehicle::load_parameters(void)
{
AP_Vehicle::load_parameters(g.format_version, Parameters::k_format_version);
}
28 changes: 28 additions & 0 deletions AP_GenericVehicle/Parameters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#define AP_PARAM_VEHICLE_NAME genericvehicle

#include <AP_Param/AP_Param.h>

// Global parameter class.
//
class Parameters {
public:

static const uint16_t k_format_version = 120;

enum {
// Layout version number, always key zero.
//
k_param_format_version = 0,
k_param_vehicle = 1,
#if HAL_GCS_ENABLED
k_param_sysid_this_mav = 2,
#endif
};

AP_Int16 format_version;
#if HAL_GCS_ENABLED
AP_Int16 sysid_this_mav;
#endif
};
19 changes: 19 additions & 0 deletions AP_GenericVehicle/version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#ifndef FORCE_VERSION_H_INCLUDE
#error version.h should never be included directly. You probably want to include AP_Common/AP_FWVersion.h
#endif

#include "ap_version.h"

#define THISFIRMWARE "AP_GenericVehicle V4.6.0-dev"

// the following line is parsed by the autotest scripts
#define FIRMWARE_VERSION 4,6,0,FIRMWARE_VERSION_TYPE_DEV

#define FW_MAJOR 4
#define FW_MINOR 6
#define FW_PATCH 0
#define FW_TYPE FIRMWARE_VERSION_TYPE_DEV

#include <AP_Common/AP_FWVersionDefine.h>
19 changes: 19 additions & 0 deletions AP_GenericVehicle/wscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
# encoding: utf-8

def build(bld):
if "GenericVehicle" not in bld.env.BOARD:
return
vehicle = bld.path.name
bld.ap_stlib(
name=vehicle + '_libs',
ap_vehicle=vehicle,
ap_libraries=bld.ap_common_vehicle_libraries() + [
],
)

bld.ap_program(
program_name='genericvehicle',
program_groups=['bin', 'genericvehicle'],
use=vehicle + '_libs',
)
2 changes: 2 additions & 0 deletions Tools/AP_Periph/AP_Periph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ void AP_Periph_FW::init()
logger.init(g.log_bitmask, log_structure, ARRAY_SIZE(log_structure));
#endif

#if AP_CHECK_FIRMWARE_ENABLED
check_firmware_print();
#endif

if (hal.util->was_watchdog_reset()) {
printf("Reboot after watchdog reset\n");
Expand Down
3 changes: 3 additions & 0 deletions Tools/AP_Periph/AP_Periph.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,13 @@
void stm32_watchdog_init();
void stm32_watchdog_pat();
#endif

#if AP_CHECK_FIRMWARE_ENABLED
/*
app descriptor for firmware checking
*/
extern const app_descriptor_t app_descriptor;
#endif

extern "C" {
void can_vprintf(uint8_t severity, const char *fmt, va_list arg);
Expand Down
2 changes: 2 additions & 0 deletions Tools/AP_Periph/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,12 @@ void AP_Periph_FW::handle_get_node_info(CanardInstance* canard_instance,
pkt.software_version.major = AP::fwversion().major;
pkt.software_version.minor = AP::fwversion().minor;
pkt.software_version.optional_field_flags = UAVCAN_PROTOCOL_SOFTWAREVERSION_OPTIONAL_FIELD_FLAG_VCS_COMMIT | UAVCAN_PROTOCOL_SOFTWAREVERSION_OPTIONAL_FIELD_FLAG_IMAGE_CRC;
#if AP_CHECK_FIRMWARE_ENABLED
pkt.software_version.vcs_commit = app_descriptor.git_hash;
uint32_t *crc = (uint32_t *)&pkt.software_version.image_crc;
crc[0] = app_descriptor.image_crc1;
crc[1] = app_descriptor.image_crc2;
#endif

readUniqueID(pkt.hardware_version.unique_id);

Expand Down
2 changes: 2 additions & 0 deletions Tools/Replay/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <AP_Filesystem/posix_compat.h>
#include <AP_AdvancedFailsafe/AP_AdvancedFailsafe.h>

#include <AP_Common/ExampleFirmwareVersion.h>

#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
#include <AP_HAL_Linux/Scheduler.h>
#endif
Expand Down
Loading
Loading