|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Programming Puzzle
So I am trying to solve a programming problem that we are having with our T-Shirt cannon.
We have an analog rotation sensor that, as the cannon rotates a full rotation, the analog signal changes between 0 and 5V (linearly). My question is how I should deal with the transition between 0 to 5 volts in code. I want to be able to index the cannon so that it will snap to a position every 1/6th of the rotation. How should I do this? |
|
#2
|
||||||
|
||||||
|
Re: Programming Puzzle
1) Measure how much rotation (in degrees) you get from 0 - 5 V of your sensor. Specifically, at 0 V, set the protractor to 0 degrees. Turn your cannon to the 5V reading and read the angle on the protractor.
2) Calculate the conversion factor from voltage to degrees. Let's say in step 1 you determined that at 5 volts the angle was 270 degrees. Then your conversion factor is 270 degrees / 5 V = 54 degrees/V 3) Now in LabVIEW, multiply your sensor reading (0 - 5V) by the conversion factor calculated in step 2. This will tell your code the angle of your cannon in degrees. 4) Use a PID loop to command your motor to any angle (in degrees) you want your cannon to shoot. |
|
#3
|
||||
|
||||
|
Re: Programming Puzzle
But the problem is that I want the motor to rotate seamlessly through the 5v to 0v. For instance, if it overshoots a setpoint at 4.9 to .1, i don't want it to rotate the rest of the way around, but back up past 5v to 4.9
|
|
#4
|
||||
|
||||
|
Re: Programming Puzzle
Quote:
BTW, how much of a deadband is there ? You may need to swap out your sensor. |
|
#5
|
||||
|
||||
|
Re: Programming Puzzle
I think you misunderstand. If I was just using a simple comparator like > or < between setpoint and the analog input, and the cannon overshot past the wraparound, how do i force the cannon to go backwards instead of continuing another complete rotation to get back to the setpoint?
|
|
#6
|
||||
|
||||
|
Re: Programming Puzzle
Quote:
Can you work from there, or do you need a more detailed explanation? Again, how large is the sensor's dead zone? You may need a new sensor. |
|
#7
|
||||
|
||||
|
Re: Programming Puzzle
This zero crossing makes sense in theory but I am still unsure about how to implement it.
The dead zone is very small |
|
#8
|
|||
|
|||
|
Re: Programming Puzzle
It may be easier to think in terms of "difference between where I am and where I want to be", and write as much of your code in that reference as possible. Then you will only have to handle the wrap-around in the one spot where you calculate that value. You will need some if statements and a little bit of math - if it is calculated as past half way around in one direction, map it in the other direction.
|
|
#9
|
||||
|
||||
|
Re: Programming Puzzle
I think I found a fix, I found a zero crossing VI that I am going to try and use. Lets see how it works
|
|
#10
|
||||
|
||||
|
Re: Programming Puzzle
I don't have LabVIEW here, so I can't say for sure, but I seem to recall that the LabVIEW PID VI has an input where you can tell it that your sensor wraps around, and the VI will handle it for you. Can someone confirm? |
|
#11
|
||||
|
||||
|
Re: Programming Puzzle
I was not able to find that, but maybe i'm missing it.
I have drafted up some code that can (using the pt by pt zero crossing vi) count the number and direction of zero crossings and then calculate an integer for the number of full rotations. After that point, it simply multiplies that number by 5 and adds that to the number that it is receiving from the sensor. From that, I added PID functionality to control the spinning of the motor. We will see how it works tomorrow |
|
#12
|
||||
|
||||
|
Re: Programming Puzzle
Quote:
You may want to look into a absolute position encoder if your pot just doesn't work out. |
|
#13
|
|||||
|
|||||
|
Re: Programming Puzzle
Quote:
Last edited by plnyyanks : 21-08-2012 at 21:47. |
|
#14
|
||||
|
||||
|
Re: Programming Puzzle
Quote:
Code:
/** * Set the PID controller to consider the input to be continuous, * Rather then using the max and min in as constraints, it considers them to * be the same point and automatically calculates the shortest route to * the setpoint. * @param continuous Set to true turns on continuous, false turns off continuous */ |
|
#15
|
||||
|
||||
|
Re: Programming Puzzle
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|