Go Down

Topic: skipping my line (Read 167 times) previous topic - next topic

HYPERformance

Jan 17, 2020, 06:56 am Last Edit: Jan 17, 2020, 07:04 am by HYPERformance
every time i run this code it will run my 20% ramp, the two 5 second delays and then the 100%.
why is it completely skipping my 60% ramp?


Code: [Select]
#include <RBD_Timer.h>
#include <RBD_Motor.h>
 
RBD::Motor motor(3); // PWM pin
 
void setup() {
  delay(0);                // Delay box
                                //Logan first yellow (1290)
                                //Logan Third yellow (0320)
                               
  motor.rampPercent(20, 1000); // Launch control
                                // Use motor.setSpeedPercent(10) "hits power instantly 10%"
                                // Use motor.rampPercent(20, 300) "ramps up to 0-20% in .3 seconds"
}
 
void loop() {
  motor.update();
   
    if(motor.onTargetSpeed()) {
    delay(5000);                     // Time between launch control and power adder
   
    motor.rampPercent(60, 1000);     // Power after launch to mid track
                                     // use motor.rampPercent(60, 1000) "ramps up to 60% in 1.0 seconds"
                                     
    delay(5000);                     // Time between mid track and next power adder
   
    motor.rampPercent(100, 1000);    // Power after mid track to finish
                                     // use motor.rampPercent(100, 1000) "ramps up to 100% in 1.0 seconds"   

blh64

Auto Format your code (Ctrl-T) and it will help you figure out the problem.

For starters, you don't have an ending '}' for loop()

If motor.onTargetSpeed() returns false, none of your code gets executed, including the 60% ramp.

gcjr

add some Serial.prints to confirm what code is actually executing rather than make assumption based on what you observe the motor doing?
greg - somerset, nj

HYPERformance

Auto Format your code (Ctrl-T) and it will help you figure out the problem.

For starters, you don't have an ending '}' for loop()

If motor.onTargetSpeed() returns false, none of your code gets executed, including the 60% ramp.
I have the ending } I just missed it while I was copying it. I'll try (Ctrl-t) when I get off work. Thanks for the input.

TheMemberFormerlyKnownAsAWOL

Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

boolrules

What does motor.update( ) do?

lastchancename

I suspect the motor.update() call, refreshes the motor control and status registers.
Each time around loop, the delay() calls are going to delay those updates, and I have no idea how that will affect the motion and control functionality.

It may be time to look into millis() timing and possibly a simple state-machine to move between the different phases of operation.
Experienced responders have a nose for laziness, (they were beginners once)... Sure, there are trolls, chest-beaters, and pretenders - but the help you'll get here is about as good as it gets - if you try to help youself!.

Go Up