Initial commit
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import rospy
|
||||
from pynput import keyboard
|
||||
from threading import Thread
|
||||
from nav_msgs.msg import Odometry
|
||||
|
||||
class Rebpublic:
|
||||
def __init__(self):
|
||||
self.is_pub = True
|
||||
self.lidar_odom1_pub = rospy.Publisher("/m2/gpsOdom1", Odometry, queue_size=1)
|
||||
|
||||
def on_press(self, key):
|
||||
try:
|
||||
if key.char == "q":
|
||||
self.is_pub = not self.is_pub
|
||||
print(self.is_pub)
|
||||
except:
|
||||
print("error")
|
||||
|
||||
def odom_callback(self, data):
|
||||
if self.is_pub:
|
||||
self.lidar_odom1_pub.publish(data)
|
||||
print("publish", rospy.get_time())
|
||||
else:
|
||||
print("not publish", rospy.get_time())
|
||||
|
||||
def key_listen(self):
|
||||
with keyboard.Listener(on_press=self.on_press) as listener:
|
||||
listener.join()
|
||||
|
||||
def listen(self):
|
||||
rospy.Subscriber("/m2/gpsOdom", Odometry, self.odom_callback, queue_size=1)
|
||||
rospy.spin()
|
||||
|
||||
if __name__ == "__main__":
|
||||
rospy.init_node("republic", anonymous=True)
|
||||
rebpublic = Rebpublic()
|
||||
thread_key_listern = Thread(target=rebpublic.key_listen, args=())
|
||||
thread_key_listern.start()
|
||||
rebpublic.listen()
|
||||
Reference in New Issue
Block a user