def __init__(self, msg="", msgtype = MSGTYPE.INFO, freq=1000, length=0, repeat=1 ):
self.msg = msg
self.f = freq
self.l = length
self.r = repeat
self.beep = length>0
self.type = msgtype
def beepMsg(self, msg):
if self.beepOn and msg.beep:
os.system("beep -f "+str(msg.f)+"-l "+str(msg.l)+" -r "+str(msg.r)+"&")
if msg.msg != "":
if msg.type == MSGTYPE.INFO:
rospy.loginfo(msg.msg)
elif msg.type == MSGTYPE.WARN:
rospy.logwarn(msg.msg)
elif msg.type == MSGTYPE.ERROR:
rospy.logerr(msg.msg)
elif msg.type == MSGTYPE.DEBUG:
rospy.logdebug(msg.msg)
else:
rospy.logerr("UNKNOWN MESSAGE TYPE: %s", msg.msg)
self.ui.statusbar.showMessage(msg.msg, 0)
def run(self):
rospy.init_node('CrazyflieDriverUSB%d' % self.options.radio,
log_level=rospy.DEBUG if self.options.debug else rospy.INFO,
disable_signals=True,
anonymous=False)
def main():
"""SDK Gripper Button Control Example
Connects cuff buttons to gripper open/close commands:
'Circle' Button - open gripper
'Dash' Button - close gripper
Cuff 'Squeeze' - turn on Nav lights
Run this example in the background or in another terminal
to be able to easily control the grippers by hand while
using the robot. Can be run in parallel with other code.
"""
rp = RobotParams()
valid_limbs = rp.get_limb_names()
if not valid_limbs:
rp.log_message(("Cannot detect any limb parameters on this robot. "
"Exiting."), "ERROR")
return
if len(valid_limbs) > 1:
valid_limbs.append("all_limbs")
arg_fmt = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(formatter_class=arg_fmt,
description=main.__doc__)
parser.add_argument('-g', '--gripper', dest='gripper', default=valid_limbs[0],
choices=[valid_limbs],
help='gripper limb to control (default: both)')
parser.add_argument('-n', '--no-lights', dest='lights',
action='store_false',
help='do not trigger lights on cuff grasp')
parser.add_argument('-v', '--verbose', dest='verbosity',
action='store_const', const=rospy.DEBUG,
default=rospy.INFO,
help='print debug statements')
args = parser.parse_args(rospy.myargv()[1:])
rospy.init_node('sdk_gripper_cuff_control_{0}'.format(args.gripper),
log_level=args.verbosity)
arms = (args.gripper,) if args.gripper != 'all_limbs' else valid_limbs[:-1]
grip_ctrls = [GripperConnect(arm, args.lights) for arm in arms]
print("Press cuff buttons for gripper control. Spinning...")
rospy.spin()
print("Gripper Button Control Finished.")
return 0