-
Notifications
You must be signed in to change notification settings - Fork 69
PR: Add support for L298N driver #54
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,11 +124,12 @@ Use the Rate potentiometer to move the arm up/down. | |
| # define pin_AD 13 // Amp Down - not used when you have potentiometers | ||
| # define pin_AU 13 // Amp Up - not used when you have potentiometers | ||
| # define curr_sense false // o no current sensor | ||
| # define control_with_pot true // 1 = control with potentiometers 0 = with push buttons | ||
| # define control_with_pot true // 1 = control with potentiometers 0 = with push butto | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert |
||
| # define FF 10 // motion control feed forward | ||
| # define KP 3 // motion control propportional gain | ||
| #>>>>>>> master | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conflicts leftovers |
||
| # define KI 1 // motion control integral gain | ||
| # define integral_limit 5 // limits the integral of error | ||
| # efine integral_limit 5 // limits the integral of error | ||
| # define f_reduction_up_val 0.80 // reduce feedforward by this factor when moving up | ||
| #else | ||
| // FULL_CONFIGURATION == false: no potentiometers for User Interface, feedback pot on pulley. | ||
|
|
@@ -161,7 +162,13 @@ Use the Rate potentiometer to move the arm up/down. | |
| #define pin_FRQ 3 // analog pin of rate potentiometer control | ||
| #define pin_PRE 6 // analog pin of pressure potentiometer control | ||
|
|
||
| // Talon SR or SPARK controller PWM settings ("angle" for Servo library) | ||
| // L298N specific | ||
| #define L298N false | ||
| #define pin_SPEED 7 // analog | ||
| #define pin_FORWARD 5 // digital | ||
| #define pin_BACK 3 // digital | ||
|
|
||
| // Talon SR or SPARK controller PWM settings ("angle" for Servo library | ||
| #define PWM_mid 93 // was 93 - mid value for PWM 0 motion - higher pushes up | ||
| #define PWM_max 85 | ||
| #define PWM_min -85 | ||
|
Comment on lines
+165
to
174
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Insert the motor's def to |
||
|
|
@@ -362,19 +369,32 @@ enum main_states state; | |
| /// @return None | ||
| void setup() | ||
| { | ||
| if (L298N) | ||
| { | ||
| pinMode(pin_SPEED, OUTPUT); | ||
| pinMode(pin_FORWARD, OUTPUT); | ||
| pinMode(pin_BACK, OUTPUT); | ||
| } | ||
|
|
||
| pinMode(pin_PWM, OUTPUT); | ||
| pinMode(pin_FD, INPUT_PULLUP); | ||
| pinMode(pin_FU, INPUT_PULLUP); | ||
| pinMode(pin_AD, INPUT_PULLUP); | ||
| pinMode(pin_AU, INPUT_PULLUP); | ||
| pinMode(PIN_SW2, INPUT_PULLUP); | ||
| pinMode(pin_TST, INPUT_PULLUP); | ||
| pinMode(pin_LED_AMP, OUTPUT); | ||
| pinMode(pin_LED_FREQ, OUTPUT); | ||
| pinMode(pin_LED_Fail, OUTPUT); | ||
| pinMode(pin_USR, OUTPUT); | ||
|
Comment on lines
+386
to
+389
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those aren't supposed to exist anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nimrod Nimrod define pin_RST 5 |
||
| if (!L298N) | ||
| { | ||
| motor.attach(pin_PWM); | ||
| } | ||
| pinMode(pin_LED_RED, OUTPUT); | ||
| pinMode(pin_LED_GREEN, OUTPUT); | ||
| // pinMode(pin_LED_BLUE, OUTPUT); //TODO: Return if needed | ||
| pinMode(pin_LED_USR, OUTPUT); | ||
| motor.attach(pin_PWM); | ||
|
|
||
| Serial.begin(115200); | ||
| Serial.print("\nAmboVent Version: "); | ||
| Serial.println(VERSION_STR); | ||
|
|
@@ -1009,7 +1029,31 @@ void set_motor_PWM(float wanted_vel_PWM) | |
| if (wanted_vel_PWM < PWM_min) | ||
| wanted_vel_PWM = PWM_min; // limit PWM | ||
| motorPWM = PWM_mid + int(wanted_vel_PWM); | ||
| motor.write(motorPWM); | ||
|
|
||
| if (L298N) | ||
| { | ||
| if (motorPWM > PWM_mid + 3) | ||
| { // leave a -3 to +3 stop range | ||
| digitalWrite(pin_FORWARD, HIGH); | ||
| digitalWrite(pin_BACK, LOW); | ||
| } | ||
| else if (motorPWM < PWM_mid - 3) | ||
| { // leave a -3 to +3 stop range | ||
| digitalWrite(pin_FORWARD, LOW); | ||
| digitalWrite(pin_BACK, HIGH); | ||
| } | ||
| else | ||
| { | ||
| digitalWrite(pin_FORWARD, LOW); | ||
| digitalWrite(pin_BACK, LOW); | ||
| } | ||
|
|
||
| analogWrite(pin_SPEED, map(motorPWM, PWM_min, PWM_max, 0, 25)); | ||
| } | ||
| else | ||
| { | ||
| motor.write(motorPWM); | ||
| } | ||
| } | ||
|
|
||
| int read_motion_for_calib() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this change do and why was it required?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not my change but let me explain the pwm driver used up until now is a 40$ part the LM298N module is is a 2$ part it is not 10amps but even if you use a https://www.cytron.io/p-10amp-5v-30v-dc-motor-driver it is 10$ . To me dropping bom cost by 30$ or 35$ is a good reason.
As this is community Funded you need to Lower the BOM as far as possible.
Using 20$ pcbs for the TI sensor not 60$ Using PWM PCB that are High Volume not made
for REX Robotics for kids
https://www.cytron.io/p-10amp-5v-30v-dc-motor-driver 10$ (My option)
https://www.4project.co.il/product/l298n-module 5$ ( I do not know if 2amp will do)
2$ from Aliexpress type places.
https://www.revrobotics.com/rev-11-1200/ 40$
Note The Two Top option need PWM on 2 pins and care to create dead time . It Saves 30-35$ on the BOM . The Two Top options are far more of the Shelf Items.
Sorry For the Slow reply. Take a good look at this Project and the BOM costs
https://scitechdaily.com/easy-to-build-75-open-source-arduino-ventilator-with-high-quality-performance/ (it is CPAP I doubt the include the mask in 75$)
Note Today the funds to make 20 units stands on 4260$ Just over 200$ .two weeks into the campaign. To save 600$ on the 20 units for me is worth while and also off the mass produced if they get made.
Note 3v Level shift has been added to the pcb