本文整理汇总了Python中sensor_msgs.msg.Joy.buttons方法的典型用法代码示例。如果您正苦于以下问题:Python Joy.buttons方法的具体用法?Python Joy.buttons怎么用?Python Joy.buttons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sensor_msgs.msg.Joy
的用法示例。
在下文中一共展示了Joy.buttons方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compare_all
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def compare_all(data):
global k
last_row = csv_data[k-frequency_offset]
diff = Quaternion()
diff.x = round(float(last_row[1])-convert_ppm(data.channels[3]),4)
diff.y = round(float(last_row[2])-convert_ppm(data.channels[1]),4)
diff.z = round(float(last_row[4])-convert_ppm(data.channels[0]),4)
diff.w = round(float(last_row[5])+convert_ppm(data.channels[2]),4)
testing_pub.publish(diff)
if (k < len(csv_data)):
row = csv_data[k]
#log for post processing
#joystick log
c = csv.writer(open("/home/jinahadam/catkin_ws/src/testing/gps_joy.csv", "ab"))
c.writerow([data.header.stamp.secs,row[1],row[2],row[4],row[5]])
#rc Inn log
c = csv.writer(open("/home/jinahadam/catkin_ws/src/testing/rc_in.csv", "ab"))
c.writerow([data.header.stamp.secs,convert_ppm(data.channels[3]),convert_ppm(data.channels[1]),convert_ppm(data.channels[0]),convert_ppm(data.channels[2])])
msg = Joy()
msg.axes = (float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5]),float(row[6]),float(row[7]))
msg.buttons = (0,0,0,0,0,0,0,0,0,0,0)
k = k + 1
pub.publish(msg)
else:
#k = 0
print("Joystick & RC In data logged with GPS Time")
exit()
示例2: publish
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def publish(self):
cmd = Joy()
cmd.header.stamp = rospy.Time.now()
cmd.axes = self.axes_data
cmd.buttons = self.button_data
if self.debug: print cmd
self.pub.publish(cmd)
示例3: talker
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def talker():
pub = rospy.Publisher('joy', Joy, queue_size=20)
rospy.init_node('test', anonymous=True)
rate = rospy.Rate(100) # 10hz
bits=[]
#print axis,buttons
while not rospy.is_shutdown():
data = s.recvfrom(6144)
app_data = data[0]
app_data_addr = data[1]
app_data=app_data.strip("[]")
app_data=app_data.split(",")
app_data=map(int,app_data)
#print app_data
#app_data=[10,10,0,0,0,0,0,0,0,0]
recv = robot1.receiver(app_data)
app_axis_data,app_button_data=recv.sort_data()
axis,buttons=recv.joystick_data(app_axis_data,app_button_data)
joy=Joy()
joy.axes=axis
joy.buttons=buttons
#hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(app_data)
rospy.loginfo(buttons)
pub.publish(joy)
rate.sleep()
示例4: callback
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def callback(data):
pub = rospy.Publisher('joy', Joy)
buttons = [0] * (trigger_button + 1)
buttons[trigger_button] = 1
joy_msg = Joy()
joy_msg.buttons = buttons
pub.publish(joy_msg)
示例5: joy_callback
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def joy_callback(self, data):
joy = Joy()
joy.header.stamp = rospy.Time.now()
joy.axes = self.convert(data.axes)
joy.buttons = data.buttons
self.prev_input_axes = list(data.axes)
joy_pub = rospy.Publisher("/joy_relative/page_" + str(self.crt_page), Joy)
joy_pub.publish(joy)
示例6: run
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def run(self):
"""Loop that obtains the latest wiimote state, publishes the joystick data, and sleeps.
The Joy.msg message types calls for just two fields: float32[] axes, and int32[] buttons.
"""
rospy.loginfo("Wiimote joystick publisher starting (topic wiijoy).")
self.threadName = "Joy topic Publisher"
try:
while not rospy.is_shutdown():
(canonicalAccel, canonicalNunchukAccel, canonicalAngleRate) = self.obtainWiimoteData()
msg = Joy(header=None,
axes=[canonicalAccel[X], canonicalAccel[Y], canonicalAccel[Z]],
buttons=None)
# If a gyro is attached to the Wiimote, we add the
# gyro information:
if self.wiistate.motionPlusPresent:
msg.axes.extend([canonicalAngleRate[PHI], canonicalAngleRate[THETA], canonicalAngleRate[PSI]])
# Fill in the ROS message's buttons field (there *must* be
# a better way in python to declare an array of 11 zeroes...]
theButtons = [False,False,False,False,False,False,False,False,False,False,False]
theButtons[State.MSG_BTN_1] = self.wiistate.buttons[BTN_1]
theButtons[State.MSG_BTN_2] = self.wiistate.buttons[BTN_2]
theButtons[State.MSG_BTN_A] = self.wiistate.buttons[BTN_A]
theButtons[State.MSG_BTN_B] = self.wiistate.buttons[BTN_B]
theButtons[State.MSG_BTN_PLUS] = self.wiistate.buttons[BTN_PLUS]
theButtons[State.MSG_BTN_MINUS] = self.wiistate.buttons[BTN_MINUS]
theButtons[State.MSG_BTN_LEFT] = self.wiistate.buttons[BTN_LEFT]
theButtons[State.MSG_BTN_RIGHT] = self.wiistate.buttons[BTN_RIGHT]
theButtons[State.MSG_BTN_UP] = self.wiistate.buttons[BTN_UP]
theButtons[State.MSG_BTN_DOWN] = self.wiistate.buttons[BTN_DOWN]
theButtons[State.MSG_BTN_HOME] = self.wiistate.buttons[BTN_HOME]
msg.buttons = theButtons
measureTime = self.wiistate.time
timeSecs = int(measureTime)
timeNSecs = int(abs(timeSecs - measureTime) * 10**9)
# Add the timestamp
msg.header.stamp.secs = timeSecs
msg.header.stamp.nsecs = timeNSecs
try:
self.pub.publish(msg)
except rospy.ROSException:
rospy.loginfo("Topic wiijoy closed. Shutting down Joy sender.")
exit(0)
#rospy.logdebug("Joystick state:")
#rospy.logdebug(" Joy buttons: " + str(theButtons) + "\n Joy accel: " + str(canonicalAccel) + "\n Joy angular rate: " + str(canonicalAngleRate))
rospy.sleep(self.sleepDuration)
except rospy.ROSInterruptException:
rospy.loginfo("Shutdown request. Shutting down Joy sender.")
exit(0)
示例7: toPS3Msg
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def toPS3Msg(self):
joy = Joy()
joy.header = self.orig_msg.header
joy.buttons = [0] * 17
joy.axes = [0] * 20
if self.center:
joy.buttons[16] = 1
if self.select:
joy.buttons[0] = 1
if self.start:
joy.buttons[3] = 1
if self.L3:
joy.buttons[1] = 1
if self.R3:
joy.buttons[2] = 1
if self.square:
joy.axes[15] = -1.0
joy.buttons[15] = 1
if self.up:
joy.axes[4] = -1.0
joy.buttons[4] = 1
if self.down:
joy.axes[6] = -1.0
joy.buttons[6] = 1
if self.left:
joy.axes[7] = -1.0
joy.buttons[7] = 1
if self.right:
joy.axes[5] = -1.0
joy.buttons[5] = 1
if self.triangle:
joy.axes[12] = -1.0
joy.buttons[12] = 1
if self.cross:
joy.axes[14] = -1.0
joy.buttons[14] = 1
if self.circle:
joy.axes[13] = -1.0
joy.buttons[13] = 1
if self.L1:
joy.axes[10] = -1.0
joy.buttons[10] = 1
if self.R1:
joy.axes[11] = -1.0
joy.buttons[11] = 1
if self.L2:
joy.axes[8] = -1.0
joy.buttons[8] = 1
if self.R2:
joy.axes[9] = -1.0
joy.buttons[9] = 1
joy.axes[0] = self.left_analog_x
joy.axes[1] = self.left_analog_y
joy.axes[2] = self.right_analog_x
joy.axes[3] = self.right_analog_y
return joy
示例8: main
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def main():
global joy
pygame.midi.init()
rospy.init_node('midi_joy')
# parse the arg
argv = rospy.myargv()
if len(argv) == 0:
rospy.logfatal("You need to specify config yaml file")
sys.exit(1)
config_file = argv[1]
joy_pub = rospy.Publisher("/joy", Joy, queue_size=10)
autorepeat_rate = rospy.get_param("~autorepeat_rate", 0)
if autorepeat_rate == 0:
r = rospy.Rate(1000)
else:
r = rospy.Rate(autorepeat_rate)
with open(config_file, "r") as f:
config = yaml.load(f)
# open the device
controller = openMIDIInputByName(config["device_name"])
joy = Joy()
joy.axes = [0.0] * len(config["analogs"])
# automatically mapping to buttons from axes if it has NOTE_OFF or NOTE_ON MIDI commands
button_configs = [c for c in config["analogs"]
if c[0] == MIDICommand.NOTE_ON or c[0] == MIDICommand.NOTE_OFF]
if config.has_key("output"):
out_controller = openMIDIOutputByName(config["device_name"])
s = rospy.Subscriber("~set_feedback", JoyFeedbackArray, lambda msg: feedback_array_cb(out_controller, config, msg))
joy.buttons = [0] * len(button_configs)
while not rospy.is_shutdown():
joy.header.stamp = rospy.Time.now()
p = False
while controller.poll():
data = controller.read(1)
for elem_set in data:
p = True
(command, ind, val) = MIDIParse(elem_set)
try:
index = config["analogs"].index((command, ind))
joy.axes[index] = val
if command == MIDICommand.NOTE_ON or command == MIDICommand.NOTE_OFF:
button_index = button_configs.index((command, ind))
if val == 0.0:
joy.buttons[button_index] = 0
else:
joy.buttons[button_index] = 1
except:
rospy.logwarn("unknown MIDI message: (%d, %d, %f)" % (command, ind, val))
if (autorepeat_rate != 0) or p:
joy_pub.publish(joy)
r.sleep()
示例9: on_message
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def on_message(self, message_raw):
message = json.loads(message_raw)
if message['msg']=='lag':
self.send( json.dumps({
'start':message['start'],
}))
if message['msg']=='joy':
msg = Joy()
msg.header.stamp = rospy.Time.now()
msg.axes = message['axes']
msg.buttons = message['buttons']
joy_pub.publish(msg)
示例10: send
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def send(self):
joy_msg = Joy()
joy_msg.header.stamp = rospy.Time.now()
buttons = (self.ui.button_0, self.ui.button_1, self.ui.button_2, self.ui.button_3, self.ui.button_4,
self.ui.button_5, self.ui.button_6, self.ui.button_7, self.ui.button_8, self.ui.button_9,
self.ui.button_10, self.ui.button_11)
joy_msg.buttons = [b.isChecked() for b in buttons]
joy_msg.axes = [mult*s.value()/100.0 for s, mult in
zip((self.ui.rollSlider, self.ui.pitchSlider, self.ui.yawSlider, self.ui.altSlider), (-1.0, 1.0, -1.0, 1.0))]
for label, value in zip((self.ui.rollLabel, self.ui.pitchLabel, self.ui.yawLabel, self.ui.altLabel), joy_msg.axes):
label.setText('%0.2f' % value)
self.pub.publish(joy_msg)
示例11: run
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def run(self):
blub=Joy()
while(self.run):
data=ord(self.ser.read(1))
if data==255:
data=ord(self.ser.read(1))
if data==255:
data=ord(self.ser.read(1))
if data==255:
data=ord(self.ser.read(1))
if data==24:
data=self.ser.read(7)
axes = struct.unpack('BBBBBBB', data)
for x in axes:
blub.axes.append((x-128)/127.0)
print blub.axes
data=self.ser.read(2)
button = struct.unpack('H', data)[0]
blub.buttons.insert(0,int(button/2048))
button-=(int(button/2048))*button
blub.buttons.insert(0,int(button/1024))
button-=(int(button/1024))*button
blub.buttons.insert(0,int(button/512))
button-=(int(button/512))*button
blub.buttons.insert(0,int(button/256))
button-=(int(button/256))*button
blub.buttons.insert(0,int(button/128))
button-=(int(button/128))*button
blub.buttons.insert(0,int(button/64))
button-=(int(button/64))*button
blub.buttons.insert(0,int(button/32))
button-=(int(button/32))*button
blub.buttons.insert(0,int(button/16))
button-=(int(button/16))*button
blub.buttons.insert(0,int(button/8))
button-=(int(button/8))*button
blub.buttons.insert(0,int(button/4))
button-=(int(button/4))*button
blub.buttons.insert(0,int(button/2))
button-=(int(button/2))*button
blub.buttons.insert(0,int(button))
print blub
blub.axes=list()
blub.buttons=list()
self.ser.close()
示例12: main
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def main():
rospy.sleep(1)
rospy.init_node('trackpoint_joy')
trackpoint_joy_pub = rospy.Publisher('/trackpoint/joy', Joy)
tp_file = open( "/dev/input/mice", "rb" )
while not rospy.is_shutdown():
buf = tp_file.read(3)
button = ord( buf[0] )
bLeft = button & 0x1
bMiddle = ( button & 0x4 ) > 0
bRight = ( button & 0x2 ) > 0
x,y = struct.unpack( "bb", buf[1:] )
rospy.loginfo("L:%d, M: %d, R: %d, x: %d, y: %d\n" % (bLeft, bMiddle, bRight, x, y) )
joy_msg = Joy()
joy_msg.header.stamp = rospy.Time.now()
joy_msg.axes = [x, y]
joy_msg.buttons = [bLeft, bMiddle, bRight]
trackpoint_joy_pub.publish(joy_msg)
# rospy.sleep(0.1)
tp_file.close();
示例13: comapre_single_channel
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def comapre_single_channel(data):
global k
last_row = csv_data[k-frequency_offset]
lat = Pose2D()
lat.x = float(last_row[1])
lat.y = convert_ppm(data.channels[3])
lat.theta = 0
latency_ch.publish(lat)
if (k < len(csv_data)):
row = csv_data[k]
msg = Joy()
msg.axes = (float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5]),float(row[6]),float(row[7]))
msg.buttons = (0,0,0,0,0,0,0,0,0,0,0)
k = k + 1
pub.publish(msg)
else:
k = 0
示例14: main
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def main():
pub = rospy.Publisher('ernest_sensors/imu', Imu, queue_size=10)
eyes = rospy.Publisher('ernest_sensors/eyes', Range, queue_size=10)
nunchuck = rospy.Publisher('ernest_sensors/joy', Joy, queue_size=10)
nunchuck_giro = rospy.Publisher('ernest_sensors/joy_giro', Imu, queue_size=10)
comm = ArduinoCommunicator()
rospy.init_node('ernest_sensors')
for line in comm.loop():
print line
try:
x, y, z, dis, joy_x, joy_y, giro_x, giro_y, giro_z, but_c, but_z = line.split(",")
imu = Imu()
imu.header.frame_id = "imu"
imu.linear_acceleration.x = -float(x)
imu.linear_acceleration.y = float(z)
imu.linear_acceleration.z = float(y)
r = Range()
r.header.frame_id = "imu"
r.radiation_type = 1
r.field_of_view = 0.5
r.min_range = 0.20
r.max_range = 3
r.range = float(dis)/100.0
j = Joy()
j.axes = [
maprange(float(joy_x), 25, 226, -1, 1),
maprange(float(joy_y), 32, 223, -1, 1)
]
j.buttons = [int(but_c), int(but_z)]
imu2 = Imu()
imu2.header.frame_id = "imu"
imu2.linear_acceleration.x = (float(giro_y) - 512) / 512.0
imu2.linear_acceleration.y = -(float(giro_x) - 512) / 512.0
imu2.linear_acceleration.z = -(float(giro_z) - 512) / 512.0
pub.publish(imu)
eyes.publish(r)
nunchuck.publish(j)
nunchuck_giro.publish(imu2)
except ValueError:
continue
示例15: diff
# 需要导入模块: from sensor_msgs.msg import Joy [as 别名]
# 或者: from sensor_msgs.msg.Joy import buttons [as 别名]
def diff(data):
global k
last_row = csv_data[k-frequency_offset]
diff = Quaternion()
diff.x = round(float(last_row[1])-convert_ppm(data.channels[3]),4)
diff.y = round(float(last_row[2])-convert_ppm(data.channels[1]),4)
diff.z = round(float(last_row[4])-convert_ppm(data.channels[0]),4)
diff.w = round(float(last_row[5])+convert_ppm(data.channels[2]),4)
testing_pub.publish(diff)
if (k < len(csv_data)):
row = csv_data[k]
msg = Joy()
msg.axes = (float(row[1]),float(row[2]),float(row[3]),float(row[4]),float(row[5]),float(row[6]),float(row[7]))
msg.buttons = (0,0,0,0,0,0,0,0,0,0,0)
k = k + 1
pub.publish(msg)
else:
k = 0