Log in

View Full Version : Switch with Servo


pras870
01-03-2003, 23:37
I was wondering i there was anyway to program a servo to be activated on a rocker switch instead of with a petentiometer, such as have it rotate 180 degrees or something?

rust710
01-03-2003, 23:44
servo = 127
if sw1 = 1 then servo = 254
if sw2 = 1 then servo = 0

pras870
01-03-2003, 23:53
you're positive this would work? i've been argueing with our programmer that it is possible.

Greg Ross
02-03-2003, 00:47
Originally posted by rust710
servo = 127
if sw1 = 1 then servo = 254
if sw2 = 1 then servo = 0
Originally posted by pras870
you're positive this would work? i've been argueing with our programmer that it is possible.
With this code, the servo will normally be in a centered position, and whenever the rocker switch is thrown, the servo will turn to the corresponding extreme. The servo will return to the centered position whenever the rocker switch is in its centered position.

If you would rather have the servo only go from one extreme to the other, you might want something more like this:

servo = 0

main_loop:
...
if sw1 = 1 then servo = 254
if sw2 = 1 then servo = 0

EricS-Team180
03-03-2003, 12:23
YEP...

We used just that to activate a "brake" pin in our gearboxes last year....works fine...

JLambert
03-03-2003, 13:39
Originally posted by EricS-Team180
YEP...

We used just that to activate a "brake" pin in our gearboxes last year....works fine...

Our team did the same thing two years ago, and we're doing it this year too. It works great.

pras870
10-03-2003, 14:33
we're using a rocker switch. Right now the code we have is this:

p1_wheel = 0
if p3_sw_aux2 = 0 then p1_wheel = 0
if p3_sw_aux2 = 1 then p1_wheel = 63

since the servo is on PWM 9 we're using p1_wheel variable, but yusing the roboemu program, the wheel on the joystick moves the server but not aux2, any help would be appreciated.

rbayer
10-03-2003, 17:33
Originally posted by pras870
we're using a rocker switch. Right now the code we have is this:

p1_wheel = 0
if p3_sw_aux2 = 0 then p1_wheel = 0
if p3_sw_aux2 = 1 then p1_wheel = 63

since the servo is on PWM 9 we're using p1_wheel variable, but yusing the roboemu program, the wheel on the joystick moves the server but not aux2, any help would be appreciated.


If you email me your code, I'd be happy to take a look. RoboEmu doesn't currently have any known issues that would affect code like the stuff you posted, so it's probably a line somewhere farther down overriding your code. Anyways, let me know. rob-bayer@mn.rr.com

pras870
11-03-2003, 09:56
I also found out today that any wheel on a joystick controls p1_wheel, it's strange if you ask me.

Greg Ross
12-03-2003, 02:53
Originally posted by pras870
I also found out today that any wheel on a joystick controls p1_wheel, it's strange if you ask me.
Pras,

There's just not enough info to go on here. I suggest you do as Rob suggests, and send him your code. Better yet, post it here, and you can have a bunch more pair of eyes looking at it at the same time.