-
Notifications
You must be signed in to change notification settings - Fork 31
[APP-10023] Update joint positions when pose changes and vice versa #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martha-johnston
wants to merge
14
commits into
main
Choose a base branch
from
app-10023/update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+385
−479
Open
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
474a328
add joint positions widget
martha-johnston a60ae2e
arm_new generic screen
martha-johnston 6e38c07
Change label from 'Joint Angles' to 'Joint Positions'
martha-johnston 3d0d5a9
Implement joint position functionality (#441)
martha-johnston 7c5540d
use theme for colors
martha-johnston 8b0b6d9
Merge branch 'main' into app-9878/joint-positions
martha-johnston a3a68c1
update joint angle limits
martha-johnston ea583bc
update arm values
martha-johnston 6d78cd3
Merge branch 'main' into app-10023/update
martha-johnston 4a082e2
update branch
martha-johnston 7a432db
switch arm_new to arm
martha-johnston 9d42291
extend sliders (#449)
martha-johnston 8bf470a
pr comments
martha-johnston 1dd39cd
remove new suffix
martha-johnston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,171 +1,45 @@ | ||
| import 'package:collection/collection.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| import '../../viam_sdk.dart'; | ||
| import '../../widgets.dart'; | ||
| import 'arm_widgets/joint_positions_widget.dart'; | ||
| import 'arm_widgets/pose_widget.dart'; | ||
|
|
||
| class ArmNotifier extends ChangeNotifier { | ||
| void armHasMoved() { | ||
| notifyListeners(); | ||
| } | ||
| } | ||
|
|
||
| /// A widget to control an [Arm]. | ||
| class ViamArmWidget extends StatefulWidget { | ||
| class ViamArmWidgetNew extends StatefulWidget { | ||
| /// The [Arm] | ||
| final Arm arm; | ||
|
|
||
| const ViamArmWidget({ | ||
| const ViamArmWidgetNew({ | ||
| super.key, | ||
| required this.arm, | ||
| }); | ||
|
|
||
| @override | ||
| State<ViamArmWidget> createState() => _ViamArmWidgetState(); | ||
| } | ||
|
|
||
| enum _PoseField { | ||
| x, | ||
| y, | ||
| z, | ||
| theta, | ||
| oX, | ||
| oY, | ||
| oZ; | ||
|
|
||
| String get title { | ||
| switch (this) { | ||
| case x: | ||
| return 'X'; | ||
| case y: | ||
| return 'Y'; | ||
| case z: | ||
| return 'Z'; | ||
| case theta: | ||
| return 'Theta'; | ||
| case oX: | ||
| return 'OX'; | ||
| case oY: | ||
| return 'OY'; | ||
| case oZ: | ||
| return 'OZ'; | ||
| } | ||
| } | ||
| State<ViamArmWidgetNew> createState() => _ViamArmWidgetNewState(); | ||
| } | ||
|
|
||
| class _ViamArmWidgetState extends State<ViamArmWidget> { | ||
| Pose endPosition = Pose(); | ||
| List<double> jointPositions = []; | ||
|
|
||
| Future<void> _getPositions() async { | ||
| final ep = await widget.arm.endPosition(); | ||
| final jp = await widget.arm.jointPositions(); | ||
| setState(() { | ||
| jointPositions = jp; | ||
| endPosition = ep; | ||
| }); | ||
| } | ||
| class _ViamArmWidgetNewState extends State<ViamArmWidgetNew> { | ||
| final ArmNotifier _armNotifier = ArmNotifier(); | ||
|
|
||
| @override | ||
| void initState() { | ||
| super.initState(); | ||
| _getPositions(); | ||
| } | ||
|
|
||
| Future<void> updateEndPosition(_PoseField field, double increment) async { | ||
| final ep = endPosition; | ||
| switch (field) { | ||
| case _PoseField.x: | ||
| ep.x += increment; | ||
| case _PoseField.y: | ||
| ep.y += increment; | ||
| case _PoseField.z: | ||
| ep.z += increment; | ||
| case _PoseField.theta: | ||
| ep.theta += increment; | ||
| case _PoseField.oX: | ||
| ep.oX += increment; | ||
| case _PoseField.oY: | ||
| ep.oY += increment; | ||
| case _PoseField.oZ: | ||
| ep.oZ += increment; | ||
| } | ||
|
|
||
| await widget.arm.moveToPosition(ep); | ||
| await _getPositions(); | ||
| } | ||
|
|
||
| Future<void> updateJointPosition(int joint, double increment) async { | ||
| final jp = jointPositions; | ||
| jp[joint] += increment; | ||
| await widget.arm.moveToJointPositions(jp); | ||
| await _getPositions(); | ||
| } | ||
|
|
||
| TableRow _getEndPositionRow(_PoseField field) { | ||
| double value; | ||
| switch (field) { | ||
| case _PoseField.x: | ||
| value = endPosition.x; | ||
| case _PoseField.y: | ||
| value = endPosition.y; | ||
| case _PoseField.z: | ||
| value = endPosition.z; | ||
| case _PoseField.theta: | ||
| value = endPosition.theta; | ||
| case _PoseField.oX: | ||
| value = endPosition.oX; | ||
| case _PoseField.oY: | ||
| value = endPosition.oY; | ||
| case _PoseField.oZ: | ||
| value = endPosition.oZ; | ||
| } | ||
|
|
||
| return TableRow(children: [ | ||
| _ArmTableCell(Text(field.title, textAlign: TextAlign.end)), | ||
| _ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, -10), text: '--', size: ViamButtonSizeClass.small)), | ||
| _ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, -1), text: '-', size: ViamButtonSizeClass.small)), | ||
| _ArmTableCell(Text(value.toStringAsFixed(2), textAlign: TextAlign.center)), | ||
| _ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, 1), text: '+', size: ViamButtonSizeClass.small)), | ||
| _ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, 10), text: '++', size: ViamButtonSizeClass.small)), | ||
| ]); | ||
| void dispose() { | ||
| _armNotifier.dispose(); | ||
| super.dispose(); | ||
| } | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Column( | ||
| mainAxisAlignment: MainAxisAlignment.center, | ||
| crossAxisAlignment: CrossAxisAlignment.center, | ||
| children: [ | ||
| const Text('End Positions (mm)', style: TextStyle(fontWeight: FontWeight.bold)), | ||
| Table( | ||
| columnWidths: const {0: IntrinsicColumnWidth()}, | ||
| defaultVerticalAlignment: TableCellVerticalAlignment.middle, | ||
| children: _PoseField.values.map((e) => _getEndPositionRow(e)).toList(), | ||
| ), | ||
| const SizedBox(height: 16), | ||
| const Text('Joints (degrees)', style: TextStyle(fontWeight: FontWeight.bold)), | ||
| Table( | ||
| columnWidths: const {0: IntrinsicColumnWidth()}, | ||
| defaultVerticalAlignment: TableCellVerticalAlignment.middle, | ||
| children: jointPositions | ||
| .mapIndexed((index, element) => TableRow(children: [ | ||
| _ArmTableCell(Text('Joint $index', textAlign: TextAlign.end)), | ||
| _ArmTableCell( | ||
| ViamButton(onPressed: () => updateJointPosition(index, -10), text: '--', size: ViamButtonSizeClass.small)), | ||
| _ArmTableCell(ViamButton(onPressed: () => updateJointPosition(index, -1), text: '-', size: ViamButtonSizeClass.small)), | ||
| _ArmTableCell(Text(element.toStringAsFixed(2), textAlign: TextAlign.center)), | ||
| _ArmTableCell(ViamButton(onPressed: () => updateJointPosition(index, 1), text: '+', size: ViamButtonSizeClass.small)), | ||
| _ArmTableCell(ViamButton(onPressed: () => updateJointPosition(index, 10), text: '++', size: ViamButtonSizeClass.small)), | ||
| ])) | ||
| .toList(), | ||
| ) | ||
| JointPositionsWidget(arm: widget.arm, updateNotifier: _armNotifier), | ||
| PoseWidget(arm: widget.arm, updateNotifier: _armNotifier), | ||
| ], | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class _ArmTableCell extends StatelessWidget { | ||
| final Widget child; | ||
|
|
||
| const _ArmTableCell(this.child); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return TableCell(child: Padding(padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 1), child: child)); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the
Newsuffix on all of these?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep forgot that