mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-27 22:50:34 +08:00
New UAVCAN initialization logic
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
#!nsh
|
||||
#
|
||||
# UAVCAN initialization script.
|
||||
#
|
||||
|
||||
if param compare UAVCAN_ENABLE 1
|
||||
then
|
||||
if uavcan start
|
||||
then
|
||||
sleep 1 # Sensor autodetection delay
|
||||
echo "[init] UAVCAN started"
|
||||
else
|
||||
echo "[init] ERROR: Could not start UAVCAN"
|
||||
tone_alarm $TUNE_OUT_ERROR
|
||||
fi
|
||||
fi
|
||||
@@ -304,11 +304,10 @@ then
|
||||
then
|
||||
if [ $OUTPUT_MODE == uavcan_esc ]
|
||||
then
|
||||
if uavcan start 1
|
||||
if param compare UAVCAN_ENABLE 0
|
||||
then
|
||||
echo "CAN UP"
|
||||
else
|
||||
echo "CAN ERR"
|
||||
echo "[init] OVERRIDING UAVCAN_ENABLE = 1"
|
||||
param set UAVCAN_ENABLE 1
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -447,6 +446,11 @@ then
|
||||
|
||||
mavlink start $MAVLINK_FLAGS
|
||||
|
||||
#
|
||||
# UAVCAN
|
||||
#
|
||||
sh /etc/init.d/rc.uavcan
|
||||
|
||||
#
|
||||
# Sensors, Logging, GPS
|
||||
#
|
||||
|
||||
@@ -42,7 +42,8 @@ MAXOPTIMIZATION = -Os
|
||||
|
||||
# Main
|
||||
SRCS += uavcan_main.cpp \
|
||||
uavcan_clock.cpp
|
||||
uavcan_clock.cpp \
|
||||
uavcan_params.c
|
||||
|
||||
# Actuators
|
||||
SRCS += actuators/esc.cpp
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include <fcntl.h>
|
||||
#include <systemlib/err.h>
|
||||
#include <systemlib/systemlib.h>
|
||||
#include <systemlib/param/param.h>
|
||||
#include <systemlib/mixer/mixer.h>
|
||||
#include <systemlib/board_serial.h>
|
||||
#include <version/version.h>
|
||||
@@ -587,7 +588,7 @@ void UavcanNode::sensor_print_enabled()
|
||||
static void print_usage()
|
||||
{
|
||||
warnx("usage: \n"
|
||||
"\tuavcan start <node_id> [can_bitrate]\n"
|
||||
"\tuavcan start\n"
|
||||
"\tuavcan sensor enable <sensor name>\n"
|
||||
"\tuavcan sensor list");
|
||||
|
||||
@@ -599,52 +600,32 @@ extern "C" __EXPORT int uavcan_main(int argc, char *argv[]);
|
||||
|
||||
int uavcan_main(int argc, char *argv[])
|
||||
{
|
||||
constexpr unsigned DEFAULT_CAN_BITRATE = 1000000;
|
||||
|
||||
if (argc < 2) {
|
||||
print_usage();
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
if (!std::strcmp(argv[1], "start")) {
|
||||
if (argc < 3) {
|
||||
print_usage();
|
||||
::exit(1);
|
||||
if (UavcanNode::instance()) {
|
||||
errx(1, "already started");
|
||||
}
|
||||
|
||||
/*
|
||||
* Node ID
|
||||
*/
|
||||
const int node_id = atoi(argv[2]);
|
||||
// Node ID
|
||||
int32_t node_id = 0;
|
||||
(void)param_get(param_find("UAVCAN_NODE_ID"), &node_id);
|
||||
|
||||
if (node_id < 0 || node_id > uavcan::NodeID::Max || !uavcan::NodeID(node_id).isUnicast()) {
|
||||
warnx("Invalid Node ID %i", node_id);
|
||||
::exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* CAN bitrate
|
||||
*/
|
||||
unsigned bitrate = 0;
|
||||
// CAN bitrate
|
||||
int32_t bitrate = 0;
|
||||
(void)param_get(param_find("UAVCAN_BITRATE"), &bitrate);
|
||||
|
||||
if (argc > 3) {
|
||||
bitrate = atol(argv[3]);
|
||||
}
|
||||
|
||||
if (bitrate <= 0) {
|
||||
bitrate = DEFAULT_CAN_BITRATE;
|
||||
}
|
||||
|
||||
if (UavcanNode::instance()) {
|
||||
errx(1, "already started");
|
||||
}
|
||||
|
||||
/*
|
||||
* Start
|
||||
*/
|
||||
// Start
|
||||
warnx("Node ID %u, bitrate %u", node_id, bitrate);
|
||||
return UavcanNode::start(node_id, bitrate);
|
||||
|
||||
}
|
||||
|
||||
/* commands below require the app to be started */
|
||||
@@ -655,14 +636,13 @@ int uavcan_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!std::strcmp(argv[1], "status") || !std::strcmp(argv[1], "info")) {
|
||||
|
||||
inst->print_info();
|
||||
::exit(0);
|
||||
inst->print_info();
|
||||
::exit(0);
|
||||
}
|
||||
|
||||
if (!std::strcmp(argv[1], "stop")) {
|
||||
delete inst;
|
||||
::exit(0);
|
||||
delete inst;
|
||||
::exit(0);
|
||||
}
|
||||
|
||||
if (!std::strcmp(argv[1], "sensor")) {
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (C) 2014 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @author Pavel Kirienko <pavel.kirienko@gmail.com>
|
||||
*/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <systemlib/param/param.h>
|
||||
|
||||
/**
|
||||
* Enable UAVCAN.
|
||||
*
|
||||
* Enables support for UAVCAN-interfaced actuators and sensors.
|
||||
*
|
||||
* @min 0
|
||||
* @max 1
|
||||
* @group UAVCAN
|
||||
*/
|
||||
PARAM_DEFINE_INT32(UAVCAN_ENABLE, 0);
|
||||
|
||||
/**
|
||||
* UAVCAN Node ID.
|
||||
*
|
||||
* Read the specs at http://uavcan.org to learn more about Node ID.
|
||||
*
|
||||
* @min 1
|
||||
* @max 125
|
||||
* @group UAVCAN
|
||||
*/
|
||||
PARAM_DEFINE_INT32(UAVCAN_NODE_ID, 1);
|
||||
|
||||
/**
|
||||
* UAVCAN CAN bus bitrate.
|
||||
*
|
||||
* @min 20000
|
||||
* @max 1000000
|
||||
* @group UAVCAN
|
||||
*/
|
||||
PARAM_DEFINE_INT32(UAVCAN_BITRATE, 1000000);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user