Skip to content

Commit

Permalink
feat: Implements JVL command for zeroing position encoder, calls on w…
Browse files Browse the repository at this point in the history
…inch startup
  • Loading branch information
figuernd committed Aug 9, 2023
1 parent 3748a66 commit 68d1ea7
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ devel_isolated
rosbags
__pycache__
.venv
logs
logs

# Ignore all configs except example
configs
!configs/example.yaml
1 change: 1 addition & 0 deletions src/jvl_motor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_service_files(
SetPositionEnvelopeCmd.srv
SetVelocityCmd.srv
StopCmd.srv
ZeroCmd.srv
)

generate_messages(
Expand Down
15 changes: 14 additions & 1 deletion src/jvl_motor/src/jvl_motor_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ def write_registers(client, reg_values):
if not success:
raise RuntimeError('Failed to write registers')

def cmd_zero_position(client, request):
try:
write_registers(client, {
mac400.P_IST: 0
})
except RuntimeError:
rospy.logerr('Failed to clear position encoder')
return srv.ZeroCmdResponse()

def cmd_set_position(client, request):
try:
Expand Down Expand Up @@ -148,9 +156,14 @@ def main():
msg.Motion,
queue_size=1
)

# Create services
services = [
rospy.Service(
'~zero_position',
srv.ZeroCmd,
functools.partial(cmd_zero_position, client)
),
rospy.Service(
'~set_position',
srv.SetPositionCmd,
Expand Down
4 changes: 4 additions & 0 deletions src/jvl_motor/srv/ZeroCmd.srv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# ZeroCmd
# Resets the position encoder by zeroing the encoder register.

---
8 changes: 6 additions & 2 deletions src/phyto_arm/src/winch_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from ds_sensor_msgs.msg import DepthPressure
from jvl_motor.msg import Motion
from jvl_motor.srv import SetPositionEnvelopeCmd, SetVelocityCmd, StopCmd
from jvl_motor.srv import SetPositionEnvelopeCmd, SetVelocityCmd, StopCmd, ZeroCmd

from phyto_arm.msg import MoveToDepthAction, MoveToDepthFeedback, \
MoveToDepthResult
Expand Down Expand Up @@ -84,6 +84,7 @@ def __getattr__(self, name):


# Service proxies for interacting with the motor
zero_position = rospy.ServiceProxy('/motor/zero_position', ZeroCmd)
set_position_envelope = rospy.ServiceProxy('/motor/set_position_envelope',
SetPositionEnvelopeCmd)
set_velocity = rospy.ServiceProxy('/motor/set_velocity', SetVelocityCmd)
Expand Down Expand Up @@ -324,9 +325,12 @@ async def main():
rospy.core.add_preshutdown_hook(lambda reason: loop.stop())

# Wait for services to become available
for svc in [ set_velocity, set_position_envelope, stop ]:
for svc in [ zero_position, set_velocity, set_position_envelope, stop ]:
svc.wait_for_service()

# Reset the position encoder to zero
zero_position()

# Subscribe to incoming messages
rospy.Subscriber('/ctd/depth', DepthPressure, depth.update_soon)
rospy.Subscriber('/motor/motion', Motion, motor.update_soon)
Expand Down

0 comments on commit 68d1ea7

Please sign in to comment.