This is my first year in FIRST, so please bear with me
How can I output voltage to one of the PWM pins only? If I use SEROUT, I also have to specify all the other pins, including the relay pins. More specifically, I want to use the PWM command, which requires a pin. But I donāt think the pin number for the argument is the same as the pin number on the RCā¦because the Software Handbook (.pdf) says that the Issac system (is it the PBASIC processor inside the RC?) has 8 analog outputs, but the RC has 16ā¦
*Originally posted by diego25 * Hi all,
How can I output voltage to one of the PWM pins only? If I use SEROUT, I also have to specify all the other pins, including the relay pins.
The PBASIC processor we actually program on the robot is not directly connected to the outputs of the Robot Controller, rather, it is run through an āoutput processorā within the RC. Therefore, you have to use the SEROUT command as shown within the default code to communicate with any of the outputs, relay or PWM. Due to the internal nature of the Innovation First Control System, the PWM command in PBASIC is not of much(if any!) use to usā¦just send a 0-254 value using SerOut to talk to the Speed Controllersā¦
I need some way to do timed output, i.e. output voltage for a certain amount of time only. Iām writing a program for a steering wheel. So when you move the joystick right, it turns right. When you move the joystick left, it turns left. I kind of have it working, but the problem Iām having is that I canāt control HOW MUCH the motor (that turns the wheel) turns. I was thinking of using PWM and use its cycles argument to time itā¦but I guess that wonāt work. So, how would I be able to do this?
This is my current code - it is modified from the default program:
'Beginning stuff
p1_x_old VAR BYTE
PWM2 VAR BYTE
p1_x_old = p1_X
PWM2 = 127
Mainloop:
'SERIN, etc
'My code follows
IF ABS (p1_x_old - p1_x) < 2 THEN skip2
I know Iāve got a bit of a logic error (i.e. it doesnāt take into account how much the joystick moved), but I think Iāll be able to solve that once I can get a timed output Or would a joystick-dependent voltage be the answer here?
-Make a counter. Crude example code below.
Count = Count + delta_t + 1
If count < (value)
PWM1 = 255
PWM2 = 255
goto end_drive
'if finished, do nothing
PWM1 = 127
PWM2 = 127
end_drive:
-Use the gyroscope and record your angular velocity (or is it acceleration?). Manipulate the data to suit your needs.
-What I call āCSSā. Basically, it is a wheel with sensors on or near it. See this post: http://www.chiefdelphi.com/forums/showthread.php?s=&threadid=1814
Instead of measuring forward velocity, you would want a āmagic wheelā and have it pointed sideways. Or, you can make two and put them on either side of your robot and measure the difference.
I believe the last idea is the best, but it is also the most complex.
*Originally posted by Kai Zhao *
**3 ways (that I can think of):
-Make a counter. Crude example code below.
<snip>
-Use the gyroscope and record your angular velocity (or is it acceleration?). Manipulate the data to suit your needs.
-What I call āCSSā. Basically, it is a wheel with sensors on or near it.
<snip>
**
Yup, I was thinking about putting a counter type of thing also. But I was afraid that each iteration of the mainloop will have different running times and therefore the amount of output will also be variable. Therefore, it wonāt be able to center again, when the joystick is in the middle. But again, these are just my useless newbie instincts so Iām going to try this tomorrow when I get to school
About the āCSSā, I donāt think Iāll do it that wayā¦Iād like to keep the robot simple; itās just my first year, so I donāt want to make it too complicated and end up with a non-working robot.
I donāt think you will not be successful at what you are trying to do by just timing the outputs.
You really need to use feedback.
Have a potentiometer (pot) give your program the true position of the steering.
Compare the pot value to the desired value. Calculate the sign and magnitude of the error. Multiply the magnitude of the error by a gain (you may want to multiply it by a constant and divide it by a power of 2, i.e. shift the result right N bits, this will give you the abiltiy to have a gain between 1 and 2 for example). Then if the error is greater than zero add this scaled error to 127 to get the appropriate PWM output. If the error is less than zero subtract the scaled error from 127 to get your appropriate PWM output. You have to be careful about going under 0 or over 254 with your PWM output.
Anyway, this is a very simple feedback loop (called proportional feedback). It works pretty well, especially for steering (trust me I know this to be true).
Have your finger on the e-stop button (you all have built a yellow dongle with an e-stop button havenāt you?) as you test your code because it is easy to have the steering go insane while you debug your code. You have to get the gain to have the right sign AND you have to have the gain set large enough but not too large. There are a lot of places to stub your toe, but the destination is worth the trip.
*Originally posted by Joe Johnson *
**You really need to use feedback.
Have a potentiometer (pot) give your program the true position of the steering.
<snip>
Anyway, this is a very simple feedback loop (called proportional feedback). It works pretty well, especially for steering (trust me I know this to be true).
**
I see, I see. How would I hook up the potentiometer, though? The potentiometers that Iāve worked with, are small, designed for small electronic circuitsā¦so I canāt really imagine how I can hook it up to the steering wheel. Iāll check tomorrow if weāve gotten any potentiometers from Innovation First and try to figure it out from there Do you happen to have a picture of that kind of setup?
Using a pot for a sensor is a very well documented practice in the FIRST manual and in the Innovation First documentation.
We have 100K pots at our disposal. Put 5V from the sensor port on one side of the 100K pot, ground the other side, send the wiper to the sensor pin of your hearts desire.
It is as simple as that.
As to pictures, ask around, you would have thought our swerve motors last year were related to Princess Di for all the pictures folks took of them
Diego,
I canāt tell what it is youāre trying to accomplish. Are you trying to limit how far the wheel turns? Or do you want to trigger a sequence that holds the wheel turned for some amount of time and then returns to straight? Sorry, Iām a bit muddled ā¦ I read through your program and it looks like as long as the joystick continuses to change the stering motor moves, but as soon as it stops and stays within the former cycle value Ā± 2 it stops movingā¦it works almost like a computer mouse. kind of strange butā¦okā¦ so what exactly do you want it to do?
Best Wishes
Steve Alaniz
āDid you know Einstein once stuck out his tongue for a picture?ā - Hilary Forth
āProbably expressing his opinion of houseworkā - Sally Forth as she unloads a washing machine.
*Originally posted by Joe Johnson *
**Using a pot for a sensor is a very well documented practice in the FIRST manual and in the Innovation First documentation.
**
Sorry, Iām new to this and I wasnāt able to find any documentation on using pots for a sensor in the FIRST Manual. And I checked out the documentation at Innovation Firstās website but couldnāt find it either Is it possible for you to tell me which document it is in?
*Originally posted by s_alaniz *
**Diego,
I canāt tell what it is youāre trying to accomplish. Are you trying to limit how far the wheel turns? Or do you want to trigger a sequence that holds the wheel turned for some amount of time and then returns to straight? Sorry, Iām a bit muddled ā¦ I read through your program and it looks like ā¦
<snip>
so what exactly do you want it to do?
**
Yeah, I know, my program doesnāt do what I wanted it to do; thatās why Iām asking here
If the joystick is halfway left, I want a motor to turn 45 degrees and stop. If the joystick is all the way left, I want the motor turn till 90 degrees and stop. Basically Iām trying to write a program for a steering wheel.
Yep, the advice you were given is correct. You need some kind of sensing of the wheel position to impliment the scheme youāre looking at. Potentiometer is the proven way to go, Iāll look for a scheme we used for an arm sensor last year. Weāve dismantled the robot so itās hit and miss.
Best Wishes
Steve Alaniz
" Computers are taking over? Good! Let THEM try to figure all this out for awhileā¦" - Sally Forth