Go Down

Topic: ArduKart Question for ramping speed (Read 1 time) previous topic - next topic

415porto

8) I built my son a go-kart.  It has two buttons on the steering wheel one for Forward and one for reverse.  Basically when you hold down one of the buttons it ramps up to full speed in either direction.  When you release the button the Kart should ramp down or just release control of the motor controllers. 

The problem I am having is when the button is pressed the Kart stays at that speed.  It doesn't ramp down or stop controlling the motor controllers (coast).

8)

Code: [Select]

#include <Servo.h>
#include <Button.h>


/*
ArduKart

This program was written for an Arduino powered GoKart. 

Press GO and the kart with ramp up to top speed
This is done through PWM to a motor controller
Press REV and the kart will go into reverse with a preset max speed
This is also done through PWM to a motor controller

This shit is pretty dope!!!!!!

*/


Servo leftMotor;
Servo rightMotor;

Button goButton(8,PULLUP);
Button revButton(7,PULLUP);



int goPos = 90;         //puts motor controllers @ 90 degrees (neutral)
int revPos = 90;        //puts motor controllers @ 90 degrees (neutral)
int rampSpeed = 0;      //time it takes to ramp up to full speed



void setup() 
{
  Serial.begin (9600);
  leftMotor.attach(9);      // left motor controller connected to digital pin 9
  rightMotor.attach(10);      // right motor controller connected to digital pin 10


}



void loop() 
{
 

  //delay(100);                      //delay for testing
  if(goButton.isPressed())
  {
    if (goPos < 180) {goPos ++;}
    if (goPos > 180)  {goPos = 180;}
    leftMotor.write(goPos);
    rightMotor.write(goPos);
    delay(rampSpeed);
  }
 
  else
    {
      goPos = 90;
    }
 
 
if(revButton.isPressed())
  {
    if (revPos <= 90) {revPos --;}
    if (revPos < 0)  {revPos = 0;}
    leftMotor.write(revPos);
    rightMotor.write(revPos);
   
  }
 
  else
    {
      revPos = 90;
    }
 
 

 
 
 

   
  Serial.print("Reverse Postion:");
  //Serial.print('\t');
  Serial.print(revPos);
  Serial.print('\n');
 
  Serial.print("Go Position:");
  //Serial.print('\t');
  Serial.print(goPos);


}



mstanley

With just a very quick look at your code I would say that a rampSpeed setting of zero would reach max speed in less than a millisecond.

PaulS

All the white space and random indents in your code make it hard to read. The vulgarity at the beginning makes it unpleasant. Clean up your act.
The art of getting good answers lies in asking good questions.

Go Up