本文整理汇总了Python中rospy.Rate方法的典型用法代码示例。如果您正苦于以下问题:Python rospy.Rate方法的具体用法?Python rospy.Rate怎么用?Python rospy.Rate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rospy
的用法示例。
在下文中一共展示了rospy.Rate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendSetpoint
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def sendSetpoint():
# Input data
global setpoint, yawSetPoint, run, position_control
# Output data
local_setpoint_pub = rospy.Publisher('/mavros/setpoint_position/local', PoseStamped, queue_size=0)
rate = rospy.Rate(5)
while run:
q = tf.transformations.quaternion_from_euler(0, 0, deg2radf(yawSetPoint), axes="sxyz")
msg = PoseStamped()
msg.header.stamp = rospy.Time.now()
msg.pose.position.x = float(setpoint.x)
msg.pose.position.y = float(setpoint.y)
msg.pose.position.z = float(setpoint.z)
msg.pose.orientation.x = q[0]
msg.pose.orientation.y = q[1]
msg.pose.orientation.z = q[2]
msg.pose.orientation.w = q[3]
local_setpoint_pub.publish(msg)
rate.sleep()
示例2: spin
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def spin(self):
#############################################################
r = rospy.Rate(self.rate)
idle = rospy.Rate(10)
then = rospy.Time.now()
self.ticks_since_target = self.timeout_ticks
###### main loop ######
while not rospy.is_shutdown():
while not rospy.is_shutdown() and self.ticks_since_target < self.timeout_ticks:
self.spinOnce()
r.sleep()
idle.sleep()
#############################################################
示例3: talker_ctrl
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def talker_ctrl():
global rate_value
# publishes to thruster and rudder topics
pub_motor = rospy.Publisher('thruster_command', JointState, queue_size=10)
pub_rudder = rospy.Publisher('joint_setpoint', JointState, queue_size=10)
rospy.init_node('usv_simple_ctrl', anonymous=True)
rate = rospy.Rate(rate_value) # 10h
# subscribe to state and targer point topics
rospy.Subscriber("state", Odometry, get_pose) # get usv position (add 'gps' position latter)
rospy.Subscriber("usv_position_setpoint", Odometry, get_target) # get target position
while not rospy.is_shutdown():
pub_motor.publish(thruster_ctrl_msg())
pub_rudder.publish(rudder_ctrl_msg())
rate.sleep()
示例4: move_circle
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def move_circle():
# Create a publisher which can "talk" to Turtlesim and tell it to move
pub = rospy.Publisher('turtle1/cmd_vel', Twist, queue_size=1)
# Create a Twist message and add linear x and angular z values
move_cmd = Twist()
move_cmd.linear.x = 1.0
move_cmd.angular.z = 1.0
# Save current time and set publish rate at 10 Hz
now = rospy.Time.now()
rate = rospy.Rate(10)
# For the next 6 seconds publish cmd_vel move commands to Turtlesim
while rospy.Time.now() < now + rospy.Duration.from_sec(6):
pub.publish(move_cmd)
rate.sleep()
示例5: spin
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def spin(self):
###############################################
r = rospy.Rate
self.secs_since_target = self.timeout_secs
self.then = rospy.Time.now()
self.latest_msg_time = rospy.Time.now()
rospy.loginfo("-D- spinning")
###### main loop #########
while not rospy.is_shutdown():
while not rospy.is_shutdown() and self.secs_since_target < self.timeout_secs:
self.spinOnce()
r.sleep
self.secs_since_target = rospy.Time.now() - self.latest_msg_time
self.secs_since_target = self.secs_since_target.to_sec()
#rospy.loginfo(" inside: secs_since_target: %0.3f" % self.secs_since_target)
# it's been more than timeout_ticks since we recieved a message
self.secs_since_target = rospy.Time.now() - self.latest_msg_time
self.secs_since_target = self.secs_since_target.to_sec()
# rospy.loginfo(" outside: secs_since_target: %0.3f" % self.secs_since_target)
self.velocity = 0
r.sleep
###############################################
示例6: scaleWheel
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def scaleWheel():
rospy.init_node("wheel_scaler")
rospy.loginfo("wheel_scaler started")
scale = rospy.get_param('distance_scale', 1)
rospy.loginfo("wheel_scaler scale: %0.2f", scale)
rospy.Subscriber("lwheel", Int16, lwheelCallback)
rospy.Subscriber("rwheel", Int16, rwheelCallback)
lscaled_pub = rospy.Publisher("lwheel_scaled", Int16, queue_size=10)
rscaled_pub = rospy.Publisher("rwheel_scaled", Int16, queue_size=10)
### testing sleep CPU usage
r = rospy.Rate(50)
while not rospy.is_shutdown:
r.sleep()
rospy.spin()
示例7: talker_ctrl
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def talker_ctrl():
global rate_value
rospy.init_node('usv_simple_ctrl', anonymous=True)
rate = rospy.Rate(rate_value) # 10h
# publishes to thruster and rudder topics
pub_motor = rospy.Publisher('thruster_command', JointState, queue_size=10)
pub_rudder = rospy.Publisher('joint_setpoint', JointState, queue_size=10)
pub_result = rospy.Publisher('move_usv/result', Float64, queue_size=10)
# subscribe to state and targer point topics
rospy.Subscriber("state", Odometry, get_pose) # get usv position (add 'gps' position latter)
rospy.Subscriber("move_usv/goal", Odometry, get_target) # get target position
while not rospy.is_shutdown():
try:
pub_motor.publish(thruster_ctrl_msg())
pub_rudder.publish(rudder_ctrl_msg())
pub_result.publish(verify_result())
rate.sleep()
except rospy.ROSInterruptException:
rospy.logerr("ROS Interrupt Exception! Just ignore the exception!")
except rospy.ROSTimeMovedBackwardsException:
rospy.logerr("ROS Time Backwards! Just ignore the exception!")
示例8: navigation
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def navigation():
pub = rospy.Publisher('usv_position_setpoint', Odometry, queue_size=10) # only create a rostopic, navigation system TODO
rospy.init_node('navigation_publisher')
rate = rospy.Rate(60) # 10h
x = -20.0
y = -20.0
msg = Odometry()
# msg.header = Header()
msg.header.stamp = rospy.Time.now()
msg.header.frame_id = "navigation"
msg.pose.pose.position = Point(x, y, 0.)
while not rospy.is_shutdown():
pub.publish(msg)
rate.sleep()
示例9: talker_ctrl
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def talker_ctrl():
global rate_value
global result
# publishes to thruster and rudder topics
pub_motor = rospy.Publisher('thruster_command', JointState, queue_size=10)
pub_result = rospy.Publisher('move_usv/result', Float64, queue_size=10)
rospy.init_node('usv_simple_ctrl', anonymous=True)
rate = rospy.Rate(rate_value) # 10h
# subscribe to state and targer point topics
rospy.Subscriber("state", Odometry, get_pose) # get usv position (add 'gps' position latter)
rospy.Subscriber("move_usv/goal", Odometry, get_target) # get target position
while not rospy.is_shutdown():
try:
pub_motor.publish(thruster_ctrl_msg())
pub_result.publish(verify_result())
rate.sleep()
except rospy.ROSInterruptException:
rospy.logerr("ROS Interrupt Exception! Just ignore the exception!")
except rospy.ROSTimeMovedBackwardsException:
rospy.logerr("ROS Time Backwards! Just ignore the exception!")
示例10: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def __init__(self, robot_name, print_debug, email_cred_file='', log_file='', control_rate=100, gripper_attached='default'):
super(WidowXController, self).__init__(robot_name, print_debug, email_cred_file, log_file, control_rate, gripper_attached)
self._redist_rate = rospy.Rate(50)
self._arbotix = ArbotiX('/dev/ttyUSB0')
assert self._arbotix.syncWrite(MAX_TORQUE_L, [[servo_id, 255, 0] for servo_id in SERVO_IDS]) != -1, "failure during servo configuring"
assert self._arbotix.syncWrite(TORQUE_LIMIT, [[servo_id, 255, 0] for servo_id in SERVO_IDS]) != -1, "failure during servo configuring"
self._joint_lock = Lock()
self._angles, self._velocities = {}, {}
rospy.Subscriber("/joint_states", JointState, self._joint_callback)
time.sleep(1)
self._joint_pubs = [rospy.Publisher('/{}/command'.format(name), Float64, queue_size=1) for name in JOINT_NAMES[:-1]]
self._gripper_pub = rospy.Publisher('/gripper_prismatic_joint/command', Float64, queue_size=1)
p.connect(p.DIRECT)
widow_x_urdf = '/'.join(__file__.split('/')[:-1]) + '/widowx/widowx.urdf'
self._armID = p.loadURDF(widow_x_urdf, useFixedBase=True)
p.resetBasePositionAndOrientation(self._armID, [0, 0, 0], p.getQuaternionFromEuler([np.pi, np.pi, np.pi]))
self._n_errors = 0
示例11: main
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--lr", default="r")
args = parser.parse_args()
rospy.init_node("pr2_target_policy")
with open('config/environment/pr2.yaml') as yaml_string:
pr2_env = utils.from_yaml(yaml_string)
tool_link_name = "%s_gripper_tool_frame" % args.lr
pol = policies.Pr2TargetPolicy(pr2_env, tool_link_name, np.zeros(3))
rate = rospy.Rate(30.0)
while not rospy.is_shutdown():
state = pr2_env.get_state()
target_state = pol.get_target_state()
action = (target_state - state) / pr2_env.dt
pr2_env.step(action)
# pr2_env.reset(pol.get_target_state())
rate.sleep()
示例12: attach_springs
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def attach_springs(self):
"""
Switches to joint torque mode and attached joint springs to current
joint positions.
"""
# record initial joint angles
self._start_angles = self._limb.joint_angles()
# set control rate
control_rate = rospy.Rate(self._rate)
# for safety purposes, set the control rate command timeout.
# if the specified number of command cycles are missed, the robot
# will timeout and return to Position Control Mode
self._limb.set_command_timeout((1.0 / self._rate) * self._missed_cmds)
# loop at specified rate commanding new joint torques
while not rospy.is_shutdown():
if not self._rs.state().enabled:
rospy.logerr("Joint torque example failed to meet "
"specified control rate timeout.")
break
self._update_forces()
control_rate.sleep()
示例13: wobble
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def wobble(self):
self.set_neutral()
"""
Performs the wobbling
"""
command_rate = rospy.Rate(1)
control_rate = rospy.Rate(100)
start = rospy.get_time()
while not rospy.is_shutdown() and (rospy.get_time() - start < 10.0):
angle = random.uniform(-2.0, 0.95)
while (not rospy.is_shutdown() and
not (abs(self._head.pan() - angle) <=
intera_interface.HEAD_PAN_ANGLE_TOLERANCE)):
self._head.set_pan(angle, speed=0.3, timeout=0)
control_rate.sleep()
command_rate.sleep()
self._done = True
rospy.signal_shutdown("Example finished.")
示例14: publish_pc2
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def publish_pc2(pc, obj):
"""Publisher of PointCloud data"""
pub = rospy.Publisher("/points_raw", PointCloud2, queue_size=1000000)
rospy.init_node("pc2_publisher")
header = std_msgs.msg.Header()
header.stamp = rospy.Time.now()
header.frame_id = "velodyne"
points = pc2.create_cloud_xyz32(header, pc[:, :3])
pub2 = rospy.Publisher("/points_raw1", PointCloud2, queue_size=1000000)
header = std_msgs.msg.Header()
header.stamp = rospy.Time.now()
header.frame_id = "velodyne"
points2 = pc2.create_cloud_xyz32(header, obj)
r = rospy.Rate(0.1)
while not rospy.is_shutdown():
pub.publish(points)
pub2.publish(points2)
r.sleep()
示例15: execute
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import Rate [as 别名]
def execute(self, inputs, outputs, gvm):
turtle_name = inputs["turtle_name"]
x = inputs["x_pos"]
y = inputs["y_pos"]
phi = inputs["phi"]
service = "/spawn"
rospy.wait_for_service(service)
spawn_turtle_service = rospy.ServiceProxy(service, Spawn)
resp1 = spawn_turtle_service(x, y, phi, turtle_name)
self.logger.info("ROS external module: executed the {} service".format(service))
turtle_pos_subscriber = rospy.Subscriber("/" + turtle_name + "/pose", Pose, check_turtle_pose)
r = rospy.Rate(10)
global pose_received
# wait until the first pose message was received
while not pose_received:
r.sleep()
return 0