Changes between Version 18 and Version 19 of ControlSystems/SoftwareTeam/Training/GettingStarted/Encoders
- Timestamp:
- Nov 8, 2019, 11:18:25 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/Encoders
v18 v19 37 37 For 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] 38 38 39 === Encoder connected to a TalonSRX smart motor controller (Hazelnut )39 === Encoder connected to a TalonSRX smart motor controller (Hazelnut, Almond) 40 40 Create another program using the !TimedRobot java template and name it SRXencoderTest. Modify the generated code as follows: 41 41 42 42 * Add the following imports: 43 43 {{{ 44 import com.ctre.phoenix.motorcontrol.can *;44 import com.ctre.phoenix.motorcontrol.can.*; 45 45 import com.ctre.phoenix.motorcontrol.FeedbackDevice; 46 46 }}} 47 47 * Declare a variable for the smart motor controller with connected encoder in the Robot class 48 48 {{{ 49 private WPI_TalonSRX leftMotor;49 private WPI_TalonSRX m_Left; 50 50 }}} 51 51 * • In robotInit() instantiate the motor controller object and reset it 52 52 {{{ 53 53 // TalonSRX is configured with CAN bus address 3 54 leftMotor= new WPI_TalonSRX(3);54 m_Left = new WPI_TalonSRX(3); 55 55 // Clear any non default configuration/settings 56 leftMotor.configFactoryDefaults();56 m_Left.configFactoryDefaults(); 57 57 // A quadrature encoder is connected to the TalonSRX 58 leftMotor.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder);58 m_Left.configSelectedFeedbackSensor(FeedbackDevice.QuadEncoder); 59 59 }}} 60 60 * In robotPeriodic() read and display the encoder valuey 61 61 {{{ 62 SmartDashboard.putNumber("Encoder value", leftMotor.getSelectedSensorPosition());62 SmartDashboard.putNumber("Encoder value", m_Left.getSelectedSensorPosition()); 63 63 }}} 64 64 65 For the complete Robot.java see [wiki:ControlSystems/SoftwareTeam/Training/GettingStarted/Encoders/CANCode here] 66 65 67 Note: 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. 66 68 67 === Quadrature Encod ures69 === Quadrature Encoders 68 70 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 quad ature 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. 70 72 71 73 You can read more about quadrature encoders [https://robu.in/quadrature-encoder/ here]