Giter Club home page Giter Club logo

xpadcontrol's Introduction

XpadControl

CodeQL .NET Core Desktop GitHub GitHub code size in bytes GitHub tag (with filter)

A cross-platform console application for controlling the Adam robot via a local/remote socket using an xbox gamepad and its analogues.

Capture and simulation of game controllers

To capture the gamepad in Windows, the XInputium library is used. In Linux the Gamepad library is used.

To simulate the operation of controllers in Linux, you can use uinput-joystick-demo. In Windows x360ce

Install xpad driver in Linux (raspberrypi)

$ sudo apt-get install raspberrypi-kernel-headers
$ sudo apt-get install dkms 
$ sudo git clone https://github.com/paroj/xpad.git /usr/src/xpad-0.4
$ sudo dkms install -m xpad -v 0.4

Command line arguments

You can view the command line arguments by typing --help or -h in Linux:

$ dotnet XpadControl.dll -h
        -c, --set-config-path[optional]... Loads the settings from the specified configuration file path and runs the program
        -s, --show-config-path[optional]... Shows path loaded config and close program
        -v, --version[optional]... Show app version and close program
        -h, --help[optional]... Show this help and close program

or Windows

C:\XpadControl\bin\Debug\net7.0-windows>XpadControl.exe -h

Usage:
        -c, --set-config-path[optional]... Loads the settings from the specified configuration file path and runs the program
        -s, --show-config-path[optional]... Shows path loaded config and close program
        -v, --version[optional]... Show app version and close program
        -h, --help[optional]... Show this help and close program

Managing configuration files

When running the program without arguments, a configuration file named appsettings.default.json will be used, it is located in the "Configs" subfolder in relation to the executable file.. Console output is disabled in it, and the log level of the record is error.

To set your own configuration file, you need to copy and rename the default ones, and then use the -c argument when starting the program.

If the file is located in the same directory as the executable, it is enough to specify only the name:

$ dotnet XpadControl.dll -c mysettings.json

If the configuration file is located in a nested directory relative to the executable file:

$ dotnet XpadControl.dll -c settings/mysettings.json

If the configuration file is located in an external directory relative to the executable file, you must specify the full path:

$ dotnet XpadControl.dll -c /etc/mysettings.json

To check where the settings are loaded from, run the program with the -s key

$ dotnet XpadControl.dll -s
Setting loaded from /usr/src/XpadControl/bin/Debug/net7.0-windows/publish/Configs/appsettings.default.json

Tested WebSocket server

The test web socket server is located here

Action

Axis action - an action that consists of two components (for example: head_up_down).
Only stick axes can be linked to such actions. Binding buttons or triggers to them will cause a NotImplementedException error. This is done intentionally to avoid logical errors in bindings.

Button/trigger/axis action - an action that consists of a single component (for example: head_up, head_down, to_home_position)
Can be linked to stick axes, buttons and triggers

Action list and binding

  • to_home_position - is button/trigger/axis action. the command to return the Adam robot to the zero position

    execution conditions:    
            if binding to buttons: button pressed value `{ == true }` => execute    
            if binding to trigger: trigger value `{ >= 0.5 }` => execute    
            if binding to axis: axis value `{ <= -0.5 or  >= 0.5 }` => execute   
    
  • head_up_down head_up head_down - head control commands

    head_up_down is axis action

    execution conditions: 
        if binding to buttons:  throw new NotImplementedException("Button can`t binding to axis action");
        if binding to trigger:  throw new NotImplementedException("Trigger can`t binding to axis action");
        if binding to axis:     if axis value { == 0 } => execute with param servo command = home position
                                if axis value { < 0 } => execute with param servo command = home position - axis value
                                if axis value { > 0 } => execute with param servo command = home position + axis value
    

    head_up head_down is button/trigger/axis action

       execution conditions:
           if binding to buttons:  button pressed value { == true } => execute home position + 1 by goal position != 100
                                   button pressed value { == false } => execute home position - 1 by goal position != home position 
           if binding to trigger:  trigger value { == 0 } => execute with param servo command = home position
                                   trigger value { > 0 } => execute with param servo command = home position + trigger value
           if binding to axis:     axis value { == 0 } => execute with param servo command = home position 
                                   axis value { != 0 } => execute with param servo command = home position + axis value
    

Examples:

Axis action

Binding the y-axis of the right stick to the action:

{
    "action": "head_up_down",
    "axis": "right.stick.y"
}

With this combination of parameters, the robot will move its head down when the right stick is deflected down and up when the stick is deflected up.

Button/trigger/axis action

Binding the right trigger to an action:

{
    "action": "head_up",
    "trigger": "right.trigger"
}

If you press the right trigger of the joystick, the robot will lift its head up, if you release it, the head returns to its original position

Binding the button A to an action:

{
    "action": "head_down",
    "button": "button.a"
}

If you press the button A of the joystick, the robot will lower its head down, if you release it, the head returns to its original position

xpadcontrol's People

Contributors

vertigra avatar

Watchers

 avatar

xpadcontrol's Issues

Dpad event twice

When pressing and releasing the Dpad buttons, the event is called twice

Poor implementation of converting a range of axes to a range of servos

in extension:
XpadControl.Interfaces.AdamActionsMethodsDependencies.ToServoRange(this float gamepadRangeValue, int zeroPosition)

  1. Add test
  2. Change implementation to the calculated range
    For example (???):
    zeroPosition = 17
    negativeRange = -100 -17
    negativeRangeValue = negativeRange /zeroPosition

if the value on the axis decreases, the change in the value in this case will be equal to negativeRangeValue

Clean code

  1. Remove unused events from main app
  2. Events in events in axis events

Use Options argument on init App

  1. Create section Option (or something like that) in config
  2. Create AppArguments generic and send to App constr (serialize from Option )

Value saved state in config?

if saved state == true value must not changed when ...
if saved state == false value must changed to the original values

Add abstraction action => button combination

  1. Added config approximately the following content "Action": LSX or "Action": Button.B or "Action": Button.B + Button.A
    For example:
    "Head turn left/right": RSX (Right stick X axis)
    "Head turn up/down": RSY (Right stick Y axis)
    "Go to home position": Button.Back
  2. Added enum (?) for action
  3. Serialize enum from config file

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.