Log in

View Full Version : Non-variable Victor Control


Madison
30-01-2002, 15:07
Simple question for you all:

How can we program the RC to operate the Victor's with a toggle switch?

In other words, we want the speed controller to be on (255) when the switch is on, or off (127) when it's not.

Simple in concept, but our brain trust hasn't been able to make it work in practice.

Your help, as always, is appreciated.

Matt Leese
30-01-2002, 15:44
Assume you're using PWM7.

if button_pressed then toggleOn
PWM7 = 127
goto endToggle
toggleOn:
PWM7 = 254
endToggle

Make sure that you actually pass the PWM value through to the SerOut command (look at the sample for what to send). Also, make sure to limit the value to 254 and not 255. 255 is not a valid output value. The above is mostly in psuedocode but you should be able to figure the rest out.

Matt

Manoel
30-01-2002, 16:18
Try this:

Declare nice_motor as a variable byte
Then state that:
nice_motor = 127 + (127*button1) - (127*button2)

And of course, serout nice_motor to the desired PWM pin

What will happen:

If button 1 is pressed, the motor will go full forward, if button 0 is pressed, it'll go full reverse, and if you press them both (who would do that? :) ), nothing happens.

Ian W.
30-01-2002, 16:27
In case you can't tell, I'm on the same team as Micheal. I'm the main programmer, and I have to say, THANK YOU!!!! Now, we can do something that we think is pretty cool, and we can use cool toggle switches too :D. If you guys are going to the L.I, N.Y.C., or nationals, you'll see why we need the toggle switch controlled pwms. Other than that, if I say anything else, my team members will kill me. So, once again, thanks a whole lot, and good luck to all!

Ian W.
30-01-2002, 16:29
Well, I understood the nice little if statement one (by matt), but the second one makes no sense to me. Sorry if I sound mean, but this is my first year doing PBASIC, and I want to keep it simple. We tried the first solution, and it worked. When we tried to make it work before, we set it to switch the pwm to 255, where as it can only go to 254 (thanks matt). So, end result, problem fixed, controllers of team #810 happy. :D

Joseph F
30-01-2002, 17:43
(assume victor is connected to the port for p4_wheel)

if fswitch = 1 goto move
p4_wheel = 127
goto nomove
move:
p4_wheel = 256
nomove:

also would this work better/worse if there was/wasn't a joystick plugged into port 4?

Ian W.
30-01-2002, 18:18
Well, I made it work using Matt's solution, mostly because that's the simplest (to me at least), because this is the first year I've ever used PBASIC before. I'm surprising myself with how well I already know it (I'm currently the team 810 PBASIC Guru, so t speak), but I still want to keep the program simple.

Another reason why it's easy to keep simple, the motors only have to go foward and off, they don't need to be reversed. This might give a clue to some of you what we're doing, but I'm not telling :D. If you want to see the secret, you'll have to wait until the L.I. regional. Once again, thanks for all the help. This is one of the best forums I've ever been to, I get a response so fast. :)

Matt Leese
30-01-2002, 18:57
Originally posted by Joseph F
(assume victor is connected to the port for p4_wheel)

if fswitch = 1 goto move
p4_wheel = 127
goto nomove
move:
p4_wheel = 256
nomove:

also would this work better/worse if there was/wasn't a joystick plugged into port 4?
Don't use 256! 256 is equivalent to 0 (the byte will wrap around to zero).

Matt

Ian W.
30-01-2002, 19:07
Don't worry, I'm not using 256. Someone told me it resets the RC, so I've stayed away from it always. 255 I thought was full power, although I guess I'm wrong. Oh well, learn from your mistakes.

Kai Zhao
30-01-2002, 20:26
Originally posted by Ian W.
Don't worry, I'm not using 256. Someone told me it resets the RC, so I've stayed away from it always. 255 I thought was full power, although I guess I'm wrong. Oh well, learn from your mistakes.

Never use 255. IIRC, two 255's sent in a row is the Main CPU reset signal or something malicious of the kind. Use 254.

Not like it matters anyway. 218 (?) to 254 is all full power, if I remember. And 0 - 36 (?) is all full power. I'm not too sure about the exact values and its something that Dr. Joe would know.

Ian W.
30-01-2002, 21:05
Really? I did not know that. I thought a number of 256 would reset the uP. Hmm, maybe that's why our relays flipped out when we flipped the switch. Oh well, no damage done (I hope). Thanks for all the help, cause now our little sercret works. :D

Joseph F
30-01-2002, 22:13
Originally posted by Matt Leese

Don't use 256! 256 is equivalent to 0 (the byte will wrap around to zero).

Matt

I meant to say 254. It's been a long day and I havn't downloaded any sleep lately. With that same code but a 254 instead of a 256 would it work without serout editing? would it work better/worse/not at all if a joystick was/wasn't attached to the port

Manoel
30-01-2002, 22:29
Originally posted by Ian W.
Another reason why it's easy to keep simple, the motors only have to go foward and off, they don't need to be reversed.

Then simplify the formula to

nice_motor = 127 + (button * 127)

:)

Joe Johnson
30-01-2002, 22:57
Wow! That was great!

The question was posted at 3:00 and by 11:00 we are all a lot smarter.

This is why I love these forums.

Well done, FIRST online folks.

Keep up the good work.

Joe J.

Ian W.
31-01-2002, 15:17
Yes, I have to agree with Joe. I've pretty much self-taught myself PBASIC over the past two or three weeks. Yeah, it's a bit late to be learning it, but someone else who was supposed to do the programming dropped out. But me and my friend looked through the default code, learned literally every line of that (took about an hour or two), and after that went on to alter the code to our needs. So far, it hasn't been that hard, the math is kind of annoying though. But the coolest thing is that whenever I have a problem, I can just come here and I have an answer right away. Yay for online forums! Now I just wish my team's forums were as active...:D

Madison
31-01-2002, 15:30
Uh oh, this is turning into a CD lovefest! :)

Seriously, though, thanks for the help. I have no experience with the programming at all, so being any sort of help to the team has been nearly impossible for me.

If I had my way, our robot would have one giant wind up motor.

Ian W.
31-01-2002, 15:35
Don't give away our design! :D But seriously, you have to love Chief Delphi :)