Skip to content

Commit

Permalink
Removed unnecessary json data in PID controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Gold872 committed Dec 9, 2023
1 parent 72a6362 commit f893d6d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
28 changes: 10 additions & 18 deletions lib/widgets/nt4_widgets/multi-topic/pid_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,17 @@ class PIDControllerWidget extends NT4Widget {
kdTopic,
setpointTopic,
super.period,
}) : super() {
kpTopicName = kpTopic ?? '$topic/p';
kiTopicName = kiTopic ?? '$topic/i';
kdTopicName = kdTopic ?? '$topic/d';
setpointTopicName = setpointTopic ?? '$topic/setpoint';
}
}) : super();

PIDControllerWidget.fromJson({super.key, required super.jsonData})
: super.fromJson();

PIDControllerWidget.fromJson(
{super.key, required Map<String, dynamic> jsonData})
: super.fromJson(jsonData: jsonData) {
kpTopicName = tryCast(jsonData['kp_topic']) ?? '$topic/p';
kiTopicName = tryCast(jsonData['ki_topic']) ?? '$topic/i';
kdTopicName = tryCast(jsonData['kd_topic']) ?? '$topic/d';
setpointTopicName =
tryCast(jsonData['setpoint_topic']) ?? '$topic/setpoint';
@override
void init() {
kpTopicName = '$topic/p';
kiTopicName = '$topic/i';
kdTopicName = '$topic/d';
setpointTopicName = '$topic/setpoint';
}

@override
Expand All @@ -76,10 +72,6 @@ class PIDControllerWidget extends NT4Widget {
return {
'topic': topic,
'period': period,
'kp_topic': kpTopicName,
'ki_topic': kiTopicName,
'kd_topic': kdTopicName,
'setpoint_topic': setpointTopicName,
};
}

Expand Down
2 changes: 1 addition & 1 deletion test_resources/test-layout.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"tabs":[{"name":"Teleoperated","grid_layout":{"layouts":[{"title":"Example List Layout","x":1280.0,"y":0.0,"width":256.0,"height":384.0,"type":"List Layout","properties":{"label_position":"TOP"},"children":[{"title":"Differential Drive","x":0.0,"y":0.0,"width":384.0,"height":256.0,"type":"DifferentialDrive","properties":{"topic":"/SmartDashboard/Differential Drive","period":0.033}},{"title":"List Layout Boolean","x":0.0,"y":0.0,"width":128.0,"height":128.0,"type":"Boolean Box","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033,"true_color":4283215696,"false_color":4294198070}}]}],"containers":[{"title":"Test Number","x":0.0,"y":0.0,"width":128.0,"height":128.0,"type":"Text Display","properties":{"topic":"/SmartDashboard/Testing","period":0.033}},{"title":"Test Boolean","x":128.0,"y":0.0,"width":128.0,"height":128.0,"type":"Boolean Box","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033,"true_color":4283215696,"false_color":4294198070}},{"title":"Field","x":256.0,"y":384.0,"width":384.0,"height":256.0,"type":"Field","properties":{"topic":"/SmartDashboard/Field","period":0.033,"field_game":"Charged Up","robot_width":0.82,"robot_length":1.0,"show_other_objects":true,"show_trajectories":true}},{"title":"Test Gyro","x":0.0,"y":128.0,"width":256.0,"height":256.0,"type":"Gyro","properties":{"topic":"/SmartDashboard/Test Gyro","period":0.033,"counter_clockwise_positive":false}},{"title":"Test Distribution","x":640.0,"y":0.0,"width":384.0,"height":512.0,"type":"PowerDistribution","properties":{"topic":"/SmartDashboard/Test Distribution","period":0.033}},{"title":"Test PID Controller","x":1024.0,"y":0.0,"width":256.0,"height":384.0,"type":"PIDController","properties":{"topic":"/SmartDashboard/Test PID Controller","period":0.033,"kp_topic":"/SmartDashboard/Test PID Controller/p","ki_topic":"/SmartDashboard/Test PID Controller/i","kd_topic":"/SmartDashboard/Test PID Controller/d","setpoint_topic":"/SmartDashboard/Test PID Controller/setpoint"}},{"title":"USB Camera 0","x":0.0,"y":384.0,"width":128.0,"height":128.0,"type":"Camera Stream","properties":{"topic":"/CameraPublisher/USB Camera 0","period":0.033}},{"title":"FMSInfo","x":256.0,"y":256.0,"width":384.0,"height":128.0,"type":"FMSInfo","properties":{"topic":"/FMSInfo","period":0.033}},{"title":"Match Time","x":128.0,"y":384.0,"width":128.0,"height":128.0,"type":"Match Time","properties":{"topic":"/SmartDashboard/Match Time","period":0.033}},{"title":"Swerve Drive","x":1024.0,"y":384.0,"width":256.0,"height":256.0,"type":"SwerveDrive","properties":{"topic":"/SmartDashboard/Swerve Drive","period":0.033,"show_robot_rotation":true}}]}},{"name":"Autonomous","grid_layout":{"layouts":[],"containers":[{"title":"Test Chooser","x":0.0,"y":0.0,"width":256.0,"height":128.0,"type":"ComboBox Chooser","properties":{"topic":"/SmartDashboard/Test Chooser","period":0.033}},{"title":"Command Scheduler","x":256.0,"y":0.0,"width":256.0,"height":384.0,"type":"Scheduler","properties":{"topic":"/SmartDashboard/Command Scheduler","period":0.033}},{"title":"Drive System","x":512.0,"y":128.0,"width":256.0,"height":128.0,"type":"Subsystem","properties":{"topic":"/SmartDashboard/Drive System","period":0.033}},{"title":"Rainbow Color Array","x":0.0,"y":256.0,"width":256.0,"height":128.0,"type":"Multi Color View","properties":{"topic":"/SmartDashboard/Rainbow Color Array","period":0.033}},{"title":"Voltage","x":0.0,"y":384.0,"width":256.0,"height":128.0,"type":"Voltage View","properties":{"topic":"/SmartDashboard/Voltage","period":0.033,"min_value":4.0,"max_value":13.0,"divisions":5,"inverted":false,"orientation":"horizontal"}},{"title":"Auto Path","x":512.0,"y":0.0,"width":256.0,"height":128.0,"type":"Command","properties":{"topic":"/SmartDashboard/Auto Path","period":0.033}},{"title":"Test Boolean","x":512.0,"y":256.0,"width":128.0,"height":128.0,"type":"Toggle Switch","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033}},{"title":"Test Toggle Button","x":640.0,"y":256.0,"width":128.0,"height":128.0,"type":"Toggle Button","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033}},{"title":"Preferences","x":768.0,"y":0.0,"width":256.0,"height":384.0,"type":"RobotPreferences","properties":{"topic":"/Preferences","period":0.033}},{"title":"Auto Chooser","x":0.0,"y":128.0,"width":256.0,"height":128.0,"type":"Split Button Chooser","properties":{"topic":"/SmartDashboard/Auto Chooser","period":0.033}},{"title":"Rainbow Color","x":256.0,"y":384.0,"width":128.0,"height":128.0,"type":"Single Color View","properties":{"topic":"/SmartDashboard/Rainbow Color","period":0.033}},{"title":"Test Number","x":384.0,"y":384.0,"width":128.0,"height":128.0,"type":"Number Bar","properties":{"topic":"/SmartDashboard/Test Number","period":0.033,"min_value":-1.0,"max_value":1.0,"divisions":5,"inverted":false,"orientation":"horizontal"}},{"title":"Test Number","x":512.0,"y":384.0,"width":256.0,"height":128.0,"type":"Number Slider","properties":{"topic":"/SmartDashboard/Test Number","period":0.033,"min_value":-1.0,"max_value":1.0,"divisions":5}},{"title":"Voltage","x":768.0,"y":384.0,"width":256.0,"height":128.0,"type":"Graph","properties":{"topic":"/SmartDashboard/Voltage","period":0.033,"time_displayed":5.0,"min_value":null,"max_value":null,"color":4278238420}}]}}]}
{"tabs":[{"name":"Teleoperated","grid_layout":{"layouts":[{"title":"Example List Layout","x":1280.0,"y":0.0,"width":256.0,"height":384.0,"type":"List Layout","properties":{"label_position":"TOP"},"children":[{"title":"Differential Drive","x":0.0,"y":0.0,"width":384.0,"height":256.0,"type":"DifferentialDrive","properties":{"topic":"/SmartDashboard/Differential Drive","period":0.033}},{"title":"List Layout Boolean","x":0.0,"y":0.0,"width":128.0,"height":128.0,"type":"Boolean Box","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033,"true_color":4283215696,"false_color":4294198070}}]}],"containers":[{"title":"Test Number","x":0.0,"y":0.0,"width":128.0,"height":128.0,"type":"Text Display","properties":{"topic":"/SmartDashboard/Testing","period":0.033}},{"title":"Test Boolean","x":128.0,"y":0.0,"width":128.0,"height":128.0,"type":"Boolean Box","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033,"true_color":4283215696,"false_color":4294198070}},{"title":"Field","x":256.0,"y":384.0,"width":384.0,"height":256.0,"type":"Field","properties":{"topic":"/SmartDashboard/Field","period":0.033,"field_game":"Charged Up","robot_width":0.82,"robot_length":1.0,"show_other_objects":true,"show_trajectories":true}},{"title":"Test Gyro","x":0.0,"y":128.0,"width":256.0,"height":256.0,"type":"Gyro","properties":{"topic":"/SmartDashboard/Test Gyro","period":0.033,"counter_clockwise_positive":false}},{"title":"Test Distribution","x":640.0,"y":0.0,"width":384.0,"height":512.0,"type":"PowerDistribution","properties":{"topic":"/SmartDashboard/Test Distribution","period":0.033}},{"title":"Test PID Controller","x":1024.0,"y":0.0,"width":256.0,"height":384.0,"type":"PIDController","properties":{"topic":"/SmartDashboard/Test PID Controller","period":0.033}},{"title":"USB Camera 0","x":0.0,"y":384.0,"width":128.0,"height":128.0,"type":"Camera Stream","properties":{"topic":"/CameraPublisher/USB Camera 0","period":0.033}},{"title":"FMSInfo","x":256.0,"y":256.0,"width":384.0,"height":128.0,"type":"FMSInfo","properties":{"topic":"/FMSInfo","period":0.033}},{"title":"Match Time","x":128.0,"y":384.0,"width":128.0,"height":128.0,"type":"Match Time","properties":{"topic":"/SmartDashboard/Match Time","period":0.033}},{"title":"Swerve Drive","x":1024.0,"y":384.0,"width":256.0,"height":256.0,"type":"SwerveDrive","properties":{"topic":"/SmartDashboard/Swerve Drive","period":0.033,"show_robot_rotation":true}}]}},{"name":"Autonomous","grid_layout":{"layouts":[],"containers":[{"title":"Test Chooser","x":0.0,"y":0.0,"width":256.0,"height":128.0,"type":"ComboBox Chooser","properties":{"topic":"/SmartDashboard/Test Chooser","period":0.033}},{"title":"Command Scheduler","x":256.0,"y":0.0,"width":256.0,"height":384.0,"type":"Scheduler","properties":{"topic":"/SmartDashboard/Command Scheduler","period":0.033}},{"title":"Drive System","x":512.0,"y":128.0,"width":256.0,"height":128.0,"type":"Subsystem","properties":{"topic":"/SmartDashboard/Drive System","period":0.033}},{"title":"Rainbow Color Array","x":0.0,"y":256.0,"width":256.0,"height":128.0,"type":"Multi Color View","properties":{"topic":"/SmartDashboard/Rainbow Color Array","period":0.033}},{"title":"Voltage","x":0.0,"y":384.0,"width":256.0,"height":128.0,"type":"Voltage View","properties":{"topic":"/SmartDashboard/Voltage","period":0.033,"min_value":4.0,"max_value":13.0,"divisions":5,"inverted":false,"orientation":"horizontal"}},{"title":"Auto Path","x":512.0,"y":0.0,"width":256.0,"height":128.0,"type":"Command","properties":{"topic":"/SmartDashboard/Auto Path","period":0.033}},{"title":"Test Boolean","x":512.0,"y":256.0,"width":128.0,"height":128.0,"type":"Toggle Switch","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033}},{"title":"Test Toggle Button","x":640.0,"y":256.0,"width":128.0,"height":128.0,"type":"Toggle Button","properties":{"topic":"/SmartDashboard/Test Boolean","period":0.033}},{"title":"Preferences","x":768.0,"y":0.0,"width":256.0,"height":384.0,"type":"RobotPreferences","properties":{"topic":"/Preferences","period":0.033}},{"title":"Auto Chooser","x":0.0,"y":128.0,"width":256.0,"height":128.0,"type":"Split Button Chooser","properties":{"topic":"/SmartDashboard/Auto Chooser","period":0.033}},{"title":"Rainbow Color","x":256.0,"y":384.0,"width":128.0,"height":128.0,"type":"Single Color View","properties":{"topic":"/SmartDashboard/Rainbow Color","period":0.033}},{"title":"Test Number","x":384.0,"y":384.0,"width":128.0,"height":128.0,"type":"Number Bar","properties":{"topic":"/SmartDashboard/Test Number","period":0.033,"min_value":-1.0,"max_value":1.0,"divisions":5,"inverted":false,"orientation":"horizontal"}},{"title":"Test Number","x":512.0,"y":384.0,"width":256.0,"height":128.0,"type":"Number Slider","properties":{"topic":"/SmartDashboard/Test Number","period":0.033,"min_value":-1.0,"max_value":1.0,"divisions":5}},{"title":"Voltage","x":768.0,"y":384.0,"width":256.0,"height":128.0,"type":"Graph","properties":{"topic":"/SmartDashboard/Voltage","period":0.033,"time_displayed":5.0,"min_value":null,"max_value":null,"color":4278238420}}]}}]}

0 comments on commit f893d6d

Please sign in to comment.