pieteroskam / autopilot

ESP32 autopilot BLE
GNU General Public License v3.0
37 stars 8 forks source link

Renaming and refactoring #6

Open mcsarge opened 5 months ago

mcsarge commented 5 months ago

Not really an issue, but I wanted to let you know that in my branch I am doing a little refactoring if you are open to it.

I renamed the "Motor" class to "Tiller" and I made it a class you can create in your code. When creating an object of "Tiller" you pass it in either the 2 pin numbers for your original code (Linear Actuator) or you pass it in a single pin if you want it to work in "Servo" mode.

In servo mode, the speed and direction are converted to a 0 to 180 degree position using a the map function. In my prototype code, this seems to work well, but I think I have to adjust the PID numbers in your app to prevent the motor from swinging left and right hard. I can also setup a proportional conversion or a running average dampen out large swings back and forth.

Next I will create a class to control the speed of the motor it will be very similar to the code I wrote for the servo mode of the "Tiller" I may use a name for this calls since if I use Motor people may get confused.

Lastly, i removed the Bluetooth class and just moved that functionality into the main program. This was so that I could allow the callback function to have access to the instantiated "Tiller" class when receiving from the App.

Matt

pieteroskam commented 5 months ago

You are using it for a trolling motor right?

The naming of Tiller might be more clear, but then i dont have a tiller but a wheel! Perhaps Rudder would be a better name then? But trolling motors dont have a rudder.

So the pid output is designed not to go to a setpoint. In my case I designed it to use it without rudder feedback. I am planning to use rudder feedback though, that would be way better for a servo. with rudder feedback the Target is a certain rudder/servo angle. Without rudder feedback, i just measure the heading deficit and rotation speed and apply more or less rudder.

So without rudder feedback, i am essentially controlling to motor, and not the rudder. So the naming of the Motor Class isnt that strange I think.

But yes, it will work in your case, but only less optimal.

mcsarge commented 5 months ago

Hi,

Yes, I find the motor paradigm is a bit hard to deal with but I agree with your setup it may be the correct name. I will simply add a "Rudder" class and use that. I had to add smoothing to the speed when converting it to rudder position to dampen out the large swings from left to right. It would be great if you had a way to switch between the different modes in the App. So maybe:

Rudder - control the absolute position of a rudder (0-90, port or starboard) LinearActuator - Move the LA in or out a by commanding a motor at a variable speed. (What Motor does now)

Thrust - Control the thrust of a motor with direction (Forward, Reverse) and percentage (0-100%). Works for fixed propellers or inboard/outboard situations too (trolling or regular).

Even if you did not want to add the thrust, just supporting an absolute position for the Rudder would be a big help. Might need to add some settings to tune how much deflection of the rudder is needed based on the current speed of the vessel (not the current speed of the motor) so it would work on a sailboat. With a setting you could compensate for the thrust being vectored off the motor or as a fixed rudder with no motor, but maybe a PID calculation of take care of that all by itself.

Matt

On Thu, May 30, 2024 at 10:41 AM Pieter Oskam @.***> wrote:

You are using it for a trolling motor right?

The naming of Tiller might be more clear, but then i dont have a tiller but a wheel! Perhaps Rudder would be a better name then? But trolling motors dont have a rudder.

So the pid output is designed not to go to a setpoint. In my case I designed it to use it without rudder feedback. I am planning to use rudder feedback though, that would be way better for a servo. with rudder feedback the Target is a certain rudder/servo angle. Without rudder feedback, i just measure the heading deficit and rotation speed and apply more or less rudder.

So without rudder feedback, i am essentially controlling to motor, and not the rudder. So the naming of the Motor Class isnt that strange I think.

But yes, it will work in your case, but only less optimal.

— Reply to this email directly, view it on GitHub https://github.com/pieteroskam/autopilot/issues/6#issuecomment-2139751043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABP3HGSEM76S6DYJQ5BKTDZE43BXAVCNFSM6AAAAABILXL6FKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZZG42TCMBUGM . You are receiving this because you authored the thread.Message ID: @.***>

-- Matt Sargent

@.***