Skip to content

Commit

Permalink
Jogilber/improve sensor experience (#9)
Browse files Browse the repository at this point in the history
* Change encoder values to higher-count ticks, and then additionally convert those ticks to inches in the pose subsystem

* Add default shuffleboard

* Use newer commonlib

* use newer commonlib

* Better names for motors
  • Loading branch information
JohnGilb authored Feb 3, 2021
1 parent 11be7af commit 7fecbff
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 15 deletions.
143 changes: 143 additions & 0 deletions shuffleboard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"tabPane": [
{
"title": "LiveWindow",
"autoPopulate": true,
"autoPopulatePrefix": "LiveWindow/",
"widgetPane": {
"gridSize": 128.0,
"showGrid": true,
"hgap": 16.0,
"vgap": 16.0,
"tiles": {
"0,0": {
"size": [
2,
4
],
"content": {
"_type": "Subsystem Layout",
"_source0": "network_table:///LiveWindow/PoseSubsystem",
"_title": "PoseSubsystem",
"Layout/Label position": "BOTTOM",
"_children": []
}
},
"2,0": {
"size": [
2,
4
],
"content": {
"_type": "Subsystem Layout",
"_source0": "network_table:///LiveWindow/AutonomousCommandSelector",
"_title": "AutonomousCommandSelector",
"Layout/Label position": "BOTTOM",
"_children": []
}
},
"4,0": {
"size": [
2,
4
],
"content": {
"_type": "Subsystem Layout",
"_source0": "network_table:///LiveWindow/DriveSubsystem",
"_title": "DriveSubsystem",
"Layout/Label position": "BOTTOM",
"_children": []
}
},
"6,0": {
"size": [
2,
4
],
"content": {
"_type": "Subsystem Layout",
"_source0": "network_table:///LiveWindow/Ungrouped",
"_title": "Ungrouped",
"Layout/Label position": "BOTTOM",
"_children": []
}
}
}
}
},
{
"title": "Basic Sensors",
"autoPopulate": false,
"autoPopulatePrefix": "",
"widgetPane": {
"gridSize": 128.0,
"showGrid": true,
"hgap": 16.0,
"vgap": 16.0,
"tiles": {
"3,1": {
"size": [
2,
1
],
"content": {
"_type": "Text View",
"_source0": "network_table:///SmartDashboard/LeftDrive/LeftLeader/position",
"_title": "SmartDashboard/LeftDrive/LeftLeader/position"
}
},
"3,2": {
"size": [
1,
1
],
"content": {
"_type": "Text View",
"_source0": "network_table:///SmartDashboard/PoseSubsystem/CurrentHeading",
"_title": "SmartDashboard/PoseSubsystem/CurrentHeading"
}
},
"5,1": {
"size": [
2,
1
],
"content": {
"_type": "Text View",
"_source0": "network_table:///SmartDashboard/RightDrive/RightLeader/position",
"_title": "SmartDashboard/RightDrive/RightLeader/position"
}
},
"3,0": {
"size": [
2,
1
],
"content": {
"_type": "Text View",
"_source0": "network_table:///SmartDashboard/LeftDrive/LeftLeader/voltage",
"_title": "SmartDashboard/LeftDrive/LeftLeader/voltage"
}
},
"5,0": {
"size": [
2,
1
],
"content": {
"_type": "Text View",
"_source0": "network_table:///SmartDashboard/RightDrive/RightLeader/voltage",
"_title": "SmartDashboard/RightDrive/RightLeader/voltage"
}
}
}
}
}
],
"windowGeometry": {
"x": -1288.0,
"y": -9.0,
"width": 1296.0,
"height": 1000.0
}
}
20 changes: 9 additions & 11 deletions src/main/java/competition/subsystems/drive/DriveSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,31 @@ public class DriveSubsystem extends BaseDriveSubsystem {
public final XAnalogDistanceSensor distanceSensor2;

int i;
private final double simulatedEncoderFactor = 256.0 / Math.PI;

@Inject
public DriveSubsystem(CommonLibFactory factory, XPropertyManager propManager) {
log.info("Creating DriveSubsystem");

this.leftLeader = factory
.createCANTalon(new CANTalonInfo(1, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, 1));
.createCANTalon(new CANTalonInfo(1, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, simulatedEncoderFactor));
this.leftFollower1 = factory
.createCANTalon(new CANTalonInfo(3, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, 1));
.createCANTalon(new CANTalonInfo(3, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, simulatedEncoderFactor));
this.leftFollower2= factory
.createCANTalon(new CANTalonInfo(5, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, 1));
.createCANTalon(new CANTalonInfo(5, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, simulatedEncoderFactor));

this.rightLeader = factory
.createCANTalon(new CANTalonInfo(2, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, 1));
.createCANTalon(new CANTalonInfo(2, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, simulatedEncoderFactor));
this.rightFollower1 = factory
.createCANTalon(new CANTalonInfo(4, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, 1));
.createCANTalon(new CANTalonInfo(4, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, simulatedEncoderFactor));
this.rightFollower2 = factory
.createCANTalon(new CANTalonInfo(6, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, 1));

leftLeader.createTelemetryProperties(this.getPrefix(), "LeftLeader");
rightLeader.createTelemetryProperties(this.getPrefix(), "RightLeader");
.createCANTalon(new CANTalonInfo(6, true, FeedbackDevice.CTRE_MagEncoder_Absolute, true, simulatedEncoderFactor));

this.distanceSensor = factory.createAnalogDistanceSensor(1, VoltageMaps::sharp0A51SK);
this.distanceSensor2 = factory.createAnalogDistanceSensor(2, VoltageMaps::sharp0A51SK);

XCANTalon.configureMotorTeam("LeftDrive", "LeftLeader", leftLeader, leftFollower1, leftFollower2, true, true, true, true);
XCANTalon.configureMotorTeam("RightDrive", "RightLeader", rightLeader, rightFollower1, rightFollower2, true, true, true, true);
XCANTalon.configureMotorTeam(this.getPrefix(), "LeftLeader", leftLeader, leftFollower1, leftFollower2, true, true, true, true);
XCANTalon.configureMotorTeam(this.getPrefix(), "RightLeader", rightLeader, rightFollower1, rightFollower2, true, true, true, true);

this.register();
}
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/competition/subsystems/pose/PoseSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ public class PoseSubsystem extends BasePoseSubsystem {

DriveSubsystem drive;

// each wheel revolution is 256 ticks, and the wheels are 6 inches in diameter.
// this means each revolution would move the robot (if not slipping at all) 6*pi inches.
// So, one tick would move us (6*pi)/256 inches
// Conversely, we can
private double scalingFactorFromTicksToInches = 6.0 * Math.PI / 256.0;

@Inject
public PoseSubsystem(CommonLibFactory clf, PropertyFactory propManager, DriveSubsystem drive) {
super(clf, propManager);
this.drive = drive;
}


@Override
protected double getLeftDriveDistance() {
return drive.leftLeader.getSelectedSensorPosition(0);
return drive.leftLeader.getSelectedSensorPosition(0) * scalingFactorFromTicksToInches;
}

@Override
protected double getRightDriveDistance() {
return drive.rightLeader.getSelectedSensorPosition(0);
return drive.rightLeader.getSelectedSensorPosition(0) * scalingFactorFromTicksToInches;
}

}

0 comments on commit 7fecbff

Please sign in to comment.