robot_info.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 import roslib
00004 roslib.load_manifest('teo_apps')
00005 import os
00006 import sys
00007 import numpy as np
00008 import rospy
00009 import rosbag
00010 import tf
00011 import pprint
00012 import math
00013 import subprocess, yaml
00014 
00015 from geometry_msgs.msg import Twist
00016 from iri_segway_rmp_msgs.msg import SegwayRMP400Status
00017 from nav_msgs.msg import Odometry
00018 from sensor_msgs.msg import Imu
00019 from sensor_msgs.msg import NavSatFix
00020 from iri_common_drivers_msgs.msg import lifebatt_status
00021 
00022 from tf.transformations import euler_from_quaternion
00023 
00024 # Terminal colors for Ubuntu/Linux
00025 SB_='\033[1m' #style bold
00026 CW_='\033[1;37m' #White
00027 CLG_='\033[37m' #Light Gray
00028 CG_='\033[1;30m' #Gray    
00029 CN_='\033[30m' #Black   
00030 CR_='\033[31m' #Red        
00031 CLR_='\033[1;31m' #Light Red  
00032 CV_='\033[32m' #Green      
00033 CLV_='\033[1;32m' #Light Green
00034 CM_='\033[33m' #Brown      
00035 CY_='\033[1;33m' #Yellow     
00036 CB_='\033[34m' #Blue       
00037 CLB_='\033[1;34m' #Light Blue 
00038 CP_='\033[35m' #Purple     
00039 CK_='\033[1;35m' #Pink       
00040 CC_='\033[36m' #Cyan      
00041 CLC_='\033[1;36m' #Light Cyan
00042 _EC='\033[0m' #end color
00043 
00044 u_vel_x           = 0
00045 u_vel_yaw         = 0
00046 seg_vel_x         = 0
00047 seg_x             = 0
00048 imu_roll          = 0        
00049 imu_pitch         = 0        
00050 imu_yaw           = 0      
00051 imu_vel_x         = 0        
00052 imu_vel_y         = 0        
00053 imu_vel_z         = 0        
00054 imu_acc_x         = 0        
00055 imu_acc_y         = 0        
00056 imu_acc_z         = 0        
00057 odom_x            = 0
00058 odom_y            = 0
00059 odom_o            = 0
00060 gps_lat           = 0
00061 gps_lon           = 0
00062 gps_alt           = 0
00063 seg_ui_bat        = [0,0]
00064 powerbase_battery = [0,0]
00065 bat_vol           = 0
00066 bat_cur           = 0
00067 bat_cap           = 0
00068 bat_time          = 0
00069 
00070 def cmd_vel_cb(data):
00071   global u_vel_x,u_vel_yaw
00072   u_vel_x   = data.linear.x
00073   u_vel_yaw = data.angular.z
00074     
00075 def seg_sta_cb(data):
00076   global seg_vel_x,seg_x,seg_ui_bat,powerbase_battery
00077   seg_vel_x = (data.rmp200[0].left_wheel_velocity  + data.rmp200[0].right_wheel_velocity  + \
00078                data.rmp200[1].left_wheel_velocity  + data.rmp200[1].right_wheel_velocity) /4
00079   seg_x     = (data.rmp200[0].forward_displacement + data.rmp200[1].forward_displacement) /2
00080   seg_ui_bat        = [data.rmp200[0].ui_battery, data.rmp200[1].ui_battery]
00081   powerbase_battery = [data.rmp200[0].powerbase_battery, data.rmp200[1].powerbase_battery]
00082 
00083 def imu_cb(data):
00084   global imu_roll,imu_pitch,imu_yaw,imu_vel_x,imu_vel_y,imu_vel_z,imu_acc_x,imu_acc_y,imu_acc_z
00085   q = [data.orientation.x, data.orientation.y, data.orientation.z, data.orientation.w]
00086   imu_roll, imu_pitch, imu_yaw = euler_from_quaternion(q)
00087   if imu_roll <0:
00088     imu_roll = math.pi+imu_roll # trick
00089   else:
00090     imu_roll = -math.pi+imu_roll
00091   imu_roll, imu_pitch, imu_yaw = imu_roll*180/math.pi, imu_pitch*180/math.pi, imu_yaw*180/math.pi
00092   imu_vel_x = data.angular_velocity.x
00093   imu_vel_y = data.angular_velocity.y
00094   imu_vel_z = data.angular_velocity.z
00095   imu_acc_x = data.linear_acceleration.x
00096   imu_acc_y = data.linear_acceleration.y
00097   imu_acc_z = data.linear_acceleration.z
00098 
00099 def odom_cb(data):
00100   global odom_x,odom_y,odom_o,odom_roll,odom_pitch,odom_yaw
00101   odom_x = data.pose.pose.position.x
00102   odom_y = data.pose.pose.position.y
00103   q = [data.pose.pose.orientation.x, data.pose.pose.orientation.y, data.pose.pose.orientation.z, data.pose.pose.orientation.w]
00104   odom_roll, odom_pitch, odom_yaw = euler_from_quaternion(q)
00105 
00106 def gps_cb(data):
00107   global gps_lat,gps_lon,gps_alt
00108   gps_lat = data.latitude
00109   gps_lon = data.longitude
00110   gps_alt = data.altitude
00111 
00112 def bat_cb(data):
00113   global bat_vol,bat_cur,bat_cap,bat_time
00114   bat_vol  = data.voltage
00115   bat_cur  = data.output_current
00116   bat_cap  = data.remaining_capacity
00117   bat_time = data.time_to_discharged
00118     
00119 if __name__ == '__main__':
00120 
00121   print CY_ +"- TEO ROBOT info -"+"\n"+_EC
00122 
00123   rospy.init_node('robot_info')
00124 
00125   rospy.Subscriber("cmd_vel", Twist, cmd_vel_cb)
00126   rospy.Subscriber("segway_status", SegwayRMP400Status, seg_sta_cb)
00127   rospy.Subscriber("imu", Imu, imu_cb)
00128   rospy.Subscriber("odom", Odometry, odom_cb)
00129   rospy.Subscriber("gps", NavSatFix, gps_cb)
00130   rospy.Subscriber("battery", lifebatt_status, bat_cb)
00131 
00132   r = rospy.Rate(0.5) # [Hz]
00133   while not rospy.is_shutdown():
00134     print CY_ +"-- TEO ROBOT STATUS --------------------"+"\n\n"\
00135          +CLB_+"Velocitat: "+"U=","%.3f"%u_vel_x,",","%.3f"%u_vel_yaw,"\t\t[m/s,rad/s]\n"\
00136               +"           "+"S=","%.3f"%seg_vel_x,"\t\t\t[m/s]\n"\
00137               +"           "+"I=","%.3f"%imu_vel_x,",","%.3f"%imu_vel_y,",","%.3f"%imu_vel_z,"\t[rad/s]\n"\
00138          +CLC_+"Posicio:   "+"S=","%.3f"%seg_x,"\t\t\t[m]\n"\
00139               +"           "+"I=","%.3f"%imu_roll,",","%.3f"%imu_pitch,",","%.3f"%imu_yaw,"\t[⁰]\n"\
00140               +"           "+"O=","%.3f"%odom_x,",","%.3f"%odom_y,",","%.3f"%odom_o,"\t[m,m,⁰]\n"\
00141               +"Acceler.:  "+"I=","%.3f"%imu_acc_x,",","%.3f"%imu_acc_y,",","%.3f"%imu_acc_z,"\t[m/s²]\n"\
00142           +CV_+"GPS:       "+"Lat=",gps_lat,"\tLon=",gps_lon,"\tAlt=",gps_alt,"\n"\
00143          +CLR_+"Bateries:  "+"UI=","%.3f"%seg_ui_bat[0],",","%.3f"%seg_ui_bat[1],"\t\t[V]\n"\
00144               +"           "+"PB=","%.3f"%powerbase_battery[0],",","%.3f"%powerbase_battery[1],"\t\t[V]\n"\
00145               +"           "+"LifeBat:","%.3f"%bat_vol, "\t\t[V]\n"\
00146               +"           "+"        ","%.3f"%bat_cur, "\t\t[A]\n"\
00147               +"           "+"        ","%.3f"%bat_cap, "\t\t[Ah]\n"\
00148               +"           "+"        ","%.3f"%bat_time,"\t\t[s]\n"+_EC
00149     r.sleep()    
00150 
00151 
00152 
00153 


teo_apps
Author(s): Marti
autogenerated on Fri Dec 6 2013 22:19:45