View Single Post
  #12   Spotlight this post!  
Unread 13-02-2013, 17:40
RyanN's Avatar
RyanN RyanN is offline
RyanN
AKA: Ryan Nazaretian
FRC #4901 (Garnet Squadron)
Team Role: Mentor
 
Join Date: Jun 2006
Rookie Year: 2005
Location: Columbia, SC
Posts: 1,126
RyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond reputeRyanN has a reputation beyond repute
Re: Shooter Lifting Code

First off, a potentiometer is not an encoder, and an encoder is not a potentiometer. They're completely different things.

A potentiometer is an analog sensor which can measure angle.



You have 3 pins normally. The left one could be your ground, center will be the signal, and the right one could be your 5V power. This sensor would plug into the analog breakout board.

The reason I say could in the previous paragraph is because you can swap them around. This would change whether the voltage rises or falls in a given direction. To put it plain and simple, a potentiometer is a voltage divider circuit. You will have a voltage from 0 to 5V based on the position of the shaft.

Normal potentiometers have about a 170˚ rotation, but I would say they are only usable for about 140˚, as there is usually a huge dead zone on either end.

Okay, so now you have a general idea on how potentiometers work. Now, how to use them?

In LabVIEW, you will have a few new things to work with...

In your begin VI, you need to open an analog channel.

Click image for larger version

Name:	Screen Shot 2013-02-13 at 4.16.46 PM.png
Views:	10
Size:	34.9 KB
ID:	13981

Here would be how to open the channel and give it a reference... Easy so far, right?

Click image for larger version

Name:	Begin.PNG
Views:	13
Size:	3.7 KB
ID:	13983

How about we place a while loop in periodic tasks. What we're going to do is make a PID control loop. This is what is called closed loop control. You have a sensor giving direct feedback to the system in order to control the motor.

I'm going to change your local variable (represented with the home symbol in the first picture you provided) to a global variable. This means, you can set this variable globally (anywhere) in your code. However, this also gives you another responsibility. You cannot set global variables from more than one place in the code at a single time.

An appropriate use of a global variable would be from autonomous and from teleoperated code. However, an inappropriate use would be setting this value multiple times such as from teleop two or three more times. Basically what I'm getting to... this global variable should only show up at most 3 times in all of your code.
  1. Autonomous Independent.vi
  2. Teleop.vi
  3. Periodic Tasks.vi

First, lets create that global variable.

Double click on Robot Global Data.vi in the Project Explorer.

Click image for larger version

Name:	Project Explorer.PNG
Views:	6
Size:	26.7 KB
ID:	13984

You want to add a numeric control.

Click image for larger version

Name:	Screen Shot 2013-02-13 at 4.28.55 PM.png
Views:	8
Size:	64.1 KB
ID:	13985

It will default to a floating point (double). This is fine for what we want to do. At this point, we need to define what DesiredLevel is... Is it an angle? Is it the voltage being fed back from the potentiometer? For the sake of time and for simplicity of this demo, we'll make it represent a voltage from 0 to 5 volts.

Click image for larger version

Name:	Robot Global Data.PNG
Views:	7
Size:	30.1 KB
ID:	13986

More to come...
__________________
Garnet Squadron
FRC 4901
Controls Mentor
@rnazaretian

Previous mentor and student from Team Fusion, FRC 364
Reply With Quote