Go to Post As goes with all of my advice on CD, try it yourself and make up your own mind. I'm just suggesting things based on experience. See what works for your team. Follow my suggestions to the letter, mix and match them, or even throw them completely out the window. It's all about you and your team. - DampRobot [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 23-10-2014, 16:30
jman4747's Avatar
jman4747 jman4747 is offline
Just building robots
AKA: Josh
FRC #4080 (Team Reboot)
Team Role: CAD
 
Join Date: Apr 2013
Rookie Year: 2011
Location: Atlanta GA
Posts: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
Coustom Quadrature Encoder VI

I've been working on a VI to read counts from an encoder and get direction. I was looking for general feedback on it. Also, what would be a good way to get the period between pulses for a speed calculation?
Attached Thumbnails
Click image for larger version

Name:	Encoder Stuff1.JPG
Views:	79
Size:	203.4 KB
ID:	17410  
Attached Files
File Type: vi Quad encoder.vi (36.4 KB, 23 views)
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

Mentor: Rookie FTC Team "EVE" #10458, FRC Team "Drewbotics" #5812

#banthebag
#RIBMEATS
#1620
Reply With Quote
  #2   Spotlight this post!  
Unread 23-10-2014, 16:45
Aren Siekmeier's Avatar
Aren Siekmeier Aren Siekmeier is offline
on walkabout
FRC #2175 (The Fighting Calculators)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: 대한민국
Posts: 735
Aren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond repute
Re: Coustom Quadrature Encoder VI

Quote:
Originally Posted by jman4747 View Post
I've been working on a VI to read counts from an encoder and get direction. I was looking for general feedback on it. Also, what would be a good way to get the period between pulses for a speed calculation?
Every time you see a rising edge, take the difference between the current time and the previously stored time. Then store the current time over the previous to be used at the next rising edge. This difference is the period between rising edges. Then you can take a rolling average over a user-defined sample size to smooth out noise.

But how fast do you expect this loop to be running? Are you compiling this vi as part of an FPGA image, or will it run in software? Make a rough calculation of what the period of your encoder will be in your particular application, and make sure the loop containing this VI can keep up.
Reply With Quote
  #3   Spotlight this post!  
Unread 23-10-2014, 16:59
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: Coustom Quadrature Encoder VI

Quote:
Originally Posted by jman4747 View Post
I've been working on a VI to read counts from an encoder and get direction.
Why?

Your reasons for ignoring the FPGA-supported quadrature decoder and rolling your own will shape the advice I can give you.
Reply With Quote
  #4   Spotlight this post!  
Unread 23-10-2014, 17:19
jman4747's Avatar
jman4747 jman4747 is offline
Just building robots
AKA: Josh
FRC #4080 (Team Reboot)
Team Role: CAD
 
Join Date: Apr 2013
Rookie Year: 2011
Location: Atlanta GA
Posts: 418
jman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond reputejman4747 has a reputation beyond repute
Re: Coustom Quadrature Encoder VI

Quote:
Originally Posted by Alan Anderson View Post
Why?

Your reasons for ignoring the FPGA-supported quadrature decoder and rolling your own will shape the advice I can give you.
I wanted to learn how/practice. I'd rather output raw encoder counts for my distance. I can modify it to my parameters and understand what it's doing. It is easier to teach others how this works at its core. Understanding the algorithm means I can export it to another language and devise.

That said I would really like to know of better ways to implement this in LV on the C-Rio & RoboRIO.

Quote:
Originally Posted by compwiztobe View Post
But how fast do you expect this loop to be running? Are you compiling this vi as part of an FPGA image, or will it run in software?
No idea, I intend to test how it will work with different setups in the coming weeks and, didn't know about "compiling this vi as part of an FPGA image" can you elaborate?
__________________
---------------------
Alumni, CAD Designer, machinist, and Mentor: FRC Team #4080

Mentor: Rookie FTC Team "EVE" #10458, FRC Team "Drewbotics" #5812

#banthebag
#RIBMEATS
#1620
Reply With Quote
  #5   Spotlight this post!  
Unread 23-10-2014, 23:55
Aren Siekmeier's Avatar
Aren Siekmeier Aren Siekmeier is offline
on walkabout
FRC #2175 (The Fighting Calculators)
Team Role: Mentor
 
Join Date: Apr 2008
Rookie Year: 2008
Location: 대한민국
Posts: 735
Aren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond reputeAren Siekmeier has a reputation beyond repute
Re: Coustom Quadrature Encoder VI

As Alan said, if this is running on FRC hardware, you should really use the FPGA-packaged solution provided, with the interface given in WPILib.

If you need to access raw counts, the Encoder VIs should expose this (the Java and C++ libs do), though I don't have an FRC copy of Labview in front of me to confirm. If not, you can always divide distance by the distance per count you gave the Encoder Open block, though this is not ideal.

The FPGA is a large reconfigurable logic circuit (Field Programmable Gate Array). This means we can design (just about) any network of logic gates in a language like Verilog, VHDL, or even LabView (or just about any hardware description language), and then compile this "code" into an image for the FPGA. Imaging the FPGA reconfigures it to match this circuit design. This means that the operation of your "code," i.e. your circuit, is just as fast as hardware (or almost as fast), but you can still reprogram it without manufacturing an entirely new chip. However, in FRC, we are required to use the FPGA image provided by NI and FIRST, which already does a lot of useful stuff, like count encoder counts. Everything we do has to be in software on the CPU.

Encoder counts go by pretty fast. Even at FPGA processing speeds, we can't have shafts spinning anywhere upwards of 15,000 rpm for the typical US Digital encoders. Depending on a number of things, that limit is probably substantially lower, between 5,000 and 10,000. If instead of "looping" at 6 microseconds in the FPGA you want to loop at 6 milliseconds in software, your limit drops by a factor of a thousand, so now you can't spin the encoder shaft faster than about 5 or 10 rpm. And that's just not very exciting.

Last edited by Aren Siekmeier : 24-10-2014 at 00:00.
Reply With Quote
  #6   Spotlight this post!  
Unread 24-10-2014, 07:03
Greg McKaskle Greg McKaskle is online now
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,748
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: Coustom Quadrature Encoder VI

Before you set out to write your own encoder library, why not take a look at the source code to the WPILib one first?

If you drop the Encoder Get, you will find code implementing the math pretty much the way you described. If you go a level deeper into the read of the encoder counts or the times, you'll see some purple nodes that are register reads from the FPGA into the the CPU.

So the FPGA's job is to compare edges on the digital lines and increment or decrement accumulators. It records the direction and time of the last edge. The FPGA doesn't do the final math since that involves floating point and doesn't need to happen at the same rate as the comparisons.

On the roboRIO, the digital will not be limited by the module that was in the cRIO, and the digital portion of the FPGA will run much faster. The math to scale, filter, and make the counts meaningful will still happen on the CPU.

So, please look through the VI and see if the math makes sense to you. Btw, the FPGA is clocked at 40MHz, so that may help decode some contestants in the code.

Greg McKaskle
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 08:04.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi