Python_mavros_manual_contoller
2021/11/2 14:10:39
本文主要是介绍Python_mavros_manual_contoller,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
利用python完成mavros与PX4的通信工程,同时也完成了对应的PX4中对应消息代码的调试查看。
from __future__ import print_function import rospy from mavros_msgs.msg import AttitudeTarget, State, ManualControl, OverrideRCIn from geometry_msgs.msg import PoseStamped from mavros_msgs.srv import CommandBool from mavros_msgs.srv import SetMode import threading import time vehicleState = State() def vehicleStateCallBack(msg): global vehicleState vehicleState = msg print("armed:" + str(vehicleState.armed) + "\tconnect:" + str(vehicleState.connected) + "\tmode:" + str(vehicleState.mode)) manualControl_ = ManualControl() def ManualControlCallBack(msg): global manualControl_ manualControl_ = msg print("x=" + str(manualControl_.x) + "\ty=" + str(manualControl_.y) + "\tz=" + str(manualControl_.z)) rospy.init_node('rospy_node', anonymous=True) rospy.Subscriber('/mavros/state', State, vehicleStateCallBack) manual_contoller_pub = rospy.Publisher('/mavros/manual_control/send', ManualControl, queue_size=10) rospy.Subscriber('/mavros/manual_control/control', ManualControl, ManualControlCallBack) arm_ser = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool) set_mode_ser = rospy.ServiceProxy('/mavros/set_mode', SetMode) rc_in_pub = rospy.Publisher('/mavros/rc/override', OverrideRCIn, queue_size=10) manual_controller = ManualControl() manual_controller.x = -300 manual_controller.y = 0 manual_controller.z = 700 manual_controller.r = 500 rate = rospy.Rate(20) rc_in = OverrideRCIn() rc_in.channels = [1500, 1500, 1800, 1500, 0, 0, 0, 0] def main_threading(): while not rospy.is_shutdown(): global vehicleState if not vehicleState.armed: arm_ser(True) # set_mode_ser(custom_mode = 'OFFBOARD') manual_contoller_pub.publish(manual_controller) # rc_in_pub.publish(rc_in) rate.sleep() if __name__ == "__main__": main_threading()
对应px4中的代码段存在与src/module/mavlink/mavlink_receiver.cpp中, 通过PX4_INFO完成消息的查看。
} else {
manual_control_setpoint_s manual{};
PX4_INFO(“manual.x = %d, manual.y = %d, manual.r = %d, manual.z = %d”, man.x, man.y, man.r, man.z);
manual.timestamp = hrt_absolute_time();
manual.x = man.x / 1000.0f;
manual.y = man.y / 1000.0f;
manual.r = man.r / 1000.0f;
manual.z = man.z / 1000.0f;
manual.data_source = manual_control_setpoint_s::SOURCE_MAVLINK_0 + _mavlink->get_instance_id();
_manual_control_setpoint_pub.publish(manual);
可以看到飞机自动进入的poshold模式,也就是position模式,而非offboard模式。对应视频为:
python_mavros_manual_controller
这篇关于Python_mavros_manual_contoller的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南
- 2024-11-16`PyMuPDF4LLM`:提取PDF数据的神器
- 2024-11-16四种数据科学Web界面框架快速对比:Rio、Reflex、Streamlit和Plotly Dash
- 2024-11-14获取参数学习:Python编程入门教程
- 2024-11-14Python编程基础入门