|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
I do know C but i am not directly involved with programming, so i apologize if i don't know some obvious things. We are trying to have two switches move a servo (PWM controlled) between two different values. I assumed this would be as simple as checking the status of the button every iteration of the loop and then assigning a certain value to the PWM via an if statement.
if(p1_sw_some_switch == 1){ pwmxxx=some_value } if(p1_sw_some_other_switch == 1) { pwmxxx=some_other_value This appears to not be working (ie buttons do not move the servo at all, do the servo does appear to twitch when the OI or the RC is turned on) so my first thought was that maybe the switch takes values other than 0 and 1 like maybe 0 and 255, etc. Any help would be much appreciated |
|
#2
|
||||||
|
||||||
|
Re: Using a switch to control a PWM
your code is correct, do you have the backup battery installed?
You may want to do something for you other conditions, though, such as if neither button is pressed or if both buttons are pressed. |
|
#3
|
|||||
|
|||||
|
Re: Using a switch to control a PWM
Quote:
Try a simpler test like: Code:
if (p2_sw_trig) pwmxxx = 254; else pwmxxx = 0; [edit] Joe Ross beat me to an answer. Hey, Ken W. my typing must be slowing down! ![]() [edit 2] deltacoder corrected my reversal of the joystick button values. (I also get left and right confused). Thanks delta! Last edited by Mark McLeod : 25-02-2004 at 14:22. |
|
#4
|
||||
|
||||
|
Re: Using a switch to control a PWM
Quote:
|
|
#5
|
||||
|
||||
|
Re: Using a switch to control a PWM
If the servo is "twitching" just on the startup of the code then you are okay.
This is just the servo going to it's initial position. If the Servo is always twitching it might be a low backup battery. For a transmission shifter you are best to have it on one switch. 0=low gear, 1=high gear Also, make sure to stop the motorfor a few loops before shifting, and start the motors back up (to selected speed) after th3e servo has had a chance to move. The psuedocode would look like this Code:
// Motor speed 160 In Low Gear Shift button changed // have static store last value Store Motor Speed // in static for later use Stop Motor // 127, neutral Move Servo // 0-254 or 254-0 count loops for 10 (.2 secs, servo moves full throw in .11) Start Motor // Shift on the fly, You got to love it Hope this helps. Phil Last edited by Phil_Lutz : 25-02-2004 at 11:13. Reason: change text |
|
#6
|
||||
|
||||
|
Re: Using a switch to control a PWM
Quote:
|
|
#7
|
||||
|
||||
|
Quote:
|
|
#8
|
|||
|
|||
|
Re: Using a switch to control a PWM
I haven't used the servos w/ the new control system, but when I have worked with servo's in the past, twitching can also be caused by pushing the servo out of the position you are trying to set it to. The internals of the servo have a potentiometer and simple control circuitry to move the servo to a cooresponding value based on the pot. If you try to move it out of the position, it will try to move back.
|
|
#9
|
||||
|
||||
|
Re: Using a switch to control a PWM
Quote:
|
|
#10
|
|||||
|
|||||
|
Re: Using a switch to control a PWM
Does it work with a Victor?
|
|
#11
|
||||
|
||||
|
Re: Using a switch to control a PWM
wow, i feel really really dumb, its because we were setting something to 255 not 254, isnt it?
|
|
#12
|
|||||
|
|||||
|
Re: Using a switch to control a PWM
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Some EDURobotics Problems | squide | Robotics Education and Curriculum | 9 | 20-01-2004 10:27 |
| pwm 13-15 | wayne 05 | Programming | 2 | 04-10-2003 12:08 |
| switch speed control | wayne 05 | Programming | 6 | 01-10-2003 09:35 |
| PWM and burning out motors | patrickrd | Technical Discussion | 7 | 19-06-2003 15:30 |
| Need help with 255 Variable | Joseph F | Programming | 18 | 26-02-2002 14:49 |