![]() |
Using a switch to control a PWM
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 |
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. |
Re: Using a switch to control a PWM
Quote:
Try a simpler test like: Code:
if (p2_sw_trig)[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! |
Re: Using a switch to control a PWM
Quote:
|
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 GearHope this helps. Phil |
Re: Using a switch to control a PWM
Quote:
|
Re: Using a switch to control a PWM
Quote:
|
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.
|
Re: Using a switch to control a PWM
Quote:
|
Re: Using a switch to control a PWM
Does it work with a Victor?
|
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?
|
Re: Using a switch to control a PWM
Quote:
|
| All times are GMT -5. The time now is 04:24. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi