Changes between Version 18 and Version 19 of ControlSystems/SoftwareTeam/Training/GettingStarted/Encoders


Ignore:
Timestamp:
Nov 8, 2019, 11:18:25 PM (6 years ago)
Author:
David Albert
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/Encoders

    v18 v19  
    3737For more information and examples of using an encoder connected to DIOs, see the [https://mililanirobotics.gitbooks.io/frc-electrical-bible/content/Sensors/opticalencoder.html FRC Electrical Bible]
    3838
    39 === Encoder connected to a TalonSRX smart motor controller (Hazelnut)
     39=== Encoder connected to a TalonSRX smart motor controller (Hazelnut, Almond)
    4040Create another program using the !TimedRobot java template and name it SRXencoderTest. Modify the generated code as follows:
    4141
    4242* Add the following imports:
    4343{{{
    44    import com.ctre.phoenix.motorcontrol.can*;
     44   import com.ctre.phoenix.motorcontrol.can.*;
    4545   import com.ctre.phoenix.motorcontrol.FeedbackDevice;
    4646}}}
    4747*  Declare a variable for the smart motor controller with connected encoder in the Robot class
    4848{{{
    49    private WPI_TalonSRX leftMotor;
     49   private WPI_TalonSRX m_Left;
    5050}}}
    5151* •     In robotInit() instantiate the motor controller object and reset it
    5252{{{
    5353   // TalonSRX is configured with CAN bus address 3
    54    leftMotor = new WPI_TalonSRX(3);
     54   m_Left = new WPI_TalonSRX(3);
    5555   // Clear any non default configuration/settings
    56    leftMotor.configFactoryDefaults();
     56   m_Left.configFactoryDefaults();
    5757   // A quadrature encoder is connected to the TalonSRX
    58    leftMotor.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder);
     58   m_Left.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder);
    5959  }}}
    6060* In robotPeriodic() read and display the encoder valuey
    6161  {{{
    62     SmartDashboard.putNumber("Encoder value", leftMotor.getSelectedSensorPosition());
     62    SmartDashboard.putNumber("Encoder value", m_Left.getSelectedSensorPosition());
    6363  }}}
    6464 
     65For the complete Robot.java see [wiki:ControlSystems/SoftwareTeam/Training/GettingStarted/Encoders/CANCode here]
     66
    6567Note: you'll need to manually turn the left wheel forward and backward to see the Encoder values change. Try turning the wheel 360 degrees to see what value is equivalent to a full revolution of the wheel. 
    6668
    67 === Quadrature Encodures
     69=== Quadrature Encoders
    6870
    69 [[Image(encAB.gif,left,250px,margin=10)]][[Image(quadEncoder2.gif,right,250px,margin=10)]]Notice that the raw count reports 2x360=720 counts per rotation.  This is because the encoders used are quadature encoders which have two channels: A, B and the sum of both A and B channels are reported.  A quadrature encoder works like the optical encoder shown above, but with two rows of slits in the disk, each slightly offset from the other (overlapping) and each with its own light source/detector.  This allows you to determine not just distance and speed but also direction.  The light detectors are labeled A and B; because the slots overlap, the sequence of detected light as the wheel rotates forward is:  A, AB, B, off, A, AB, etc.  When the wheel rotates backwards, the sequence is B, AB, A, off, B, AB, A, off. 
     71[[Image(encAB.gif,left,250px,margin=10)]][[Image(quadEncoder2.gif,right,250px,margin=10)]]Notice that the raw count reports 2x360=720 counts per rotation.  This is because the encoders used are quadrature encoders which have two channels: A, B and the sum of both A and B channels are reported.  A quadrature encoder works like the optical encoder shown above, but with two rows of slits in the disk, each slightly offset from the other (overlapping) and each with its own light source/detector.  This allows you to determine not just distance and speed but also direction.  The light detectors are labeled A and B; because the slots overlap, the sequence of detected light as the wheel rotates forward is:  A, AB, B, off, A, AB, etc.  When the wheel rotates backwards, the sequence is B, AB, A, off, B, AB, A, off. 
    7072
    7173You can read more about quadrature encoders [https://robu.in/quadrature-encoder/ here]