11 from sbp.client.drivers.network_drivers
import TCPDriver
12 from sbp.client
import Handler, Framer
13 from sbp.settings
import SBP_MSG_SETTINGS_READ_RESP, MsgSettingsWrite, MsgSettingsReadReq
14 from sbp.imu
import SBP_MSG_IMU_RAW
15 from sbp.mag
import SBP_MSG_MAG_RAW
16 from sbp.navigation
import SBP_MSG_BASELINE_HEADING_DEP_A, SBP_MSG_POS_LLH, SBP_MSG_BASELINE_NED
17 from datetime
import datetime
18 from nav_msgs.msg
import Odometry
19 from sensor_msgs.msg
import Imu, MagneticField, NavSatFix
20 from std_msgs.msg
import String, Int32, Bool
21 from geometry_msgs.msg
import TwistStamped
26 rospy.loginfo(
"[RR_SWIFTNAV_PIKSI] Initializing")
46 self.
pub_imu = rospy.Publisher(
'/swift_gps/imu/raw', Imu, queue_size=10)
47 self.
pub_mag = rospy.Publisher(
'/swift_gps/mag/raw', MagneticField, queue_size=10)
48 self.
pub_llh = rospy.Publisher(
'/swift_gps/llh/position', NavSatFix, queue_size=3)
49 self.
pub_llh_n_sats = rospy.Publisher(
'/swift_gps/llh/n_sats', Int32, queue_size=3)
50 self.
pub_llh_fix_mode = rospy.Publisher(
'/swift_gps/llh/fix_mode', Int32, queue_size=3)
51 self.
pub_ecef_odom = rospy.Publisher(
'/swift_gps/baseline/ecef/position', Odometry, queue_size=3)
58 rospy.loginfo(
"[RR_SWIFTNAV_PIKSI] Loading ROS Parameters")
60 path_piksi_ip_address = rospy.search_param(
'piksi_ip_address')
62 rospy.loginfo(
"[RR_SWIFTNAV_PIKSI] Piksi IP address: %s", self.
piksi_ip_address)
64 path_piksi_port = rospy.search_param(
'piksi_port')
65 self.
piksi_port = rospy.get_param(path_piksi_port,
'55555')
66 rospy.loginfo(
"[RR_SWIFTNAV_PIKSI] Piksi Port: %s", self.
piksi_port)
68 path_base_station_ip_address = rospy.search_param(
'base_station_ip_address')
72 path_base_station_port = rospy.search_param(
'base_station_port')
74 rospy.loginfo(
"[RR_SWIFTNAV_PIKSI] Base Station Port: %s", self.
base_station_port)
76 path_computer_ip_address = rospy.search_param(
'computer_ip_address')
82 with Handler(Framer(driver.read, driver.write))
as source:
95 if cmd_vel.twist.linear.x > 0:
97 if cmd_vel.twist.linear.x < 0:
102 if (msg.data ==
True):
106 rospy.loginfo(str_cmd)
107 self.
ncat_process = subprocess.Popen(str_cmd, shell=
True)
109 rospy.loginfo(
"[RR_SWIFNAV_PIKSI] GPS comms enabled, ncat started")
111 rospy.logwarn(
"[RR_SWIFTNAV_PIKSI] GPS comms already enabled, ignoring request")
112 if (msg.data ==
False):
114 subprocess.call([
"kill",
"-9",
"%d" % self.ncat_process.pid])
115 self.ncat_process.wait()
116 os.system(
'killall ncat')
117 rospy.loginfo(
"[RR_SWIFT_NAV_PIKSI] GPS comms disables, ncat stopped")
121 rospy.logwarn(
"[RR_SWIFTNAV_PIKSI] RTK GPS already disabled, ignoring request")
128 x_pos = float(msg.e)/1000
129 y_pos = float(msg.n)/1000
130 z_pos = float(msg.d)/1000
131 h_accuracy = float(msg.h_accuracy)/1000
132 v_accuracy = float(msg.v_accuracy)/1000
134 if (x_pos,y_pos) == (0.0,0.0):
135 rospy.logwarn_throttle(10,
"SwiftNav GPS baseline reported x=0 y=0. Message not published")
139 ecef_odom_msg = Odometry()
140 ecef_odom_msg.child_frame_id =
'gps_link' 141 ecef_odom_msg.header.stamp = rospy.Time.now()
142 ecef_odom_msg.header.frame_id =
'map' 143 ecef_odom_msg.pose.pose.position.x = x_pos
144 ecef_odom_msg.pose.pose.position.y = y_pos
145 ecef_odom_msg.pose.pose.position.z = 0
154 distance_travelled = np.sqrt(np.power(delta_x,2) + np.power(delta_y,2))
157 if (distance_travelled==0):
161 delta_x_hat = delta_x / distance_travelled
162 delta_y_hat = delta_y / distance_travelled
164 if (distance_travelled>0.04):
165 angle = np.arctan2(delta_y_hat, delta_x_hat)
166 ecef_odom_msg.pose.pose.orientation.z = 1*np.sin(angle/2)
167 ecef_odom_msg.pose.pose.orientation.w = np.cos(angle/2)
174 cov_x = cov_y = h_accuracy
177 if (0<=distance_travelled
and distance_travelled<=0.04):
178 theta_accuracy = 1000
179 elif(0.04<distance_travelled
and distance_travelled<=0.01):
180 theta_accuracy = 0.348
181 elif(0.01<distance_travelled
and distance_travelled<=0.4):
182 theta_accuracy = 0.174
183 elif(0.4<distance_travelled):
184 theta_accuracy = 0.14
187 rospy.logerr_throttle(5,
"distance travelled was negative")
189 cov_theta = theta_accuracy
190 ecef_odom_msg.pose.covariance = [cov_x, 0, 0, 0, 0, 0,
191 0, cov_y, 0, 0, 0, 0,
195 0, 0, 0, 0, 0, cov_theta]
197 self.pub_ecef_odom.publish(ecef_odom_msg)
200 mag_msg = MagneticField()
201 mag_msg.header.stamp = rospy.Time.now()
202 mag_msg.header.frame_id =
'gps_link' 205 mag_msg.magnetic_field.x = msg.mag_x*magscale
206 mag_msg.magnetic_field.y = msg.mag_y*magscale
207 mag_msg.magnetic_field.z = msg.mag_z*magscale
208 mag_msg.magnetic_field_covariance = [0,0,0,
212 self.pub_mag.publish(mag_msg)
216 imu_msg.header.stamp = rospy.Time.now()
217 imu_msg.header.frame_id =
'gps_link' 220 gscale=3.14159/180/65.6
221 imu_msg.angular_velocity.x = msg.gyr_x*gscale
222 imu_msg.angular_velocity.y = msg.gyr_y*gscale
223 imu_msg.angular_velocity.z = msg.gyr_z*gscale
224 imu_msg.linear_acceleration.x = msg.acc_x*ascale
225 imu_msg.linear_acceleration.y = msg.acc_y*ascale
226 imu_msg.linear_acceleration.z = msg.acc_z*ascale
227 imu_msg.orientation_covariance = [0,0,0,
230 imu_msg.angular_velocity_covariance= [0,0,0,
233 imu_msg.linear_acceleration_covariance= [0.01,0,0,
237 self.pub_imu.publish(imu_msg)
241 llh_msg = NavSatFix()
242 llh_msg.latitude = msg.lat
243 llh_msg.longitude = msg.lon
244 llh_msg.altitude = msg.height
245 llh_msg.position_covariance_type = 2
246 llh_msg.position_covariance = [9,0,0,
250 self.pub_llh.publish(llh_msg)
251 self.pub_llh_n_sats.publish(Int32(msg.n_sats))
252 self.pub_llh_fix_mode.publish(Int32(msg.flags))
254 if __name__ ==
"__main__":
255 rospy.init_node(
'rr_swiftnav_gps_node')
def publish_llh_msg(self, msg, metadata)
def enable_comms_cb(self, msg)
def publish_mag_msg(self, msg, metadata)
def publish_imu_msg(self, msg, metadata)
def publish_baseline_msg(self, msg, metadata)
def cmd_vel_cb(self, cmd_vel)