Skip to content

Commit 641f10c

Browse files
[APP-10023] Update joint positions when pose changes and vice versa (#445)
* add joint positions widget * arm_new generic screen * Change label from 'Joint Angles' to 'Joint Positions' * Implement joint position functionality (#441) * use theme for colors * update joint angle limits * update arm values * update branch * switch arm_new to arm * extend sliders (#449) * pr comments * remove new suffix
1 parent c6294cc commit 641f10c

File tree

5 files changed

+385
-479
lines changed

5 files changed

+385
-479
lines changed

example/hotspot_provisioning_example_app/pubspec.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ packages:
157157
dependency: transitive
158158
description:
159159
name: fake_async
160-
sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44"
160+
sha256: "6a95e56b2449df2273fd8c45a662d6947ce1ebb7aafe80e550a3f68297f3cacc"
161161
url: "https://pub.dev"
162162
source: hosted
163-
version: "1.3.3"
163+
version: "1.3.2"
164164
ffi:
165165
dependency: transitive
166166
description:
@@ -300,26 +300,26 @@ packages:
300300
dependency: transitive
301301
description:
302302
name: leak_tracker
303-
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
303+
sha256: c35baad643ba394b40aac41080300150a4f08fd0fd6a10378f8f7c6bc161acec
304304
url: "https://pub.dev"
305305
source: hosted
306-
version: "11.0.2"
306+
version: "10.0.8"
307307
leak_tracker_flutter_testing:
308308
dependency: transitive
309309
description:
310310
name: leak_tracker_flutter_testing
311-
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
311+
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
312312
url: "https://pub.dev"
313313
source: hosted
314-
version: "3.0.10"
314+
version: "3.0.9"
315315
leak_tracker_testing:
316316
dependency: transitive
317317
description:
318318
name: leak_tracker_testing
319-
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
319+
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
320320
url: "https://pub.dev"
321321
source: hosted
322-
version: "3.0.2"
322+
version: "3.0.1"
323323
lints:
324324
dependency: transitive
325325
description:
@@ -633,10 +633,10 @@ packages:
633633
dependency: transitive
634634
description:
635635
name: test_api
636-
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
636+
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
637637
url: "https://pub.dev"
638638
source: hosted
639-
version: "0.7.6"
639+
version: "0.7.4"
640640
typed_data:
641641
dependency: transitive
642642
description:
@@ -657,10 +657,10 @@ packages:
657657
dependency: transitive
658658
description:
659659
name: vector_math
660-
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
660+
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
661661
url: "https://pub.dev"
662662
source: hosted
663-
version: "2.2.0"
663+
version: "2.1.4"
664664
viam_flutter_hotspot_provisioning_widget:
665665
dependency: "direct main"
666666
description:
@@ -717,5 +717,5 @@ packages:
717717
source: hosted
718718
version: "6.5.0"
719719
sdks:
720-
dart: ">=3.8.0-0 <4.0.0"
720+
dart: ">=3.7.0 <4.0.0"
721721
flutter: ">=3.27.0"

lib/widgets/resources/arm.dart

Lines changed: 14 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import 'package:collection/collection.dart';
21
import 'package:flutter/material.dart';
32

43
import '../../viam_sdk.dart';
5-
import '../../widgets.dart';
4+
import 'arm_widgets/joint_positions_widget.dart';
5+
import 'arm_widgets/pose_widget.dart';
6+
7+
class ArmNotifier extends ChangeNotifier {
8+
void armHasMoved() {
9+
notifyListeners();
10+
}
11+
}
612

713
/// A widget to control an [Arm].
814
class ViamArmWidget extends StatefulWidget {
@@ -18,154 +24,22 @@ class ViamArmWidget extends StatefulWidget {
1824
State<ViamArmWidget> createState() => _ViamArmWidgetState();
1925
}
2026

21-
enum _PoseField {
22-
x,
23-
y,
24-
z,
25-
theta,
26-
oX,
27-
oY,
28-
oZ;
29-
30-
String get title {
31-
switch (this) {
32-
case x:
33-
return 'X';
34-
case y:
35-
return 'Y';
36-
case z:
37-
return 'Z';
38-
case theta:
39-
return 'Theta';
40-
case oX:
41-
return 'OX';
42-
case oY:
43-
return 'OY';
44-
case oZ:
45-
return 'OZ';
46-
}
47-
}
48-
}
49-
5027
class _ViamArmWidgetState extends State<ViamArmWidget> {
51-
Pose endPosition = Pose();
52-
List<double> jointPositions = [];
53-
54-
Future<void> _getPositions() async {
55-
final ep = await widget.arm.endPosition();
56-
final jp = await widget.arm.jointPositions();
57-
setState(() {
58-
jointPositions = jp;
59-
endPosition = ep;
60-
});
61-
}
28+
final ArmNotifier _armNotifier = ArmNotifier();
6229

6330
@override
64-
void initState() {
65-
super.initState();
66-
_getPositions();
67-
}
68-
69-
Future<void> updateEndPosition(_PoseField field, double increment) async {
70-
final ep = endPosition;
71-
switch (field) {
72-
case _PoseField.x:
73-
ep.x += increment;
74-
case _PoseField.y:
75-
ep.y += increment;
76-
case _PoseField.z:
77-
ep.z += increment;
78-
case _PoseField.theta:
79-
ep.theta += increment;
80-
case _PoseField.oX:
81-
ep.oX += increment;
82-
case _PoseField.oY:
83-
ep.oY += increment;
84-
case _PoseField.oZ:
85-
ep.oZ += increment;
86-
}
87-
88-
await widget.arm.moveToPosition(ep);
89-
await _getPositions();
90-
}
91-
92-
Future<void> updateJointPosition(int joint, double increment) async {
93-
final jp = jointPositions;
94-
jp[joint] += increment;
95-
await widget.arm.moveToJointPositions(jp);
96-
await _getPositions();
97-
}
98-
99-
TableRow _getEndPositionRow(_PoseField field) {
100-
double value;
101-
switch (field) {
102-
case _PoseField.x:
103-
value = endPosition.x;
104-
case _PoseField.y:
105-
value = endPosition.y;
106-
case _PoseField.z:
107-
value = endPosition.z;
108-
case _PoseField.theta:
109-
value = endPosition.theta;
110-
case _PoseField.oX:
111-
value = endPosition.oX;
112-
case _PoseField.oY:
113-
value = endPosition.oY;
114-
case _PoseField.oZ:
115-
value = endPosition.oZ;
116-
}
117-
118-
return TableRow(children: [
119-
_ArmTableCell(Text(field.title, textAlign: TextAlign.end)),
120-
_ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, -10), text: '--', size: ViamButtonSizeClass.small)),
121-
_ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, -1), text: '-', size: ViamButtonSizeClass.small)),
122-
_ArmTableCell(Text(value.toStringAsFixed(2), textAlign: TextAlign.center)),
123-
_ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, 1), text: '+', size: ViamButtonSizeClass.small)),
124-
_ArmTableCell(ViamButton(onPressed: () => updateEndPosition(field, 10), text: '++', size: ViamButtonSizeClass.small)),
125-
]);
31+
void dispose() {
32+
_armNotifier.dispose();
33+
super.dispose();
12634
}
12735

