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

[WIP] Add IC engine control module #24055

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions ROMFS/px4fmu_common/init.d-posix/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ then
payload_deliverer start
fi

if param compare -s ICE_EN 1
then
internal_combustion_engine_control start
fi

#user defined mavlink streams for instances can be in PATH
. px4-rc.mavlink

Expand Down
6 changes: 6 additions & 0 deletions ROMFS/px4fmu_common/init.d/rcS
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ else
payload_deliverer start
fi

if param compare -s ICE_EN 1
then
internal_combustion_engine_control start
echo "****INFO [init] Internal Combustion Engine Control started"
fi

#
# Optional board supplied extras: rc.board_extras
#
Expand Down
2 changes: 2 additions & 0 deletions boards/px4/sitl/default.px4board
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ CONFIG_EXAMPLES_HELLO=y
CONFIG_EXAMPLES_PX4_MAVLINK_DEBUG=y
CONFIG_EXAMPLES_PX4_SIMPLE_APP=y
CONFIG_EXAMPLES_WORK_ITEM=y

CONFIG_MODULES_INTERNAL_COMBUSTION_ENGINE_CONTROL=y
1 change: 1 addition & 0 deletions msg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ set(msg_files
HomePosition.msg
HoverThrustEstimate.msg
InputRc.msg
InternalCombustionEngineControl.msg
InternalCombustionEngineStatus.msg
IridiumsbdStatus.msg
IrlockReport.msg
Expand Down
8 changes: 8 additions & 0 deletions msg/InternalCombustionEngineControl.msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
uint64 timestamp # time since system start (microseconds)

bool ignition_on # activate/deactivate ignition
float32 throttle_control # [0,1] - Motor should idle with 0. Includes slew rate if enabled.
float32 choke_control # [0,1]
float32 starter_engine_control # [0,1]

uint8 user_request # user intent for on/off/keep
1 change: 1 addition & 0 deletions src/lib/mixer_module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ px4_add_library(mixer_module
functions/FunctionConstantMax.hpp
functions/FunctionConstantMin.hpp
functions/FunctionGimbal.hpp
functions/FunctionICEngineControl.hpp
functions/FunctionLandingGear.hpp
functions/FunctionManualRC.hpp
functions/FunctionMotors.hpp
Expand Down
83 changes: 83 additions & 0 deletions src/lib/mixer_module/functions/FunctionICEngineControl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/****************************************************************************
*
* Copyright (c) 2024 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.
*
****************************************************************************/

#pragma once

#include "FunctionProviderBase.hpp"

#include <uORB/topics/internal_combustion_engine_control.h>

/**
* Functions: ICE...
*/
class FunctionICEControl : public FunctionProviderBase
{
public:
FunctionICEControl()
{
resetAllToDisarmedValue();
}

static FunctionProviderBase *allocate(const Context &context) { return new FunctionICEControl(); }

void update() override
{
internal_combustion_engine_control_s internal_combustion_engine_control;

// map [0, 1] to [-1, 1] which is the interface for non-motor PWM channels
if (_topic.update(&internal_combustion_engine_control)) {
_data[0] = internal_combustion_engine_control.ignition_on * 2.f - 1.f;
_data[1] = internal_combustion_engine_control.throttle_control * 2.f - 1.f;
_data[2] = internal_combustion_engine_control.choke_control * 2.f - 1.f;
_data[3] = internal_combustion_engine_control.starter_engine_control * 2.f - 1.f;
}
}

float value(OutputFunction func) override { return _data[(int)func - (int)OutputFunction::IC_Engine_Ignition]; }

private:
static constexpr int num_data_points = 4;

void resetAllToDisarmedValue()
{
for (int i = 0; i < num_data_points; ++i) {
_data[i] = NAN;
}
}

static_assert(num_data_points == (int)OutputFunction::IC_Engine_Starter - (int)OutputFunction::IC_Engine_Ignition + 1,
"number of functions mismatch");

uORB::Subscription _topic{ORB_ID(internal_combustion_engine_control)};
float _data[num_data_points] {};
};
1 change: 1 addition & 0 deletions src/lib/mixer_module/mixer_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static const FunctionProvider all_function_providers[] = {
{OutputFunction::Gripper, &FunctionGripper::allocate},
{OutputFunction::RC_Roll, OutputFunction::RC_AUXMax, &FunctionManualRC::allocate},
{OutputFunction::Gimbal_Roll, OutputFunction::Gimbal_Yaw, &FunctionGimbal::allocate},
{OutputFunction::IC_Engine_Ignition, OutputFunction::IC_Engine_Starter, &FunctionICEControl::allocate},
};

MixingOutput::MixingOutput(const char *param_prefix, uint8_t max_num_outputs, OutputModuleInterface &interface,
Expand Down
1 change: 1 addition & 0 deletions src/lib/mixer_module/mixer_module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "functions/FunctionConstantMin.hpp"
#include "functions/FunctionGimbal.hpp"
#include "functions/FunctionGripper.hpp"
#include "functions/FunctionICEngineControl.hpp"
#include "functions/FunctionLandingGear.hpp"
#include "functions/FunctionLandingGearWheel.hpp"
#include "functions/FunctionManualRC.hpp"
Expand Down
5 changes: 5 additions & 0 deletions src/lib/mixer_module/output_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ functions:

Landing_Gear_Wheel: 440

IC_Engine_Ignition: 450
IC_Engine_Throttle: 451
IC_Engine_Choke: 452
IC_Engine_Starter: 453

# Add your own here:
#MyCustomFunction: 10000

Expand Down
46 changes: 46 additions & 0 deletions src/modules/internal_combustion_engine_control/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
############################################################################
#
# Copyright (c) 2024 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 modules__internal_combustion_engine_control
MAIN internal_combustion_engine_control
COMPILE_FLAGS
#-DDEBUG_BUILD
SRCS
InternalCombustionEngineControl.cpp
InternalCombustionEngineControl.hpp
MODULE_CONFIG
module.yaml
DEPENDS
px4_work_queue
SlewRate
)
Loading
Loading