Skip to content
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

Arm widget #131

Merged
merged 5 commits into from
Oct 17, 2023
Merged

Arm widget #131

merged 5 commits into from
Oct 17, 2023

Conversation

njooma
Copy link
Member

@njooma njooma commented Oct 13, 2023

New arm widget.

Also, update buttons so we can actually have small sizes.

simulator_screenshot_F2989544-18A4-4943-BB5D-B703BF748910

@njooma njooma requested a review from a team as a code owner October 13, 2023 20:25
@njooma
Copy link
Member Author

njooma commented Oct 14, 2023

I also changed the return type of Arm.jointPositions from the proto JointPositions to a List<double>. I feel this is more in line with our system of trying to hide the proto definitions in favor of native types where possible, especially since the proto JointPositions had only one attribute: a values property which is a List<double>.

Copy link
Member

@benjirewis benjirewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have too much context here... just some qs, but looks p good from what I can tell.

/// Move each joint on the arm to the corresponding position specified in [JointPositions]
Future<void> moveToJointPositions(JointPositions positions, {Map<String, dynamic>? extra});
/// Move each joint on the arm to the corresponding position specified in [positions]
Future<void> moveToJointPositions(List<double> positions, {Map<String, dynamic>? extra});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, good catch here; definitely agree with preferring native types where possible.

lib/widgets/button.dart Show resolved Hide resolved
super.initState();
camera = widget.cameras.firstOrNull;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why move this after the super init state? Was it getting overwritten or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've just been doing it wrong the entire time. From the documentation:

Implementations of this method should start with a call to the inherited method, as in super.initState().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, you might see changes to super.dispose() in other PRs (not in this one) for the inverse reason:

Implementations of this method should end with a call to the inherited method, as in super.dispose().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool; makes intuitive sense too that you want to do the inherited construction/destruction before the custom class construction/destruction.

Copy link
Member

@clintpurser clintpurser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs some more work, close though!

Pose endPosition = Pose();
List<double> jointPositions = [];

Future<void> _positions() async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] I think in this case it is okay to prefix the method name with get. omitting get / set is more for API design, since this the internal workings of a widget and isn't a public API I think naming the method more clearly would be helpful.

Suggested change
Future<void> _positions() async {
Future<void> _getPositions() async {

ref: https://dart.dev/effective-dart/design#avoid-starting-a-method-name-with-get

Comment on lines 39 to 62
Future<void> updateEndPosition(String field, double increment) async {
final ep = endPosition;
if (field == 'x') {
ep.x += increment;
} else if (field == 'y') {
ep.y += increment;
} else if (field == 'z') {
ep.z += increment;
} else if (field == 'theta') {
ep.theta += increment;
} else if (field == 'ox') {
ep.oX += increment;
} else if (field == 'oy') {
ep.oY += increment;
} else if (field == 'oz') {
ep.oZ += increment;
}
await widget.arm.moveToPosition(ep);
await _positions();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[suggestion] I think the string comparison here is fine, I might suggest defining an enum for the fields with the different options, and using a switch statement instead.

Not something blocking merging, just a preference on my side.

crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Text('End Positions (mm)', style: TextStyle(fontWeight: FontWeight.bold)),
Table(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] This Table is a BEEFY widget, can we break it out into its own widget?

Comment on lines 78 to 100
TableRow(children: [
const TableCell(child: Padding(padding: EdgeInsets.symmetric(horizontal: 2), child: Text('X', textAlign: TextAlign.end))),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: ViamButton(onPressed: () => updateEndPosition('x', -10), text: '--', size: ViamButtonSizeClass.small))),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: ViamButton(onPressed: () => updateEndPosition('x', -1), text: '-', size: ViamButtonSizeClass.small))),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: Text(endPosition.x.toStringAsFixed(2), textAlign: TextAlign.center))),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: ViamButton(onPressed: () => updateEndPosition('x', 1), text: '+', size: ViamButtonSizeClass.small))),
TableCell(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 1),
child: ViamButton(onPressed: () => updateEndPosition('x', 10), text: '++', size: ViamButtonSizeClass.small))),
]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These TableRows and TableCells have a lot of repeated code, can we make ArmRow and ArmCell widgets to clean this up?

Copy link
Member

@clintpurser clintpurser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar feedback, overall closer, but need to prefer widgets over helper functions.

Comment on lines +41 to +58
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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ love it, thank you!

await _getPositions();
}

TableRow _getEndPositionRow(_PoseField field) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Can we put this in it's own widget instead of a helper function? See here for a bit more of a deep dive on why. Basically it's more performant when the widget tree rebuilds.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@njooma and I spoke offline, I was mistaken and TableRow is not a Widget (<--- WHAT?!) so I was mistaken. this helper function in this case is fine :)

lib/widgets/resources/arm.dart Show resolved Hide resolved
Copy link
Member

@clintpurser clintpurser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

await _getPositions();
}

TableRow _getEndPositionRow(_PoseField field) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@njooma and I spoke offline, I was mistaken and TableRow is not a Widget (<--- WHAT?!) so I was mistaken. this helper function in this case is fine :)

@njooma njooma merged commit 0eed7b5 into viamrobotics:main Oct 17, 2023
@njooma njooma deleted the arm-widget branch October 17, 2023 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants