Pages: [1]   Go Down
Author Topic: steering question  (Read 611 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to change up some arduino code to accept potentiometer input for variable turn rate. This is what I have right now but I can only tell it turn or dont turn. I need help adding the potentiometer part to it.

 //steer one way        SteerValue of 512 is straight ahead
  if (k2 == 1) {
              if (gangleratedeg2 < 5) {    //will turn clockwise at 5 degrees per sec and if not, more power fed into steering until it does
                                           SteerValue = SteerValue + 1;
                                                    }
              if (gangleratedeg2 > 5) {
                                           SteerValue = SteerValue - 1;
                                                    }               
              }
 //change the 5 and -5 values if you want faster turn rates. Could use a potentiometer to control these values so would have proportional control of steering       
             
 //steer the other way           
  if (k3 == 1) {
              if (gangleratedeg2 < -5) {    //will turn anticlockwise at 5 degrees per sec and if not, more power fed into steering until it does
                                           SteerValue = SteerValue + 1;
                                                    }
              if (gangleratedeg2 > -5) {
                                           SteerValue = SteerValue - 1;
                                                    }
              } 
   
    if (SteerValue < 1) {
                    SteerValue = 1;
                        }
    if (SteerValue > 1023) {
                    SteerValue = 1023;
                           } 
   
    SteerCorrect = 0;
    }   
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26293
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Difficult to say from such a brief snippet of code (please use the # icon in the editor's toolbar when posting code), but I think you're going to need to look at "analogRead" and "map".
http://arduino.cc/en/Reference/AnalogRead
http://arduino.cc/en/Reference/Map
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

South Louisiana
Offline Offline
Full Member
***
Karma: 0
Posts: 180
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Assuming you are using a servo (because your adjustments are listed in degrees) this page may also help.

http://www.arduino.cc/playground/ComponentLib/Servo
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a link to the entire code I am using. http://sites.google.com/site/onewheeledselfbalancing/Home/easy-build-low-cost-arduino-self-balancer
Logged

Pages: [1]   Go Up
Jump to: