-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added serial monitor and data generator scripts (#9)
- Loading branch information
1 parent
898ad39
commit 54713fe
Showing
4 changed files
with
121 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import "dart:math"; | ||
|
||
import "package:burt_network/burt_network.dart"; | ||
import "package:subsystems/subsystems.dart"; | ||
|
||
class SwingingIterator implements Iterator<double> { | ||
final double min; | ||
final double max; | ||
final double increment; | ||
SwingingIterator(this.min, this.max, this.increment) : current = min; | ||
|
||
bool forward = true; | ||
@override double current; | ||
|
||
@override | ||
bool moveNext() { | ||
if (current >= max && forward) forward = false; | ||
if (current <= min && !forward) forward = true; | ||
if (forward) { | ||
current += increment; | ||
} else { | ||
current -= increment; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
Future<void> main() async { | ||
final server = SubsystemsServer(port: 8001); | ||
await server.init(); | ||
final throttle = SwingingIterator(0, 1, 0.01); | ||
final voltage = SwingingIterator(24, 30, 0.1); | ||
final current = SwingingIterator(0, 30, 0.1); | ||
final motor = SwingingIterator(0, pi, 0.01); | ||
final motor2 = SwingingIterator(0, 2*pi, 0.05); | ||
while (true) { | ||
throttle.moveNext(); | ||
voltage.moveNext(); | ||
current.moveNext(); | ||
motor.moveNext(); | ||
motor2.moveNext(); | ||
final data = DriveData( | ||
left: 1, | ||
setLeft: true, | ||
right: -1, | ||
setRight: true, | ||
throttle: throttle.current, | ||
setThrottle: true, | ||
batteryVoltage: voltage.current, | ||
batteryCurrent: current.current, | ||
); | ||
server.sendMessage(data); | ||
final data2 = ArmData( | ||
base: MotorData(angle: motor2.current), | ||
shoulder: MotorData(angle: motor.current), | ||
elbow: MotorData(angle: motor.current), | ||
); | ||
server.sendMessage(data2); | ||
final data3 = GripperData(lift: MotorData(angle: motor.current)); | ||
server.sendMessage(data3); | ||
await Future<void>.delayed(const Duration(milliseconds: 10)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters