actuators.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020-2023 RaccoonLab.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, version 3.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Author: Dmitry Ponomarev <ponomarevda96@gmail.com>
17  */
18 
19 #include "actuators.hpp"
20 
22  _actuatorsSub = node.subscribe("/uav/actuators", 1, &Actuators::_actuatorsCallback, this);
23  _armSub = node.subscribe("/uav/arm", 1, &Actuators::_armCallback, this);
24 }
25 
26 void Actuators::retriveStats(uint64_t* msg_counter, uint64_t* max_delay_us) {
27  *msg_counter = _msgCounter;
28  *max_delay_us = _maxDelayUsec < 1000000 ? _maxDelayUsec : 0;
29 
30  _msgCounter = 0;
31  _maxDelayUsec = 0;
32 }
33 
35  if (ros::Time::now().toSec() > _lastArmingStatusTimestampSec + 1.0) {
37  }
38 
39  return _armingStatus;
40 }
41 
42 
43 void Actuators::_actuatorsCallback(sensor_msgs::Joy::Ptr msg){
44  uint64_t crntTimeUs = ros::Time::now().toSec() * 1000000;
45 
46  auto crntDelayUsec = crntTimeUs - _lastActuatorsTimestampUsec;
47  if(crntDelayUsec > _maxDelayUsec){
48  _maxDelayUsec = crntDelayUsec;
49  }
50  _lastActuatorsTimestampUsec = crntTimeUs;
51  _msgCounter++;
52 
53  actuatorsSize = std::min(msg->axes.size(), actuators.size());
54  for(size_t idx = 0; idx < actuatorsSize; idx++){
55  actuators[idx] = msg->axes[idx];
56  }
57 
58  if (_scenarioType == 1) {
59  actuators[7] = 0.0;
60  }
61 }
62 
63 void Actuators::_armCallback(std_msgs::Bool msg){
64  auto new_arming_status = msg.data ? ArmingStatus::ARMED : ArmingStatus::DISARMED;
65 
66  if(new_arming_status != _armingStatus){
70  ROS_INFO_STREAM_THROTTLE(1, "ArmingStatus: " << (msg.data ? "Arm" : "Disarm"));
72  }
73 
75 }
Actuators::getArmingStatus
ArmingStatus getArmingStatus()
Definition: actuators.cpp:34
actuators.hpp
ArmingStatus::DISARMED
@ DISARMED
Actuators::_armingStatus
ArmingStatus _armingStatus
Definition: actuators.hpp:54
ArmingStatus::ARMED
@ ARMED
Actuators::_armCallback
void _armCallback(std_msgs::Bool msg)
Definition: actuators.cpp:63
TimeBase< Time, Duration >::toSec
double toSec() const
Actuators::_msgCounter
uint64_t _msgCounter
Definition: actuators.hpp:52
Actuators::_maxDelayUsec
uint64_t _maxDelayUsec
Definition: actuators.hpp:51
Actuators::init
void init(ros::NodeHandle &node)
Definition: actuators.cpp:21
Actuators::_scenarioType
uint8_t _scenarioType
Definition: actuators.hpp:41
ROS_INFO_STREAM_THROTTLE
#define ROS_INFO_STREAM_THROTTLE(period, args)
ArmingStatus
ArmingStatus
Definition: actuators.hpp:27
Actuators::retriveStats
void retriveStats(uint64_t *msg_counter, uint64_t *max_delay_us)
Definition: actuators.cpp:26
Actuators::actuatorsSize
uint8_t actuatorsSize
Definition: actuators.hpp:40
Actuators::_armSub
ros::Subscriber _armSub
Definition: actuators.hpp:48
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
Actuators::_actuatorsCallback
void _actuatorsCallback(sensor_msgs::Joy::Ptr msg)
Definition: actuators.cpp:43
Actuators::_lastActuatorsTimestampUsec
uint64_t _lastActuatorsTimestampUsec
Definition: actuators.hpp:49
Actuators::actuators
std::vector< double > actuators
Definition: actuators.hpp:39
Actuators::_lastArmingStatusTimestampSec
double _lastArmingStatusTimestampSec
Definition: actuators.hpp:55
ArmingStatus::UNKNOWN
@ UNKNOWN
Actuators::_actuatorsSub
ros::Subscriber _actuatorsSub
Definition: actuators.hpp:47
ros::NodeHandle
ros::Time::now
static Time now()


inno_vtol_dynamics
Author(s): Roman Fedorenko, Dmitry Ponomarev, Ezra Tal, Winter Guerra
autogenerated on Mon Dec 9 2024 03:13:35