def callback(self, inmsg): global extract_warn outmsg = Joy() outmsg.buttons = remap(inmsg.buttons, self.button_mapping) outmsg.axes = remap(inmsg.axes, self.axis_mapping) self.pub.publish(outmsg) if not self.warned and extract_warn: self.warned = True rospy.logwarn("Out of range remapping. Setting to zero. Joystick has %i buttons and %i axes.")%(len(inmsg.buttons), len(inmsg.axes))
def callback(self, inmsg): global extract_warn outmsg = Joy() outmsg.buttons = remap(inmsg.buttons, self.button_mapping) outmsg.axes = remap(inmsg.axes, self.axis_mapping) self.pub.publish(outmsg) if not self.warned and extract_warn: self.warned = True rospy.logwarn( "Out of range remapping. Setting to zero. Joystick has %i buttons and %i axes." ) % (len(inmsg.buttons), len(inmsg.axes))
def run(self): """Loop that obtains the latest nunchuk state, publishes the joystick data, and sleeps. The Joy.msg message types calls for just two fields: float32[] axes, and int32[] buttons. """ self.threadName = "nunchuk Joy topic Publisher" try: while not rospy.is_shutdown(): (canonicalAccel, scaledAcc, canonicalAngleRate) = self.obtainWiimoteData() if not self.wiistate.nunchukPresent: continue if self.pub is None: self.pub = rospy.Publisher('/wiimote/nunchuk', Joy) rospy.loginfo( "Wiimote Nunchuk joystick publisher starting (topic nunchuk)." ) (joyx, joyy) = self.wiistate.nunchukStick msg = Joy( # the Joy msg does not have a header :-( header=None, axes=[ joyx, joyy, scaledAcc[X], scaledAcc[Y], scaledAcc[Z] ], buttons=None) theButtons = [False, False] theButtons[ State.MSG_BTN_Z] = self.wiistate.nunchukButtons[BTN_Z] theButtons[ State.MSG_BTN_C] = self.wiistate.nunchukButtons[BTN_C] msg.buttons = theButtons measureTime = self.wiistate.time timeSecs = int(measureTime) timeNSecs = int(abs(timeSecs - measureTime) * 10**9) # the Joy msg does not have a header :-( # msg.header.stamp.secs = timeSecs # msg.header.stamp.nsecs = timeNSecs self.pub.publish(msg) rospy.logdebug("nunchuk state:") rospy.logdebug(" nunchuk buttons: " + str(theButtons) + "\n Nuchuck axes: " + str(msg.axes) + "\n") rospy.sleep(self.sleepDuration) except rospy.ROSInterruptException: rospy.loginfo("Shutdown request. Shutting down Nun sender.") exit(0)
def run(self): """Loop that obtains the latest nunchuk state, publishes the joystick data, and sleeps. The Joy.msg message types calls for just two fields: float32[] axes, and int32[] buttons. """ self.threadName = "nunchuk Joy topic Publisher" try: while not rospy.is_shutdown(): (canonicalAccel, scaledAcc, canonicalAngleRate) = self.obtainWiimoteData() if not self.wiistate.nunchukPresent: continue if self.pub is None: self.pub = rospy.Publisher('/wiimote/nunchuk', Joy) rospy.loginfo("Wiimote Nunchuk joystick publisher starting (topic nunchuk).") (joyx, joyy) = self.wiistate.nunchukStick msg = Joy(# the Joy msg does not have a header :-( header=None, axes=[joyx, joyy, scaledAcc[X], scaledAcc[Y], scaledAcc[Z]], buttons=None) theButtons = [False,False] theButtons[State.MSG_BTN_Z] = self.wiistate.nunchukButtons[BTN_Z] theButtons[State.MSG_BTN_C] = self.wiistate.nunchukButtons[BTN_C] msg.buttons = theButtons measureTime = self.wiistate.time timeSecs = int(measureTime) timeNSecs = int(abs(timeSecs - measureTime) * 10**9) # the Joy msg does not have a header :-( # msg.header.stamp.secs = timeSecs # msg.header.stamp.nsecs = timeNSecs self.pub.publish(msg) rospy.logdebug("nunchuk state:") rospy.logdebug(" nunchuk buttons: " + str(theButtons) + "\n Nuchuck axes: " + str(msg.axes) + "\n") rospy.sleep(self.sleepDuration) except rospy.ROSInterruptException: rospy.loginfo("Shutdown request. Shutting down Nun sender.") exit(0)
def main(screen): screen.nodelay(1) # make getch() a non-blocking call pub = rospy.Publisher(PUBLISH_TOPIC, Joy) rospy.init_node(NODE_NAME) rate = rospy.Rate(LOOP_FREQ) while not rospy.is_shutdown(): keypress = screen.getch() if keypress > -1: keyval = chr(keypress) if keyval == "q": # quit rospy.signal_shutdown("User requested shutdown.") else: button = int(keyval) if button < 10: msg = Joy() msg.buttons = [0 for x in range(10)] msg.buttons[button] = 1 pub.publish(msg) rate.sleep()
def on_new_joy(msg,publisher): out = Joy() out.axes= msg.axes; out.buttons = msg.buttons; publisher[0].publish(out)