ros机器人的直行

#include < ros/ros . h > #include < signal . h > #include < geometry_msgs/Twist . h > ros ::Publisher cmdVelPub; void shutdown(int sig){ cmdVelPub . publish(geometry_msgs ::Twist ()); //使机器人停止运动 ROS_INFO( "goforward cpp ended!" ); ros ::shutdown ();}int main(int argc, char ** argv){ ros ::init (argc, argv, "GoForward" ); //初始化ROS,它允许ROS通过命令行进行名称重映射 std ::string topic = "/cmd_vel" ; ros ::NodeHandle node; //为这个进程的节点创建一个句柄 cmdVelPub = node . advertise < geometry_msgs ::Twist > (topic, 1 ); //告诉master将要在/cmd_vel topic上发布一个geometry_msgs/Twist的消息 ros ::Rate loopRate( 10 ); //The desired rate to run at in Hz,ros::Rate对象可以允许你指定自循环的频率 // Override the default ros sigint handler. This must be set after the first NodeHandle is creat signal(SIGINT, shutdown); ROS_INFO( "goforward cpp start..." ); geometry_msgs ::Twist speed; // 控制信号载体 Twist message while (ros ::ok ()) { speed . linear . x = 0.1 ; // 设置线速度为0.1m/s,正为前进,负为后退 speed . angular . z = 0 ; // 设置角速度为0rad/s,正为左转,负为右转 cmdVelPub . publish(speed); // 将刚才设置的指令发送给机器人 loopRate . sleep(); //休眠直到一个频率周期的时间 } return 0 ;}

修改robot_move目录下的CMakeLists.txt

在CMakeLists.txt文件末尾加入几条语句:

add_executable(goforward src/goforward.cpp)
target_link_libraries(goforward ${catkin_LIBRARIES})

add_executable(goincircles src/goincircles.cpp)
target_link_libraries(goincircles ${catkin_LIBRARIES})
  
  
  • 1
  • 2
  • 3
  • 4
  • 5

整个CMakeLists.txt文件如下:

cmake_minimum_required(VERSION 2.8.3)
project(robot_move)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  tf
  roscpp
)

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES robot_move
  CATKIN_DEPENDS geometry_msgs roscpp
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
# include_directories(include)
include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_executable(goforward src/goforward.cpp)
target_link_libraries(goforward ${catkin_LIBRARIES})

add_executable(goincircles src/goincircles.cpp)
target_link_libraries(goincircles ${catkin_LIBRARIES})
启动机器人
若是运行仿真机器人
   roslaunch aicroboxi_bringup fake_aicroboxi.launch
  
  
  • 1
若是运行真实的机器人平台
   roslaunch aicroboxi_bringup minimal.launch
  
  
  • 1
启动 rviz 图形化显示程序,如图1
   roslaunch aicroboxi_rviz view_mobile.launch
  
  
  • 1

RVIZ1



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值