I am getting Time is not intialised error
Error message:
File "/home/angshuman/catkin_ws/src/barc/src/state_estimation_KinBkMdl_sim.py", line 81, in <module>
state_estimation()
File "/home/angshuman/catkin_ws/src/barc/src/state_estimation_KinBkMdl_sim.py", line 56, in state_estimation
rate = rospy.Rate(loop_rate)
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/timer.py", line 59, in __init__
self.last_time = rospy.rostime.get_rostime()
File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/rostime.py", line 209, in get_rostime
raise rospy.exceptions.ROSInitException("time is not initialized. Have you called init_node()?")
rospy.exceptions.ROSInitException: time is not initialized. Have you called init_node()?
My code:
#!/usr/bin/env python
# ---------------------------------------------------------------------------
# Licensing Information: You are free to use or extend these projects for
# education or reserach purposes provided that (1) you retain this notice
# and (2) you provide clear attribution to UC Berkeley, including a link
# to http://barc-project.com
#
# Attibution Information: The barc project ROS code-base was developed
# at UC Berkeley in the Model Predictive Control (MPC) lab by Jon Gonzales
# (jon.gonzales@berkeley.edu). The cloud services integation with ROS was developed
# by Kiet Lam (kiet.lam@berkeley.edu). The web-server app Dator was
# based on an open source project by Bruce Wootton
#
# The original code is being modified by Angshuman Goswami(agoswam@clemson.edu)
# from Clemson University working in Efficient Mobility via Connectivity
# and Control (EMC2) lab
# ---------------------------------------------------------------------------
import rospy
import time
import os
from sensor_msgs.msg import Imu
from barc.msg import ECU, Encoder, Z_KinBkMdl
from numpy import pi, cos, sin, eye, array, zeros, unwrap
from observers import kinematicLuembergerObserver, ekf
from system_models import f_KinBkMdl, h_KinBkMdl
from tf import transformations
from numpy import unwrap
# input variables [default values]
d_f = 0 # steering angle [deg]
acc = 0 # acceleration [m/s]
# ecu command update
def ecu_callback(data):
global acc, d_f
acc = data.motor # input acceleration
d_f = data.servo # input steering angle
# state estimation node
def state_estimation_sim():
# initialize node
rospy.init_node('state_estimation_sim', anonymous=True)
# topic subscriptions / publications
rospy.Subscriber('ecu', ECU, ecu_callback)
state_pub = rospy.Publisher('state_estimate_sim', Z_KinBkMdl, queue_size = 10)
# get vehicle dimension parameters
L_a = 0.125 # distance from CoG to front axel
L_b = 0.125 # distance from CoG to rear axel
vhMdl = (L_a, L_b)
# set node rate
loop_rate = 50
dt = 1.0 / loop_rate
rate = rospy.Rate(loop_rate)
t0 = time.time()
while not rospy.is_shutdown():
# publish state estimate
(x, y, psi, v) = z
# publish information
state_pub.publish( Z_KinBkMdl(x, y, psi, v) )
# collect measurements, inputs, system properties
# collect inputs
u = array([ d_f, acc ])
args = (u,vhMdl,dt)
# apply EKF and get each state estimate
z= f_KinBkMdl
# wait
rate.sleep()
if __name__ == '__main__':
try:
state_estimation_sim()
except rospy.ROSInterruptException:
pass
add a comment