12836
@override
12937
Widget build(BuildContext context) {
13038
return Column(
131-
mainAxisAlignment: MainAxisAlignment.center,
132-
crossAxisAlignment: CrossAxisAlignment.center,
13339
children: [
134-
const Text('End Positions (mm)', style: TextStyle(fontWeight: FontWeight.bold)),
135-
Table(
136-
columnWidths: const {0: IntrinsicColumnWidth()},
137-
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
138-
children: _PoseField.values.map((e) => _getEndPositionRow(e)).toList(),
139-
),
140-
const SizedBox(height: 16),
141-
const Text('Joints (degrees)', style: TextStyle(fontWeight: FontWeight.bold)),
142-
Table(
143-
columnWidths: const {0: IntrinsicColumnWidth()},
144-
defaultVerticalAlignment: TableCellVerticalAlignment.middle,
145-
children: jointPositions
146-
.mapIndexed((index, element) => TableRow(children: [
147-
_ArmTableCell(Text('Joint $index', textAlign: TextAlign.end)),
148-
_ArmTableCell(
149-
ViamButton(onPressed: () => updateJointPosition(index, -10), text: '--', size: ViamButtonSizeClass.small)),
150-
_ArmTableCell(ViamButton(onPressed: () => updateJointPosition(index, -1), text: '-', size: ViamButtonSizeClass.small)),
151-
_ArmTableCell(Text(element.toStringAsFixed(2), textAlign: TextAlign.center)),
152-
_ArmTableCell(ViamButton(onPressed: () => updateJointPosition(index, 1), text: '+', size: ViamButtonSizeClass.small)),
153-
_ArmTableCell(ViamButton(onPressed: () => updateJointPosition(index, 10), text: '++', size: ViamButtonSizeClass.small)),
154-
]))
155-
.toList(),
156-
)
40+
JointPositionsWidget(arm: widget.arm, updateNotifier: _armNotifier),
41+
PoseWidget(arm: widget.arm, updateNotifier: _armNotifier),
15742
],
15843
);
15944
}
16045
}
161-
162-
class _ArmTableCell extends StatelessWidget {
163-
final Widget child;
164-
165-
const _ArmTableCell(this.child);
166-
167-
@override
168-
Widget build(BuildContext context) {
169-
return TableCell(child: Padding(padding: const EdgeInsets.symmetric(horizontal: 2, vertical: 1), child: child));
170-
}
171-
}

lib/widgets/resources/arm_new.dart

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)