PBASIC access to 1 pin only

Hi all,

This is my first year in FIRST, so please bear with me :slight_smile:

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

*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ā€¦

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.

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 :slight_smile: Or would a joystick-dependent voltage be the answer here?

Thanks!!

Diego

*Originally posted by Joe Johnson *
**See my Novi Presentation on Innovation First Hardware & Default Code.

**

Thanks, Iā€™ll check it out.

Diego

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.

*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 :slight_smile:

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

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.

*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 :slight_smile: Do you happen to have a picture of that kind of setup?

Thanks! Really appreciate it!

Diego

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 :wink:

Joe J.

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 :frowning: Is it possible for you to tell me which document it is in?

Thanks,

Diego

*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 :slight_smile:

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

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