Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Joystick enhancements #8

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open

Conversation

ion098
Copy link
Collaborator

@ion098 ion098 commented Jun 17, 2024

Add controller deadband, curves and fisheye, also changes the const references to Button/floats into getter methods, and renames some stuff.

Test code:

#include "main.h"

#include "gamepad/api.hpp"

void initialize() {
    gamepad::master.set_left_transform(gamepad::TransformationBuilder(gamepad::Deadband(0.05, 0.05))
                                           .and_then(gamepad::Fisheye(1.26))
                                           .and_then(gamepad::ExpoCurve(1.1, 1.1)));
    while (true) {
        gamepad::master.update();
        std::cout << "With curves:" << std::endl;
        std::cout << "(" << gamepad::master.axisLeftX() << "," << gamepad::master.axisLeftY() << ") ("
                  << gamepad::master.axisRightX() << "," << gamepad::master.axisRightY() << ")" << std::endl;
        std::cout << "Without curves:" << std::endl;
        std::cout << "(" << gamepad::master.axisLeftX(false) << "," << gamepad::master.axisLeftY(false) << ") ("
                  << gamepad::master.axisRightX(false) << "," << gamepad::master.axisRightY(false) << ")" << std::endl
                  << std::endl;
        pros::delay(1000);
    }
}

Download the template for this pull request:

Note

This is auto generated from Add Template to Pull Request

curl -o [email protected]+36b33d.zip https://nightly.link/LemLib/Gamepad/actions/artifacts/2251659223.zip;
pros c fetch [email protected]+36b33d.zip;
pros c apply [email protected]+36b33d;
rm [email protected]+36b33d.zip;

ion098 added 5 commits June 16, 2024 18:59
Add an abstarct DriveCurve class and a concrete ExproDriveCurve class, both based on LemLib's implementation.
Allow users to assign a DriveCurve per axis to be used by the controller when updating joystick values.
@ion098 ion098 added the enhancement New feature or request label Sep 11, 2024
@ion098 ion098 marked this pull request as ready for review November 4, 2024 16:46
@ion098 ion098 requested review from Aang099 and SizzinSeal November 4, 2024 19:34
Copy link
Member

@SizzinSeal SizzinSeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm from a design standpoint, but it needs more docs as well as some other nitpickings

const float& RightX = m_RightX;
const float& RightY = m_RightY;

const Button& L1() { return m_L1; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't methods use lowerCamelCase ?

Comment on lines 82 to 85
float LeftX(bool use_curve = true) {
if (use_curve && m_left_transformation) return m_left_transformation->get_value({m_LeftX, m_LeftY}).first;
else return m_LeftX;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a specific reason why this is defined in the header file? This should be put in a source file to minimize hot package size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that since this function is included in a cold package source file, the version of the function that is included in the hot package binary should be discarded at link time, so there shouldn't be any noticeable difference in hot package size.

include/gamepad/joystick_modifier.hpp Outdated Show resolved Hide resolved
include/gamepad/joystick_modifier.hpp Outdated Show resolved Hide resolved
include/gamepad/joystick_modifier.hpp Outdated Show resolved Hide resolved
include/gamepad/joystick_modifier.hpp Outdated Show resolved Hide resolved
include/gamepad/joystick_modifier.hpp Outdated Show resolved Hide resolved
include/gamepad/joystick_modifier.hpp Outdated Show resolved Hide resolved
src/gamepad/joystick_modifier.cpp Outdated Show resolved Hide resolved
include/gamepad/controller.hpp Outdated Show resolved Hide resolved
@ion098 ion098 requested a review from SizzinSeal November 16, 2024 23:44
Copy link
Member

@SizzinSeal SizzinSeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (almost), just need to wrap up our convo on function defs in headers vs in source, and fix style issues

Comment on lines 19 to 24
/**
* @brief Get the transformed coordinate given the original.
*
* @param original The original value of the joystick
* @return std::pair<float, float> The transformed value
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be aligned with the function. Usually clang-format catches this

Suggested change
/**
* @brief Get the transformed coordinate given the original.
*
* @param original The original value of the joystick
* @return std::pair<float, float> The transformed value
*/
/**
* @brief Get the transformed coordinate given the original.
*
* @param original The original value of the joystick
* @return std::pair<float, float> The transformed value
*/

@ion098 ion098 changed the title Joystick enhancements ✨ Joystick enhancements Nov 20, 2024
@ion098 ion098 added the needs testing This PR/bug report needs testing label Nov 20, 2024
@SizzinSeal
Copy link
Member

Test data:

With curves:
(0,0) (0,0)
Without curves:
(0,0) (0,0)

With curves:
(0,0) (0.401575,-0.330709)
Without curves:
(-0.149606,0.212598) (0.401575,-0.330709)

With curves:
(0,0) (0.322835,-0.606299)
Without curves:
(-0.0866142,0.511811) (0.322835,-0.606299)

With curves:
(0,0) (0.244094,-0.574803)
Without curves:
(-0.0472441,0.346457) (0.244094,-0.574803)

With curves:
(0,0) (0.0708661,0.15748)
Without curves:
(0.181102,-0.88189) (0.0708661,0.15748)

With curves:
(0,0) (0,0.417323)
Without curves:
(0.23622,-0.984252) (0,0.417323)

With curves:
(0,0) (-0.433071,0.204724)
Without curves:
(0.527559,0) (-0.433071,0.204724)

With curves:
(0,0) (0.0866142,-0.566929)
Without curves:
(0.0866142,0.519685) (0.0866142,-0.566929)

With curves:
(0,0) (0.795276,-0.165354)
Without curves:
(-0.582677,-0.173228) (0.795276,-0.165354)

@SizzinSeal
Copy link
Member

More tests:

With curves:
(-0.294027,1) (0,0)
Without curves:
(-0.362205,1) (0,0)

With curves:
(-1,0.351606) (0,0)
Without curves:
(-1,0.417323) (0,0)

With curves:
(0.703634,-0.520595) (0,0)
Without curves:
(0.740157,-0.574803) (0,0)

With curves:
(0.598425,0.14346) (0,0)
Without curves:
(0.645669,0.212598) (0,0)

With curves:
(-0.891154,-0.22151) (0,0)
Without curves:
(-0.905512,-0.291339) (0,0)

With curves:
(0.189927,-1) (0,0)
Without curves:
(0.259843,-1) (0,0)

With curves:
(0,-1) (0,0)
Without curves:
(0,-1) (0,0)

With curves:
(1,0.494878) (0,0)
Without curves:
(1,0.551181) (0,0)

With curves:
(1,-0.326815) (0,0)
Without curves:
(1,-0.393701) (0,0)

With curves:
(-1,-1) (0,0)
Without curves:
(-0.84252,-0.80315) (0,0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs testing This PR/bug report needs testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants