def _start(self, spin):
for args, kwargs in self.subscribers:
self.subscribers_init.append(rospy.Subscriber(*args, **kwargs))
is_func = isinstance(self.cl, types.FunctionType)
is_class = isinstance(self.cl, types.TypeType)
if is_class:
targ = self.__start_class
elif is_func:
targ = self.__start_func
self.thread = threading.Thread(target=targ,
args=(self.cl,) + self.cl_args,
kwargs=self.cl_kwargs)
self.thread.daemon = True
self.thread.start()
if spin:
rospy.spin()
return self
python类spin()的实例源码
tf_broadcast_transform_pre_cleanup.py 文件源码
项目:amosero
作者: PaulPetring
项目源码
文件源码
阅读 16
收藏 0
点赞 0
评论 0
def listener():
global odom_pub,left_motor_pub,left_motor_speed_pub,right_motor_pub,right_motor_speed_pub
#subscribing to required topics
rospy.Subscriber("/cmd_vel", Twist, cmd_velCb)
rospy.Subscriber('imu_data',Imu,imuCb)
rospy.Subscriber('north',std_msgs.msg.Float32,northCb)
odom_pub = rospy.Publisher('/odom', Odometry, queue_size=10)
left_motor_pub = rospy.Publisher('/left_motor', std_msgs.msg.Int32, queue_size=10)
right_motor_pub = rospy.Publisher('/right_motor', std_msgs.msg.Int32, queue_size=10)
#left_motor_speed_pub = rospy.Publisher('/left_motor_speed', std_msgs.msg.Int32, queue_size=10)
#right_motor_speed_pub = rospy.Publisher('/right_motor_speed', std_msgs.msg.Int32, queue_size=10)
rospy.spin()
def __init__(self):
rospy.init_node('multiplexer_node', anonymous=False)
rospy.loginfo('\033[93m[%s]\033[0m wait for bringup social_events_memory...'%rospy.get_name())
rospy.wait_for_service('social_events_memory/read_data')
self.rd_event_mem = rospy.ServiceProxy('social_events_memory/read_data', ReadData)
rospy.Subscriber('forwarding_event', ForwardingEvent, self.handle_social_events)
self.pub_rasing_event = rospy.Publisher('raising_events', RaisingEvents, queue_size=10)
self.events_queue = Queue.Queue()
self.recognized_words_queue = Queue.Queue()
event_period = rospy.get_param('~event_period', 0.5)
rospy.Timer(rospy.Duration(event_period), self.handle_trigger_events)
rospy.loginfo('\033[93m[%s]\033[0m initialized...'%rospy.get_name())
rospy.spin()
def talker():
pub = rospy.Publisher('chatter', String, queue_size=10)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep()
# rate = rospy.Rate(10)
# hello_str = "hello world"
# rospy.loginfo(hello_str)
# pub.publish(hello_str)
# rospy.spin()
# exit(0)
def listener():
global odom_pub,left_motor_pub,left_motor_speed_pub,right_motor_pub,right_motor_speed_pub
#subscribing to required topics
rospy.Subscriber("/cmd_vel", Twist, cmd_velCb)
rospy.Subscriber('imu_data',Imu,imuCb)
rospy.Subscriber('north',std_msgs.msg.Float32,northCb)
odom_pub = rospy.Publisher('/odom', Odometry, queue_size=10)
left_motor_pub = rospy.Publisher('/left_motor', std_msgs.msg.Int32, queue_size=10)
right_motor_pub = rospy.Publisher('/right_motor', std_msgs.msg.Int32, queue_size=10)
#left_motor_speed_pub = rospy.Publisher('/left_motor_speed', std_msgs.msg.Int32, queue_size=10)
#right_motor_speed_pub = rospy.Publisher('/right_motor_speed', std_msgs.msg.Int32, queue_size=10)
rospy.spin()
def listener():
global odom_pub,left_motor_pub,left_motor_speed_pub,right_motor_pub,right_motor_speed_pub
#subscribing to required topics
rospy.Subscriber("/cmd_vel", Twist, cmd_velCb)
rospy.Subscriber('imu_data',Imu,imuCb)
rospy.Subscriber('north',std_msgs.msg.Float32,northCb)
odom_pub = rospy.Publisher('/odom', Odometry, queue_size=10)
left_motor_pub = rospy.Publisher('/left_motor', std_msgs.msg.Int32, queue_size=10)
right_motor_pub = rospy.Publisher('/right_motor', std_msgs.msg.Int32, queue_size=10)
#left_motor_speed_pub = rospy.Publisher('/left_motor_speed', std_msgs.msg.Int32, queue_size=10)
#right_motor_speed_pub = rospy.Publisher('/right_motor_speed', std_msgs.msg.Int32, queue_size=10)
rospy.spin()
def ros_loop(test):
while True:
rospy.Subscriber('human_turn_topic', String, human_turn)
rospy.Subscriber('human_chosen_topic', String, have_chosen)
rospy.Subscriber('human_predict_turn_topic', String, human_predict)
rospy.Subscriber('robot_turn_topic', String, robot_turn)
rospy.Subscriber('robot_chosen_topic', String, have_chosen)
rospy.Subscriber('story_telling', String, new_phrase)
rospy.Subscriber('new_element', String, new_element)
rospy.sleep(0.1)
rospy.spin()
################################################
def ros_loop(test):
while True:
rospy.Subscriber('human_turn_topic', String, human_turn)
rospy.Subscriber('human_chosen_topic', String, have_chosen)
rospy.Subscriber('human_predict_turn_topic', String, human_predict)
rospy.Subscriber('robot_turn_topic', String, robot_turn)
rospy.Subscriber('robot_chosen_topic', String, have_chosen)
rospy.Subscriber('story_telling', String, new_phrase)
rospy.Subscriber('new_element', String, new_element)
rospy.sleep(0.1)
rospy.spin()
################################################
def ros_loop(test):
while True:
rospy.Subscriber('human_turn_topic', String, human_turn)
rospy.Subscriber('human_chosen_topic', String, have_chosen)
rospy.Subscriber('human_predict_turn_topic', String, human_predict)
rospy.Subscriber('robot_turn_topic', String, robot_turn)
rospy.Subscriber('robot_chosen_topic', String, have_chosen)
rospy.Subscriber('story_telling', String, new_phrase)
rospy.Subscriber('new_element', String, new_element)
rospy.sleep(0.1)
rospy.spin()
################################################
def main():
rospy.init_node("whatsapp_service")
cred = credentials.WHATSAPP
stackBuilder = YowStackBuilder()
stack = (stackBuilder
.pushDefaultLayers(True)
.push(AideRosLayer)
.build())
loginfo("Stack built...")
stack.setCredentials(cred)
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) # sending the connect signal
loginfo("Connected...")
atexit.register(lambda: stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT)))
th = threading.Thread(target=stack.loop)
th.daemon = True
th.start()
loginfo("Running in background.")
loginfo("All done. spinning.")
while not rospy.is_shutdown():
rospy.spin()
def main():
rospy.init_node("actions")
loginfo("Creating action handler...")
action_handler = ActionHandler()
loginfo("Registering services...")
get_service_handler(CallFunction).register_service(
lambda func_name, kwargs: action_handler.call_func(func_name, **json.loads(kwargs))
)
rospy.Subscriber("/aide/update_apis", String, lambda x: action_handler.reload_api_references(x.data))
get_service_handler(GetActionProvider).register_service(lambda name: action_handler.get_action_provider(name) or ())
get_service_handler(GetAllActionProviders).register_service(action_handler.get_all_action_providers)
get_service_handler(AddActionProvider).register_service(action_handler.add_action_provider)
get_service_handler(DeleteActionProvider).register_service(action_handler.remove_action_provider)
loginfo("Registered services. Spinning.")
rospy.spin()
def main():
rospy.init_node("api_handler")
loginfo("Creating api handler...")
notify_publisher = rospy.Publisher("/aide/update_apis", String, queue_size=50)
api = ApiHandler(lambda x: notify_publisher.publish(x))
loginfo("Registering services...")
get_service_handler(GetApi).register_service(lambda **args: api.get_api(**args) or ())
get_service_handler(GetAllApis).register_service(api.get_all_apis)
get_service_handler(AddApi).register_service(api.add_api)
get_service_handler(DeleteApi).register_service(api.remove_api)
loginfo("Registered services. Spinning.")
rospy.spin()
def ControlListener():
rospy.init_node('robot_motion_control', anonymous=True)
rospy.Subscriber("robot1Com", controldata, callback1)
P1.pub = rospy.Publisher('/home1/command', Vector3, queue_size=10)
rospy.Subscriber("robot2Com", controldata, callback2)
P2.pub = rospy.Publisher('/home2/command', Vector3, queue_size=10)
while not rospy.is_shutdown():
rospy.spin()
return
# spin() simply keeps python from exiting until this node is stopped
#rospy.spin()
def drive(self):
while not rospy.is_shutdown():
if self.received_data is None or self.parsed_data is None:
rospy.sleep(0.5)
continue
if np.any(self.parsed_data['front'][:,0] < MIN_FRONT_DIST):
rospy.loginfo("stoping!")
# this is overkill to specify the message, but it doesn't hurt
# to be overly explicit
drive_msg_stamped = AckermannDriveStamped()
drive_msg = AckermannDrive()
drive_msg.speed = 0.0
drive_msg.steering_angle = 0.0
drive_msg.acceleration = 0
drive_msg.jerk = 0
drive_msg.steering_angle_velocity = 0
drive_msg_stamped.drive = drive_msg
self.pub.publish(drive_msg_stamped)
# don't spin too fast
rospy.sleep(.1)
def start():
# create ros node handle
nh = rospy.init_node('beziermapping')
#nh = "fff"
# create mapping obj
mp = mapping(nh)
rospy.spin()
'''r = rospy.Rate(150)
while not rospy.is_shutdown():
if mp._run_bz_controller:
mp._pub_thrust_sp_desired()
r.sleep()'''
def __init__(self):
'''
Instance variables
'''
#constants for racecar speed and angle calculations
self.pSpeed = 0.3
self.pAngle = 1
#positive charge behind racecar to give it a "kick" (forward vector)
self.propelling_charge = 6
#charge pushing on the car from the laser points
self.charge = 0.005
'''
Node setup and start
'''
rospy.init_node('grand_prix', anonymous=False)
self.drive = rospy.Publisher('/vesc/ackermann_cmd_mux/input/navigation', AckermannDriveStamped, queue_size=5)
rospy.Subscriber('scan', LaserScan, self.laserCall)
'''
Leave the robot going until roscore dies, then set speed to 0
'''
rospy.spin()
self.drive.publish(AckermannDriveStamped())
def __init__(self,bool_direction):
print "Beginning wall follow"
#setup the node
rospy.init_node('wall_follower', anonymous=False)
rospy.on_shutdown(self.shutdown)
self.right = bool_direction
# node specific topics (remap on command line or in launch file)
self.drive = rospy.Publisher('/vesc/ackermann_cmd_mux/input/navigation', AckermannDriveStamped, queue_size=5)
#sets the subscriber
rospy.Subscriber('scan', LaserScan, self.laserCall)
rospy.Subscriber('blob_info', blob_detect,self.blobCall)
rospy.spin()
# always make sure to leave the robot stopped
self.drive.publish(AckermannDriveStamped())
def __init__(self,bool_direction):
print "Beginning wall follow"
#setup the node
rospy.init_node('wall_follower', anonymous=False)
rospy.on_shutdown(self.shutdown)
self.right = bool_direction
# node specific topics (remap on command line or in launch file)
self.drive = rospy.Publisher('/vesc/ackermann_cmd_mux/input/navigation', AckermannDriveStamped, queue_size=5)
#sets the subscriber
rospy.Subscriber('scan', LaserScan, self.laserCall)
rospy.Subscriber('blob_info', blob_detect,self.blobCall)
rospy.spin()
# always make sure to leave the robot stopped
self.drive.publish(AckermannDriveStamped())
def listenerDomainNameProblem(self):
'''
listen on the topic domain_problem_from_controller_topic
It get a String msg structured like [problemDirectory__problemName]
The callback function is resolvProblemAsTopic which take the data received in parameter
:param: void
:return: void
'''
rospy.Subscriber("domain_problem_from_controller_topic",
String, self.resolvProblemAsTopic)
print(">> Ready to be requested, waiting a std_msgs/String...")
print(">> Topic : /domain_problem_from_controller_topic...")
print(">> Callback : resolvProblemAsTopic...")
print("############################"
+ "######################################")
rospy.spin()
inverse_perspective_mapping_node.py 文件源码
项目:autonomous_driving
作者: StatueFungus
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def __init__(self, node_name, sub_topic, pub_topic):
self.img_prep = ImagePreparator()
self.bridge = CvBridge()
self.camera = None
self.horizon_y = None
self.transformation_matrix = None
self.image_resolution = DEFAULT_RESOLUTION
self.transformated_image_resolution = DEFAULT_RESOLUTION
self.image_pub = rospy.Publisher(pub_topic, Image, queue_size=QUEUE_SIZE)
rospy.init_node(node_name, anonymous=True)
self.image_sub = rospy.Subscriber(sub_topic, Image, self.callback)
rospy.spin()
def main():
node = SignalMonitor()
rospy.spin()
def exec_(self):
if self.show_plots:
import sys
import pyqtgraph
if sys.flags.interactive != 1 or not hasattr(QtCore, 'PYQT_VERSION'):
pyqtgraph.QtGui.QApplication.exec_()
else:
rospy.spin()
def exec_(self):
rospy.spin()
def __init__(self):
if rospy.has_param('~orientation_offset'):
# Orientation offset as quaterion q = [x,y,z,w].
self.orientation_offset = rospy.get_param('~orientation_offset')
else:
yaw_offset_deg = rospy.get_param('~yaw_offset_deg', 0.0)
self.orientation_offset = tf.quaternion_from_euler(0.0, 0.0, math.radians(yaw_offset_deg))
rospy.Subscriber(rospy.get_name() + "/imu_in", Imu, self.imu_callback)
self.pub_imu_out = rospy.Publisher(rospy.get_name() + '/imu_out',
Imu, queue_size=10)
rospy.spin()
def __init__(self):
# Read Settings
self.read_settings()
# Init other variables
self._num_magnetometer_reads = 0
self._latest_bearings = np.zeros(shape = (self._number_samples_average, 1))
self._received_enough_samples = False
# Subscribe to magnetometer topic
rospy.Subscriber("magnetic_field", Vector3Stamped, self.magnetic_field_callback)
# Publishers
self._pub_bearing_raw = rospy.Publisher(rospy.get_name() + '/bearing_raw_deg',
Float64, queue_size = 10)
self._pub_bearing_avg = rospy.Publisher(rospy.get_name() + '/bearing_avg_deg',
Float64, queue_size = 10)
self._pub_imu_bearing_avg = rospy.Publisher(rospy.get_name() + '/imu_bearing_avg',
Imu, queue_size = 10)
if self._verbose:
self._pub_mag_corrected = rospy.Publisher(rospy.get_name() + '/mag_corrected',
Vector3Stamped, queue_size = 10)
rospy.spin()
def main():
rospy.init_node("listener")
sub = rospy.Subscriber("/chatter_topic", String, callback)
rospy.spin()
def main():
from optparse import OptionParser
rospy.init_node('cameracheck')
parser = OptionParser()
parser.add_option("-s", "--size", default="8x6", help="specify chessboard size as nxm [default: %default]")
parser.add_option("-q", "--square", default=".108", help="specify chessboard square size in meters [default: %default]")
options, args = parser.parse_args()
size = tuple([int(c) for c in options.size.split('x')])
dim = float(options.square)
CameraCheckerNode(size, dim)
rospy.spin()
def main():
rospy.init_node('easy_handeye')
while rospy.get_time() == 0.0:
pass
cw = HandeyeServer()
rospy.spin()
def main():
rgb_object_detection = RGBObjectDetection()
rospy.init_node('rgb_object_detection', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")
def main():
store_data = StoreData()
rospy.init_node('store_data', anonymous=True)
try:
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")