Skip to content

Commit bc0d802

Browse files
stevebriskinnjooma
andauthored
RSDK-623: remove position_reporting from MotorStatus (#198)
Co-authored-by: Naveed Jooma <[email protected]>
1 parent 49e38f1 commit bc0d802

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+547
-128
lines changed

docs/examples/my_cool_arm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,6 @@ async def move_to_joint_positions(self, positions: JointPositions, extra: Option
7676

7777
async def stop(self, extra: Optional[Dict[str, Any]] = None, **kwargs):
7878
self.is_stopped = True
79+
80+
async def is_moving(self) -> bool:
81+
return not self.is_stopped

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ packages = [
1111
include = ["LICENSE", "src/viam/rpc/libviam_rust_utils.*"]
1212

1313
[tool.poetry.dependencies]
14-
python = ">=3.8,<=3.11"
14+
python = ">=3.8,<3.12"
1515
grpclib = "^0.4.3"
1616
googleapis-common-protos = "^1.57.0"
1717
typing-extensions = "^4.4.0"

src/viam/components/arm/arm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import abc
22
from typing import Any, Dict, Optional
33

4-
from viam.errors import NotSupportedError
54
from viam.proto.common import Pose, WorldState
65
from viam.proto.component.arm import JointPositions
76

@@ -101,11 +100,12 @@ async def stop(
101100
"""
102101
...
103102

103+
@abc.abstractmethod
104104
async def is_moving(self) -> bool:
105105
"""
106106
Get if the arm is currently moving.
107107
108108
Returns:
109109
bool: Whether the arm is moving.
110110
"""
111-
raise NotSupportedError(f"Arm named {self.name} does not support returning whether it is moving")
111+
...

src/viam/components/arm/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, Dict, Optional
22

33
from grpclib.client import Channel
4+
45
from viam.components.generic.client import do_command
56
from viam.proto.common import Pose, WorldState
67
from viam.proto.component.arm import (
@@ -9,6 +10,8 @@
910
GetEndPositionResponse,
1011
GetJointPositionsRequest,
1112
GetJointPositionsResponse,
13+
IsMovingRequest,
14+
IsMovingResponse,
1215
JointPositions,
1316
MoveToJointPositionsRequest,
1417
MoveToPositionRequest,
@@ -91,6 +94,13 @@ async def stop(
9194
request = StopRequest(name=self.name, extra=dict_to_struct(extra))
9295
await self.client.Stop(request, timeout=timeout)
9396

97+
async def is_moving(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) -> bool:
98+
if extra is None:
99+
extra = {}
100+
request = IsMovingRequest(name=self.name)
101+
response: IsMovingResponse = await self.client.IsMoving(request, timeout=timeout)
102+
return response.is_moving
103+
94104
async def do_command(
95105
self,
96106
command: Dict[str, Any],

src/viam/components/arm/service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
MoveToPositionResponse,
1515
StopRequest,
1616
StopResponse,
17+
IsMovingRequest,
18+
IsMovingResponse,
1719
)
1820
from viam.utils import struct_to_dict
1921

@@ -93,3 +95,15 @@ async def Stop(self, stream: Stream[StopRequest, StopResponse]) -> None:
9395
await arm.stop(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
9496
response = StopResponse()
9597
await stream.send_message(response)
98+
99+
async def IsMoving(self, stream: Stream[IsMovingRequest, IsMovingResponse]) -> None:
100+
request = await stream.recv_message()
101+
assert request is not None
102+
name = request.name
103+
try:
104+
arm = self.get_component(name)
105+
except ComponentNotFoundError as e:
106+
raise e.grpc_error
107+
is_moving = await arm.is_moving()
108+
response = IsMovingResponse(is_moving=is_moving)
109+
await stream.send_message(response)

src/viam/components/base/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import abc
22
from typing import Any, Dict, Optional
33

4-
from viam.errors import NotSupportedError
54
from viam.proto.common import Vector3
65

76
from ..component_base import ComponentBase
@@ -121,11 +120,12 @@ async def stop(
121120
"""
122121
...
123122

123+
@abc.abstractmethod
124124
async def is_moving(self) -> bool:
125125
"""
126126
Get if the base is currently moving.
127127
128128
Returns:
129129
bool: Whether the base is moving.
130130
"""
131-
raise NotSupportedError(f"Base named {self.name} does not support returning whether it is moving")
131+
...

src/viam/components/base/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from typing import Any, Dict, Optional
22

33
from grpclib.client import Channel
4+
45
from viam.components.generic.client import do_command
56
from viam.proto.common import Vector3
67
from viam.proto.component.base import (
78
BaseServiceStub,
9+
IsMovingRequest,
10+
IsMovingResponse,
811
MoveStraightRequest,
912
SetPowerRequest,
1013
SetVelocityRequest,
@@ -104,6 +107,13 @@ async def stop(
104107
request = StopRequest(name=self.name, extra=dict_to_struct(extra))
105108
await self.client.Stop(request, timeout=timeout)
106109

110+
async def is_moving(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) -> bool:
111+
if extra is None:
112+
extra = {}
113+
request = IsMovingRequest(name=self.name)
114+
response: IsMovingResponse = await self.client.IsMoving(request, timeout=timeout)
115+
return response.is_moving
116+
107117
async def do_command(
108118
self,
109119
command: Dict[str, Any],

src/viam/components/base/service.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
SpinResponse,
1414
StopRequest,
1515
StopResponse,
16+
IsMovingRequest,
17+
IsMovingResponse,
1618
)
1719
from viam.utils import struct_to_dict
1820

@@ -105,3 +107,15 @@ async def Stop(self, stream: Stream[StopRequest, StopResponse]) -> None:
105107
await base.stop(extra=struct_to_dict(request.extra), timeout=timeout, metadata=stream.metadata)
106108
response = StopResponse()
107109
await stream.send_message(response)
110+
111+
async def IsMoving(self, stream: Stream[IsMovingRequest, IsMovingResponse]) -> None:
112+
request = await stream.recv_message()
113+
assert request is not None
114+
name = request.name
115+
try:
116+
base = self.get_component(name)
117+
except ComponentNotFoundError as e:
118+
raise e.grpc_error
119+
is_moving = await base.is_moving()
120+
response = IsMovingResponse(is_moving=is_moving)
121+
await stream.send_message(response)

src/viam/components/gantry/client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
GetLengthsResponse,
1111
GetPositionRequest,
1212
GetPositionResponse,
13+
IsMovingRequest,
14+
IsMovingResponse,
1315
MoveToPositionRequest,
1416
StopRequest,
1517
)
@@ -61,5 +63,12 @@ async def stop(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optiona
6163
request = StopRequest(name=self.name, extra=dict_to_struct(extra))
6264
await self.client.Stop(request, timeout=timeout)
6365

66+
async def is_moving(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optional[float] = None) -> bool:
67+
if extra is None:
68+
extra = {}
69+
request = IsMovingRequest(name=self.name)
70+
response: IsMovingResponse = await self.client.IsMoving(request, timeout=timeout)
71+
return response.is_moving
72+
6473
async def do_command(self, command: Dict[str, Any]) -> Dict[str, Any]:
6574
return await do_command(self.channel, self.name, command)

src/viam/components/gantry/gantry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import abc
22
from typing import Any, Dict, List, Optional
33

4-
from viam.errors import NotSupportedError
54
from viam.proto.common import WorldState
65

76
from ..component_base import ComponentBase
@@ -64,11 +63,12 @@ async def stop(self, *, extra: Optional[Dict[str, Any]] = None, timeout: Optiona
6463
"""
6564
...
6665

66+
@abc.abstractmethod
6767
async def is_moving(self) -> bool:
6868
"""
6969
Get if the gantry is currently moving.
7070
7171
Returns:
7272
bool: Whether the gantry is moving.
7373
"""
74-
raise NotSupportedError(f"Gantry named {self.name} does not support returning whether it is moving")
74+
...

0 commit comments

Comments
 (0)