该文为基础上https://blog.csdn.net/qq_34935373/article/details/87905784
想通过游戏手柄自定义话题,自定义按键实现对海龟的控制。于是有了本文
新建节点/joymsg_pub_node和话题/joycontrol_topic.
在src/目录下新建功能包joy_msg,在joy_msg/src的新建源文件joymsg_pub.cpp。代码如下::
#include "ros/ros.h"
#include<geometry_msgs/Twist.h>
#include <iostream>
#include <sstream>
#include <stdio.h> //perror()
#include <unistd.h> //fork()
#include <stdlib.h>
#include <errno.h> //errno, EINTR
#include <string.h> //strlen()
#include <fcntl.h>
#include <signal.h>
#include <syspes.h>
#include <sys/stat.h>
#include <linux/input.h>
#include <linux/joystick.h>
#include <errno.h>
#include <pthread.h>
#define AXES0 0x00 //Left_Axis from right to left
#define AXES1 0x01 //Left_Axis from up to down
#define AXES2 0x02 //Right_Axis from right to left
#define AXES3 0x03 //Right_Axis from down to up
#define AXES4 0x04 //R&L_Key from Right_Key to Left_Key
#define AXES5 0x05 //D&U_Key from Down_key to Up_key
#define BUTTON0 0x00 //X_Botton
#define BUTTON1 0x01 //A_Botton
#define BUTTON2 0x02 //B_Botton
#define BUTTON3 0x03 //Y_Botton
#define BUTTON4 0x04 //LB_Botton
#define BUTTON5 0x05 //RB_Botton
#define BUTTON6 0x06 //LT_Botton
#define BUTTON7 0x07 //RT_Botton
#define BUTTON8 0x08 //BACK_Botton
#define BUTTON9 0x09 //START_Botton
#define BUTTON10 0x10 //Left_Axis__Botton
#define B