EtherCAT Control Framework v0.9
Implementation of EtherCAT protocol using IgH EtherCAT library for robot controller.
xbox_controller.hpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright (C) 2021 Veysi ADIN, UST KIST
6 *
7 * This file is part of the Wrapped IgH EtherCAT master userspace program
8 * for control applications.
9 *
10 * The Wrapped IgH EtherCAT master userspace program for control application
11 * in userspace is free software; you canredistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; version 2 of the License.
14 *
15 * The Wrapped IgH EtherCAT master userspace program for control application
16 * is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
17 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 * PURPOSE.
19 * See the GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with the Wrapped IgH EtherCAT master userspace program for control application.
23 * If not, see <http://www.gnu.org/licenses/>.
24 *
25 * ---
26 *
27 * The license mentioned above concerns the source code only. Using the
28 * EtherCAT technology and brand is only permitted in compliance with the
29 * industrial property and similar rights of Beckhoff Automation GmbH.
30 *
31 * Contact information: veysi.adin@kist.re.kr
32 *****************************************************************************/
33/*******************************************************************************
34 * \file xboxController.hpp
35 * \brief Contains blueprint for reading values from XboxController
36 *******************************************************************************/
37
38/*
39 * Xbox Controller code has been downloaded from ;
40 * https://github.com/msch26/scholtyssek-blogspot/tree/master/xboxControllerClient/src
41 * as a C code, this code has been modified to C++ code, and class implementation
42 * added by
43 * VeysiADN
44 * 01/18/2020
45 * veysi.adin@kist.re.kr
46 */
47
48#ifndef XBOXCONTROLLER_H_
49#define XBOXCONTROLLER_H_
50
51#include <string>
52#include <stdlib.h>
53#include <stdio.h>
54#include <fcntl.h>
55#include <unistd.h>
56#include <linux/joystick.h>
57#include <iostream>
58
59#define IDENTIFIER_SIZE 64
60
61#define STICK_LEFT_X_ID 0x00
62#define STICK_LEFT_Y_ID 0x01
63#define STICK_RIGHT_X_ID 0x03
64#define STICK_RIGHT_Y_ID 0x04
65#define STICK_LEFT_TOP_ID 0x02
66#define STICK_RIGHT_TOP_ID 0x05
67#define CROSS_LR_ID 0x06
68#define CROSS_FB_ID 0x07
69
70#define BTN_BACK_ID 0x06
71#define BTN_START_ID 0x07
72#define BTN_XBOX_ID 0x08
73#define BTN_LEFT_STICK_ID 0x09
74#define BTN_RIGHT_STICK_ID 0x0A
75
76#define BTN_A_ID 0x00
77#define BTN_B_ID 0x01
78#define BTN_X_ID 0x02
79#define BTN_Y_ID 0x03
80#define BTN_TOP_LEFT_ID 0x04
81#define BTN_TOP_RIGHT_ID 0x05
82
83static std::string s = "/dev/input/js0";
84static char* XBOX_DEVICE = const_cast<char*>(s.c_str());
86typedef struct {
89 char identifier[IDENTIFIER_SIZE];
90 int stk_LeftX; /* left stick */
91 int stk_LeftY; /* left stick */
92 int stk_RightX; /* right stick */
94 int stk_crossFB; /* cross front/back */
95 int stk_crossLR; /* cross left/right */
96 int stk_LeftTop; /* left top stick */
97 int stk_RightTop; /* right top stick */
102 int btn_A;
103 int btn_B;
104 int btn_X;
105 int btn_Y;
109} XboxCtrl;
115public:
116 struct js_event js;
118 int fd = -1;
119 XboxCtrl* xbox = NULL;
126 int InitXboxController(char* dev);
157 void SetXboxCtrlValue(XboxCtrl* xbox, struct js_event* js);
164};
165#endif /* XBOXCONTROLLER_H_ */
Class for opening joystick and reading values from XboxController.
Definition: xbox_controller.hpp:114
XboxCtrl * xbox
Definition: xbox_controller.hpp:119
int fd
Definition: xbox_controller.hpp:118
char joysickIdentifier[IDENTIFIER_SIZE]
Definition: xbox_controller.hpp:117
XboxCtrl * GetXboxDataStruct(void)
Allocate mememory for XboxDataStruct.
Definition: xbox_controller.cpp:25
void DeinitXboxController(XboxCtrl *xbox)
Closes opened controller.
Definition: xbox_controller.cpp:9
int InitXboxController(char *dev)
Opens xbox controller via file descriptor.
Definition: xbox_controller.cpp:14
void PrintXboxCtrlValues(XboxCtrl *xbox)
Prints acquired values from xbox controller.
Definition: xbox_controller.cpp:119
void ReadXboxData(XboxCtrl *xbox)
Reads actual values from xbox controller such as axis data and button data.
Definition: xbox_controller.cpp:47
void SetXboxCtrlValue(XboxCtrl *xbox, struct js_event *js)
Assing acquired values to controller struct.
Definition: xbox_controller.cpp:51
void ReadXboxControllerInformation(XboxCtrl *xbox)
Reads xbox controller information, e.g number of axis and buttons.
Definition: xbox_controller.cpp:33
struct js_event js
Definition: xbox_controller.hpp:116
Structure for reading values from XboxController.
Definition: xbox_controller.hpp:86
int stk_crossFB
Definition: xbox_controller.hpp:94
int btn_A
Definition: xbox_controller.hpp:102
int btn_leftTop
Definition: xbox_controller.hpp:107
int btn_start
Definition: xbox_controller.hpp:99
int stk_LeftTop
Definition: xbox_controller.hpp:96
int btn_X
Definition: xbox_controller.hpp:104
int stk_RightTop
Definition: xbox_controller.hpp:97
int btn_rightStk
Definition: xbox_controller.hpp:101
int btn_leftStk
Definition: xbox_controller.hpp:100
int numOfAxis
Definition: xbox_controller.hpp:87
int btn_B
Definition: xbox_controller.hpp:103
int stk_RightY
Definition: xbox_controller.hpp:93
int stk_LeftY
Definition: xbox_controller.hpp:91
int stk_crossLR
Definition: xbox_controller.hpp:95
int btn_xbox
Definition: xbox_controller.hpp:106
int btn_rightTop
Definition: xbox_controller.hpp:108
int btn_back
Definition: xbox_controller.hpp:98
int stk_LeftX
Definition: xbox_controller.hpp:90
int numOfButtons
Definition: xbox_controller.hpp:88
int stk_RightX
Definition: xbox_controller.hpp:92
int btn_Y
Definition: xbox_controller.hpp:105
#define IDENTIFIER_SIZE
Definition: xbox_controller.hpp:59
static char * XBOX_DEVICE
Definition: xbox_controller.hpp:84
static std::string s
Definition: xbox_controller.hpp:83