Skip to content

Commit

Permalink
Add version-agnostic get_ir_proximity() command
Browse files Browse the repository at this point in the history
  • Loading branch information
shamlian committed Apr 27, 2023
1 parent 9dad0b9 commit 807419c
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions irobot_edu_sdk/create3.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ async def get_ipv4_address(self) -> IPv4Addresses:
return self.ipv4_address
return None

async def get_ir_proximity(self):
async def get_6x_ir_proximity(self):
"""Get Original IR Proximity Values and States"""
dev, cmd, inc = 11, 1, self.inc
completer = Completer()
self._responses[(dev, cmd, inc)] = completer
Expand All @@ -62,6 +63,11 @@ async def get_ir_proximity(self):
return None

async def get_packed_ir_proximity(self):
"""DEPRECATED function for new Get IR Proximity Values and States"""
print('Warning: get_packed_ir_proximity() has been deprecated, please use get_ir_proximity() instead')
await self.get_7x_ir_proximity()

async def get_7x_ir_proximity(self):
"""Get Packed IR Proximity Values and States"""
dev, cmd, inc = 11, 2, self.inc
completer = Completer()
Expand All @@ -85,7 +91,22 @@ async def get_packed_ir_proximity(self):
return ir_proximity
return None

async def get_ir_proximity(self):
"""Version-Agnostic Get IR Proximity Values and States"""
ir_prox = await self.get_7x_ir_proximity()
if ir_prox is not None:
return ir_prox

ir_prox = await self.get_6x_ir_proximity()
if ir_prox is not None:
print('Warning: ir_prox() missing seventh value; you may need to update your robot')
ir_prox.sensors.append(float('nan'))
return ir_prox

return None

async def get_position(self):
"""Get robot's position and heading."""
dev, cmd, inc = 1, 16, self.inc
completer = Completer()
self._responses[(dev, cmd, inc)] = completer
Expand All @@ -101,6 +122,7 @@ async def get_position(self):
return None

async def reset_navigation(self):
"""Request that robot resets position and heading."""
await self._backend.write_packet(Packet(1, 15, self.inc))

async def navigate_to(self, x: Union[int, float], y: Union[int, float], heading: Union[int, float] = None):
Expand Down Expand Up @@ -175,4 +197,4 @@ async def get_version_string(self) -> str:

return '.'.join([major, str(minor), str(patch)])
except IndexError:
return None;
return None

0 comments on commit 807419c

Please sign in to comment.