SMACC2
Loading...
Searching...
No Matches
smacc2_client_library
cl_px4_mr
src
cl_px4_mr
components
cp_vehicle_command.cpp
Go to the documentation of this file.
1
// Copyright 2025 Robosoft Inc.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <
cl_px4_mr/components/cp_vehicle_command.hpp
>
16
17
namespace
cl_px4_mr
18
{
19
20
CpVehicleCommand::CpVehicleCommand
() {}
21
22
CpVehicleCommand::~CpVehicleCommand
() {}
23
24
void
CpVehicleCommand::onInitialize
()
25
{
26
auto
node = this->
getNode
();
27
publisher_
= node->create_publisher<px4_msgs::msg::VehicleCommand>(
28
"/fmu/in/vehicle_command"
, rclcpp::QoS(1).best_effort());
29
RCLCPP_INFO(
getLogger
(),
"CpVehicleCommand: publisher created on /fmu/in/vehicle_command"
);
30
}
31
32
void
CpVehicleCommand::sendCommand
(
33
uint32_t command,
float
param1,
float
param2,
float
param3,
float
param4,
double
param5,
34
double
param6,
float
param7)
35
{
36
auto
node = this->
getNode
();
37
px4_msgs::msg::VehicleCommand msg;
38
msg.timestamp = node->get_clock()->now().nanoseconds() / 1000;
39
msg.command = command;
40
msg.param1 = param1;
41
msg.param2 = param2;
42
msg.param3 = param3;
43
msg.param4 = param4;
44
msg.param5 = param5;
45
msg.param6 = param6;
46
msg.param7 = param7;
47
msg.target_system = 1;
48
msg.target_component = 1;
49
msg.source_system = 1;
50
msg.source_component = 1;
51
msg.from_external =
true
;
52
publisher_
->publish(msg);
53
RCLCPP_INFO(
54
getLogger
(),
"CpVehicleCommand: sent command %u (p1=%.1f p2=%.1f p7=%.1f)"
, command, param1,
55
param2, param7);
56
}
57
58
void
CpVehicleCommand::arm
()
59
{
60
sendCommand
(px4_msgs::msg::VehicleCommand::VEHICLE_CMD_COMPONENT_ARM_DISARM, 1.0f);
61
}
62
63
void
CpVehicleCommand::forceArm
()
64
{
65
// param2 = 21196 bypasses pre-arm checks (useful for SITL without RC/GCS)
66
sendCommand
(px4_msgs::msg::VehicleCommand::VEHICLE_CMD_COMPONENT_ARM_DISARM, 1.0f, 21196.0f);
67
}
68
69
void
CpVehicleCommand::disarm
()
70
{
71
sendCommand
(px4_msgs::msg::VehicleCommand::VEHICLE_CMD_COMPONENT_ARM_DISARM, 0.0f);
72
}
73
74
void
CpVehicleCommand::setOffboardMode
()
75
{
76
sendCommand
(px4_msgs::msg::VehicleCommand::VEHICLE_CMD_DO_SET_MODE, 1.0f, 6.0f);
77
}
78
79
void
CpVehicleCommand::land
() {
sendCommand
(px4_msgs::msg::VehicleCommand::VEHICLE_CMD_NAV_LAND); }
80
81
void
CpVehicleCommand::takeoff
(
float
altitude)
82
{
83
sendCommand
(
84
px4_msgs::msg::VehicleCommand::VEHICLE_CMD_NAV_TAKEOFF, 0.0f, 0.0f, 0.0f, 0.0f, 0.0, 0.0,
85
altitude);
86
}
87
88
}
// namespace cl_px4_mr
cl_px4_mr::CpVehicleCommand::setOffboardMode
void setOffboardMode()
Definition
cp_vehicle_command.cpp:74
cl_px4_mr::CpVehicleCommand::takeoff
void takeoff(float altitude)
Definition
cp_vehicle_command.cpp:81
cl_px4_mr::CpVehicleCommand::CpVehicleCommand
CpVehicleCommand()
Definition
cp_vehicle_command.cpp:20
cl_px4_mr::CpVehicleCommand::onInitialize
void onInitialize() override
Definition
cp_vehicle_command.cpp:24
cl_px4_mr::CpVehicleCommand::arm
void arm()
Definition
cp_vehicle_command.cpp:58
cl_px4_mr::CpVehicleCommand::land
void land()
Definition
cp_vehicle_command.cpp:79
cl_px4_mr::CpVehicleCommand::disarm
void disarm()
Definition
cp_vehicle_command.cpp:69
cl_px4_mr::CpVehicleCommand::forceArm
void forceArm()
Definition
cp_vehicle_command.cpp:63
cl_px4_mr::CpVehicleCommand::sendCommand
void sendCommand(uint32_t command, float param1=0.0f, float param2=0.0f, float param3=0.0f, float param4=0.0f, double param5=0.0, double param6=0.0, float param7=0.0f)
Definition
cp_vehicle_command.cpp:32
cl_px4_mr::CpVehicleCommand::~CpVehicleCommand
virtual ~CpVehicleCommand()
Definition
cp_vehicle_command.cpp:22
cl_px4_mr::CpVehicleCommand::publisher_
rclcpp::Publisher< px4_msgs::msg::VehicleCommand >::SharedPtr publisher_
Definition
cp_vehicle_command.hpp:44
smacc2::ISmaccComponent::getLogger
rclcpp::Logger getLogger() const
Definition
smacc_component.cpp:44
smacc2::ISmaccComponent::getNode
rclcpp::Node::SharedPtr getNode()
Definition
smacc_component.cpp:42
cp_vehicle_command.hpp
cl_px4_mr
Definition
cl_px4_mr.hpp:28
Generated by
1.12.0