你的位置:首页-大奥资零食有限公司 > 新闻资讯 > 灵通你的QG灯具roundControl
灵通你的QG灯具roundControl
发布日期:2024-05-04 08:01 点击次数:102
刚刚初学ROS开荒,四肢刚刚挺过艰苦的ubuntu装置、ros装置的萌新来说,你应该正处于ROS开荒的运行过渡阶段。一方面,你红运你处理了很多装置新系统的很多bug,跨过了扼制了多量东谈主初学ROS的一王人坎,另一方面,你脱手惆怅,面临着空荡荡的新系统的新桌面灯具,你不知谈接下来的一步该若何走,该如何学习。
淌若你思学习无东谈主机仿真,不错接着往下看,我带你从下好ROS之后空论连篇的新系统,一步同相貌兑现无东谈主机的仿真航行。
第一步:成立仿真平台咱们要循序进行gazebo装置(仿真平台)、mavros装置(无东谈主机通讯模块)、px4成立、大地站QGroundControl装置。
此处仿真平台的搭建比拟复杂,上邻接:仿真平台基础成立 · 语雀
邻接的步调先容依然相配属目,黑龙江隆达贸易有限公司淌若还有那边不懂, 温州晟迈铂贸易有限公司不错随着b站的一个up主的视频一步一步安靖搭建
【【XTDrone】无东谈主机仿真平台基础成立(基于ROS和PX4的无东谈主机仿真平台的基础成立搭建)-哔哩哔哩】 https://b23.tv/txNJO6P
第二步:创建职责空间与功能包, 嘉兴明琴国际贸易有限公司写入航行代码1、创建职责空间
#创建职责空间midir catkin_ws/cd catkin_ws/midir srccd src/catkin_init_workspace#编译职责空间cd..catkin_make#设立环境变量source devel/setup.bash#检查环境变量echo $ROS_PACKAGE_PATH
2、创立功能包
功能包是放在职责空间src文献夹中兑现具体功能的零散文献夹, 中研技术有限公司是甩掉ROS源码的最小单位
#创立功能包(offboard_sin是功能包名)$ cd ~/catkin_ws/src$ catkin_create_pkg offboard_sin std_msgs rospy roscpp#编译功能包$ cd ~/catkin_ws$ catkin_make$ source ~/catkin_ws/devel/setup.bash
3、写入航行代码
在功能包的src旅途下创建offboard_sin_node.cpp文献, 平安宝 保平安 专注于安全网络投资并写入如下沿着sin旅途航行的代码
(凭据官方offboard代码示例改写)
杭州纪森川贸易有限公司/** * @file offb_node.cpp * @brief Offboard control example node, written with MAVROS version 0.19.x, PX4 Pro Flight * Stack and tested in Gazebo SITL */#include <ros/ros.h>#include <geometry_msgs/PoseStamped.h>#include <geometry_msgs/Vector3.h>#include <mavros_msgs/CommandBool.h>#include <mavros_msgs/SetMode.h>#include <mavros_msgs/State.h>#define PI acos(-1)mavros_msgs::State current_state;geometry_msgs::PoseStamped current_position;void state_cb(const mavros_msgs::State::ConstPtr& msg){ current_state = *msg;}void getpointfdb(const geometry_msgs::PoseStamped::ConstPtr& msg){ ROS_INFO('x: [%f]',灯具 msg->pose.position.x); ROS_INFO('y: [%f]', msg->pose.position.y); ROS_INFO('z: [%f]', msg->pose.position.z); current_position = *msg;}int main(int argc, char **argv){ ros::init(argc, argv, 'offb_node'); ros::NodeHandle nh; ros::Subscriber state_sub = nh.subscribe<mavros_msgs::State> ('mavros/state', 10, state_cb); ros::Subscriber get_point = nh.subscribe<geometry_msgs::PoseStamped> ('mavros/local_position/pose', 10, getpointfdb); ros::Publisher local_pos_pub = nh.advertise<geometry_msgs::PoseStamped> ('mavros/setpoint_position/local', 10); ros::ServiceClient arming_client = nh.serviceClient<mavros_msgs::CommandBool> ('mavros/cmd/arming'); ros::ServiceClient set_mode_client = nh.serviceClient<mavros_msgs::SetMode> ('mavros/set_mode'); //the setpoint publishing rate MUST be faster than 2Hz ros::Rate rate(20.0f); // wait for FCU connection while(ros::ok() && !current_state.connected){ ros::spinOnce(); rate.sleep(); } geometry_msgs::PoseStamped pose; pose.pose.position.x = 0; pose.pose.position.y = 0; pose.pose.position.z = 3; //send a few setpoints before starting for(int i = 100; ros::ok() && i > 0; --i){ local_pos_pub.publish(pose); ros::spinOnce(); rate.sleep(); } mavros_msgs::SetMode offb_set_mode; offb_set_mode.request.custom_mode = 'OFFBOARD'; mavros_msgs::CommandBool arm_cmd; arm_cmd.request.value = true; ros::Time last_request = ros::Time::now(); while(ros::ok()){ if( current_state.mode != 'OFFBOARD' && (ros::Time::now() - last_request > ros::Duration(5.0f))){ if( set_mode_client.call(offb_set_mode) && offb_set_mode.response.mode_sent){ ROS_INFO('Offboard enabled'); } last_request = ros::Time::now(); } else { if( !current_state.armed && (ros::Time::now() - last_request > ros::Duration(5.0f))){ if( arming_client.call(arm_cmd) && arm_cmd.response.success){ ROS_INFO('Vehicle armed'); } last_request = ros::Time::now(); } } if((abs(current_position.pose.position.x-pose.pose.position.x)<0.5f)&&(abs(current_position.pose.position.y-pose.pose.position.y)<0.5f)&&(abs(current_position.pose.position.y-pose.pose.position.y)<0.5f)) { pose.pose.position.x += 5; pose.pose.position.y = 20*sin(pose.pose.position.x/40*PI); pose.pose.position.z = 3; } local_pos_pub.publish(pose); ros::spinOnce(); rate.sleep(); } return 0;}
4、修改CMakeLists.txt文献
珠海市亚迪力电器有限公司加入底下两行
add_executable(offboard_sin_node src/offboard_sin_node.cpp)target_link_libraries(offboard_sin_node ${catkin_LIBRARIES})第三步:兑现航行仿真
灵通结尾,输入
roslaunch px4 mavros_posix_sitl.launch
此launch文献会灵通你的gazebo启动无东谈主机模子并开荒好mavros通讯
同期,灵通你的QGroundControl,其会自动与你gazebo里的无东谈主机进行通讯聚首
然后灵通新结尾,输入
rosrun offboard_sin offboard_sin_node#rosrun+功能包+功能包内节点文献
兑现恶果
图片灯具
图片
至此,第一次通俗的无东谈主机航行仿真结尾。
参考著述:(8条讯息) 使用PX4+mavros+gazebo兑现无东谈主机offboard戒指仿真_sdhdwyx的博客-CSDN博客_offboard 无东谈主机
图片
https://blog.csdn.net/qq_42680785/article/details/118853000?utm_source=app&app_version=5.3.0&code=app_1562916241&uLinkId=usr1mkqgl919blen 本站仅提供存储就业,系数实质均由用户发布,如发现存害或侵权实质,请点击举报。上一篇:没有了
Powered by 首页-大奥资零食有限公司 @2013-2022 RSS地图 HTML地图