Log in

View Full Version : PBASIC access to 1 pin only


diego25
17-01-2002, 19:36
Hi all,

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...

Thanks,

Diego

Nate Smith
17-01-2002, 19:50
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...

Joe Johnson
17-01-2002, 20:30
See my Novi Presentation on Innovation First Hardware & Default Code.

Basically, the only direct access you have to the outside world is to flash a few LED's.

Anything more that requires going through the Master CPU on the Robot Controller.

You are the tail, you are not the dog.

Remember that and you will get along just fine.

Joe J.

diego25
17-01-2002, 20:36
Hm, yeah, that's what I was afraid of...

Ok, here's my problem:

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

IF p1_x_old < p1_x THEN skip1
PWM2 = 200
p1_x_old = p1_x
GOTO skip3
skip1:
PWM2 = 60
p1_x_old = p1_x
GOTO skip3
skip2:
PWM2 = 127
skip3:

'limits, SEROUT, etc
GOTO Mainloop


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?

Thanks!!

Diego

diego25
17-01-2002, 20:41
Originally posted by Joe Johnson
See my Novi Presentation on Innovation First Hardware & Default Code.



Thanks, I'll check it out.

Diego

Kai Zhao
17-01-2002, 20:56
3 ways (that I can think of):

-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.

diego25
17-01-2002, 21:17
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.

Thanks,

Diego

Joe Johnson
17-01-2002, 21:19
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.

Good luck.

Joe J.

diego25
17-01-2002, 21:47
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?

Thanks! Really appreciate it!

Diego

Joe Johnson
17-01-2002, 22:16
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 ;-)

Joe J.

s_alaniz
17-01-2002, 23:32
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.

diego25
21-01-2002, 08:39
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?

Thanks,

Diego

diego25
21-01-2002, 08:42
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.

Thanks,

Diego

s_alaniz
21-01-2002, 10:55
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