无线手柄发送接收间断的问题

ROS中无线手柄控制小车中反馈机制的改进

参考链接:ROS配置和使用Xbox One无线手柄添加链接描述
链接:https://blog.csdn.net/Jeffxu_lib/article/details/88074621

备注:参考turtlebot3进行设计手柄操作小车机制,x方向速度,yaw角度进行叠加,发现无线手柄程序的机制只能进行一次的操作,手柄不进行改变的时候,反馈指令接收就没有了,这样小车就不再移动了,所以想改一下,这样就可以连续操作小车移动了,类似与turtlebot3键盘机制。

源程序

首先我是参考上文的链接的,所以ROS中的一些东西就不讲了。

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/Joy.h>

int linear_, angular_;   // used to define which axes of the joystick will control our turtle
int stop;  //用于急停
double l_scale_, a_scale_;
geometry_msgs::Twist twist;

void joyCallback(const sensor_msgs::Joy::ConstPtr& joy)
{
  
  // take  //ros::spin(); the data from the joystick and manipulate it by scaling it and using independent axes to control the linear and angular velocities of the turtle
  twist.angular.z += a_scale_*joy->axes[angular_]; //角度
  twist.linear.x += l_scale_*joy->axes[linear_]; //线速度
  stop = joy->buttons[1];
  if(stop)
  {
     twist.angular.z = 0;
     twist.linear.x = 0;
  }
  ROS_INFO("twist : [%.2f , %.2f]", twist.linear.x, twist.angular.z );
  ROS_INFO("joy : [ %.2f , %.2f ]",joy->axes[0], joy->axes[1]);
  ROS_INFO("Button : [%d , %d , %d , %d]", joy->buttons[0],joy->buttons[1],joy->buttons[2],joy->buttons[3]);
}

int main(int argc, char** argv)
{
  linear_ = 0;
  angular_ = 1;
  l_scale_ = 0.1;
  a_scale_ = 0.1;

  // initialize our ROS node, create a teleop_turtle, and spin our node until Ctrl-C is pressed
  ros::init(argc, argv, "teleop_turtle");
  ros::NodeHandle nh_;
  ros::Publisher vel_pub_ = nh_.advertise<geometry_msgs::Twist>("turtle1/cmd_vel", 1);
  ros::Subscriber joy_sub_ = nh_.subscribe<sensor_msgs::Joy>("joy", 100, &joyCallback);
     
  nh_.param("axis_linear", linear_, linear_);  
  nh_.param("axis_angular", angular_, angular_);
  nh_.param("scale_angular", a_scale_, a_scale_);
  nh_.param("scale_linear", l_scale_, l_scale_);

  ros::Rate loop_rate(10);

  while(ros::ok())
  {
     vel_pub_.publish(twist);
     
     ros::spinOnce();
     loop_rate.sleep();

  }
}

这样相对于原作者的程序,没有使用C++的类的封装性,这样会大大减少程序的安全性,所以有人如果写了C++程序还望分享;

launch文件控制乌龟移动

程序:

<!-- 用于测试的launch文件  -->

<launch>
 <!-- Turtlesim Node-->
  <node pkg="turtlesim" type="turtlesim_node" name="sim"/>

 <!-- joy node -->
  <node respawn="true" pkg="joy" type="joy_node" name="simulations_joy" >
    <param name="dev" type="string" value="/dev/input/js0" />
    <param name="deadzone" value="0.12" />
  </node>

 <!-- Axes -->
 <!-- button -->
  <param name="axis_linear" value="1" type="int"/>
  <param name="axis_angular" value="0" type="int"/>
  <param name="scale_linear" value="0.1" type="double"/>
  <param name="scale_angular" value="0.1" type="double"/>
  <node pkg="learning_joy" type="turtle_teleop_joy" name="teleop" output="screen"/>

</launch>

效果展示

你可以看到乌龟按照一定的速度和角度进行转圈,而且此时不用再按手柄,当然还加入了急停的设置进行停止。

参考:
1、ROS配置和使用Xbox One无线手柄 https://blog.csdn.net/Jeffxu_lib/article/details/88074621
2、turtlebot3仿真代码 https://github.com/ROBOTIS-GIT/turtlebot3

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值