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

Support Pedals as Built-in Devices #206

Open
ATATC opened this issue Jun 2, 2024 · 10 comments
Open

Support Pedals as Built-in Devices #206

ATATC opened this issue Jun 2, 2024 · 10 comments
Assignees
Labels
enhancement New feature or request report Discussed in the meeting todo New task or assignment

Comments

@ATATC
Copy link
Member

ATATC commented Jun 2, 2024

As we've discussed, over the summer, @HaydenHour is assigned to add support for pedals.

@ATATC ATATC added enhancement New feature or request report Discussed in the meeting todo New task or assignment labels Jun 2, 2024
@ATATC ATATC added this to the Stable Release: 1.x milestone Jun 2, 2024
@qmascarenhas
Copy link
Contributor

@HaydenHour see #207 for test plan details of analog sensors - it should provide a framework for functional testing of your summer task. We can discuss further at our meeting on Monday.

@ATATC
Copy link
Member Author

ATATC commented Jun 26, 2024

@HaydenHour Hi Hayden, how it is going?

@HaydenHour
Copy link

@ATATC Hi Terry, its going all right so far. I've decided to do a couple small projects to acclimate myself to using C. In a bit I am planning to do some stuff with the micro Arduino, and eventually beginning to complete the support for pedals as we discussed

@HaydenHour
Copy link

@ATATC I have mostly completed the initial pedal. The video is blurry, but a value between 0-1 is being outputted based on the throttles position. I just want to ticker a bit with the code to make it a bit better. As expected, there are a couple variables in the code that are dependent on certain calibrations (i.e. the initial non 0 rest value being returned).

Video.1.mov

@ATATC
Copy link
Member Author

ATATC commented Jul 26, 2024

Great work.

Now you may want to wrap the code in LEADS framework as I described in the meeting earlier.

As an example, this is the voltage sensor's code:

#ifndef VOLTAGESENSOR_H
#define VOLTAGESENSOR_H


#include "Device.h"

class VoltageSensor : public Device<float> {
protected:
    float _factor;
public:
    VoltageSensor(float r1, float r2, int *const pins);
    void initialize();
    float read();
};


#endif //VOLTAGESENSOR_H
#include "VoltageSensor.h"

VoltageSensor::VoltageSensor(float r1, float r2, int *const pins) : _factor((r1 + r2) / r2), Device<float>(pins) {}

void VoltageSensor::initialize() { pinMode(_pins[0], INPUT); }

float VoltageSensor::read() { return (float) analogRead(_pins[0]) * _factor * 5 / 1023; }

You can download the library here: https://leads-docs.projectneura.org/en/latest/arduino/index.html.

In this example, the dependent variables are r1 and r2 in the constructor.

Here's a detailed setup for development:

  1. Create a file named "Pedal.h" under the same directory where your .ino file is located
  2. Wrap that file with this:
    #ifndef PEDAL_H
    #define PEDAL_H
    
    
    #include "Device.h"
    
    // your code...
    
    
    #endif //PEDAL_H
  3. Create a file named "Pedal.cpp" under the same directory where your .ino file is located and implement the methods declared in the .h file
  4. In your .ino file, import your .h file and instantiate a Pedal object like this:
    #include "LEADS.h"
    #include "Pedal.h"
    
    Pedal TPD(...);
    
    void setup() {
        Serial.begin(9600);
        TPD.initialize();
    }
    
    void loop() {
        returnFloat(THROTTLE_PEDAL, TPD.read());
        delay(100);
    }

HaydenHour added a commit to HaydenHour/LEADS that referenced this issue Jul 26, 2024
@ATATC
Copy link
Member Author

ATATC commented Jul 28, 2024

Sorry for the confusion, we are recently preparing for a massive launch of breaking changes to our Arduino Library. A corresponding revision will be released then. The newer version shall prevail. You may wait until then.

@ATATC
Copy link
Member Author

ATATC commented Jul 29, 2024

@qmascarenhas @HaydenHour

Guide to the Next Step

Please read this page first: https://leads-docs.projectneura.org/en/latest/arduino/sketch.html.
Your Pedal.h should look like this:

#ifndef PEDAL_H
#define PEDAL_H


#include "Device.h"

class Pedal : public Device<float> {
protected:
    float _restValue, _maxValue;

public:
    VoltageSensor(const ArrayList<int> &pins, float restValue, float maxValue);
    void initialize(const ArrayList<String> &parentTags) override;
    float read() override;
};


#endif // PEDAL_H

From there, these methods can be implemented in Pedal.cpp. This is a good example: https://github.com/ProjectNeura/LEADS-Arduino/blob/main/src/VoltageSensor.cpp.

@HaydenHour
Copy link

@ATATC Hi Terry, sorry I haven't responded sooner, I have been a bit busy with family. Just to avoid confusion, should I reconfigure my code to resemble what you have shown, or is this something that should be done in a separate file?

@ATATC
Copy link
Member Author

ATATC commented Aug 4, 2024

@HaydenHour
Basically, your project structure should be like this:

LEADS
-arduino
--leads_vec_power # open your Arduino IDE here
---leads_vec_power.ino
---Pedal.h
---Pedal.cpp

Your current code belongs to a .ino file because it has setup() and loop(). You will need to move the key lines that read the input to what I mentioned in Guide to the Next Step.

@ATATC
Copy link
Member Author

ATATC commented Dec 2, 2024

@qmascarenhas @HaydenHour how are we doing on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request report Discussed in the meeting todo New task or assignment
Projects
None yet
Development

No branches or pull requests

3 participants