Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information...
rLinks234 committed May 17, 2018
0 parents commit dcac806b76c48fd9d2e4aae2838d30e933bef142
@@ -0,0 +1,10 @@
# Virtual Env
venv/

# PyCharm/JetBrains folders
.idea/

# Byte compiled / optimized files
__pycache__/
*.py[cod]
*$py.class
@@ -0,0 +1,16 @@
#!/usr/bin/env python3

import hebi
from time import sleep

lookup = hebi.Lookup()
group = lookup.get_group_from_names(['X5-4'], ['X5-0000'])

command = hebi.GroupCommand(group.size)
# Set the control strategy for all the modules
command.control_strategy = 'strategy2'

if group.send_command_with_acknowledgement(command, 100):
print('Got acknowledgement')
else:
print('Did not receive acknowledgement!')
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

import hebi
from time import sleep

lookup = hebi.Lookup()
group = lookup.get_group_from_names(['family'], ['base', 'shoulder', 'elbow'])

command = hebi.GroupCommand(group.size)

# Set gains. If this doesn't succeed, it may be because the number of modules
# in the group doesn't match the number in the XML, or the file was corrupt.

try:
command.read_gains('gains.xml')
print('Successfully read gains from file; now sending to module.')
group.send_command(command)
except:
print('Could not read gains from file')
@@ -0,0 +1,48 @@
#!/usr/bin/env python3

import hebi
from time import sleep

lookup = hebi.Lookup()
group = lookup.get_group_from_names(['family'], ['name'])

# Set command lifetime to 100 ms
group.command_lifetime = 100

group_command = hebi.GroupCommand(group.size)

# Set the LED red
group_command.led.color = 'red'
group.send_command(group_command)

sleep(3)

# Set the LED Blue, and then clear the command.
# Note that this "clear" does not return the LED to module control, but
# rather remove any LED command from the command object, so when this is sent
# to the module the LED state won't be affected.
group_command.led.color = 'blue'
group_command.led.color = None
group.send_command(group_command)

sleep(3)

# Set the LED to "module control" mode; the first three digits are ignored
# if the 'alpha' value is zero.
group_command.led.color = 'transparent'
group.send_command(group_command)

sleep(3)

# Set the LED purple. Note that this override automatically sets the alpha
# channel to "255" (e.g., arguments are RGB).
group_command.led.color = hebi.Color(0, 255, 255)
group.send_command(group_command)

sleep(3)

# Set the LED to module control.
group_command.led.color = 'transparent'
group.send_command(group_command)

return 0;
@@ -0,0 +1,36 @@
#!/usr/bin/env python3

import hebi
from time import sleep

lookup = hebi.Lookup()
group = lookup.get_group_from_names(['X5-4'], ['X5-0000'])

if group == None:
print('No group found!')
exit(1)

new_name = raw_input('Enter a new name for this module:')

command = hebi.GroupCommand(group.size)

# Note that you **must** pass a list as the value here, as opposed to just a string.
# This is intentional; some fields (e.g., "name" field) in a group command
# cannot be set with a scalar value.
# The reasoning behind this is to prevent a user from accidentally setting
# all modules in a group the same name.
#
# If you try to set "name" with a scalar value (e.g., `"foo"` instead of `["foo"]`)
# an exception will be raised, informing you that you cannot broadcast a
# scalar value to this field in all modules of the group.
command.name = [ new_name ]

# Mark that settings should be persisted across reboots
command.save_current_settings = True

print('Setting and saving new module name. Restart and verify name has been reset.')

if group.send_command_with_acknowledgement(command, 100):
print('Got acknowledgement.')
else:
print('Did not receive acknowledgement!')
@@ -0,0 +1,55 @@
#!/usr/bin/env python3

import hebi
import numpy as np
from time import sleep
from math import sin

lookup = hebi.Lookup()
group = lookup.get_group_from_names(['X5-4'], ['X5-0000'])

if group == None:
print('No group found!')
exit(1)

command = hebi.GroupCommand(group.size)

# Send commands to the group in a loop.
# Note that these packets may be dropped if network traffic is too high, so
# be sure to close a feedback loop at the high level!
period = 0.5
t = 0.0

positions = np.empty(group.size, dtype=np.float64)
while t < 10.0:
for module_index in range(0, group.size):
positions[i] = sin((t * 0.5) + (module_index * 0.25))

command.position = positions
group.send_command(command)
sleep(period)
t = t + period

# For critical packets, we can verify that they were sent by requesting
# confirmation from the group. If the acknowledgement function returns
# 'True', it got positive confirmation. If it returns 'False', EITHER:
# - the sent command was dropped
# - the sent command was received by the group, but its response was either
# dropped or the timeout period expired before receipt of the group.
# Again, a high-level process should intelligently handle these conditions!
# Note that this is a blocking call, and so for high-frequency applications,
# send_command should be used instead.
timeout_ms = 100

while t < 10.0:
for module_index in range(0, group.size):
positions[i] = sin((t * 0.5) + (module_index * 0.25))

command.position = positions
if group.send_command_with_acknowledgement(command):
print('Got acknowledgement.')
else:
print('Did not receive acknowledgement!')

sleep(period)
t = t + period
@@ -0,0 +1,24 @@
#!/usr/bin/env python3

import hebi
import numpy as np
from time import sleep
from math import sin

lookup = hebi.Lookup()
group = lookup.get_group_from_names(['X5-4'], ['X5-0000'])

if group == None:
print('No group found!')
exit(1)

command = hebi.GroupCommand(group.size)

# Set the name for this module, based on its index within the group.
# (Note - we do not save this value, so upon module reset this will be cleared)
command.name = [ str(entry) for entry in range(0, group.size) ]

if group.send_command_with_acknowledgement(command, 100):
print('Got acknowledgement.')
else:
print('Did not receive acknowledgement!')
@@ -0,0 +1,33 @@
#!/usr/bin/env python3

import hebi
from time import sleep

lookup = hebi.Lookup()
sleep(2)

master = lookup.get_group_from_names(['HEBI'], ['master'])
slave = lookup.get_group_from_names(['HEBI'], ['slave'])

if (master == None) or (slave == None):
print('Groups not found!')
exit(1)
elif master.size != slave.size:
print('Groups must be same size for master/slave control')
exit(1)

command = hebi.GroupCommand(slave.size)

def feedback_handler(group_fbk):
command.position = group_fbk.position
slave.send_command(command)

# Start feedback callbacks
master.add_feedback_handler(feedback_handler)
master.feedback_frequency = 200.0

sleep(20)

# Stop the async callback before returning and deleting objects.
master.feedback_frequency = 0.0
master.clear_feedback_handlers()
Oops, something went wrong.

0 comments on commit dcac806

Please sign in to comment.
You can’t perform that action at this time.