-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Big Commit will fix more later sorry
- Loading branch information
Jeffrey
committed
Dec 3, 2019
1 parent
96e4089
commit fbe42fc
Showing
19 changed files
with
867 additions
and
880 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
import socket | ||
import rospy | ||
from sensor_msgs.msg import NavSatFix | ||
|
||
class GPS_Parser(object): | ||
|
||
def __init__(self): | ||
rospy.init_node('gps_parser') | ||
|
||
self.fix_pub = rospy.Publisher('fix', NavSatFix, queue_size = 10) | ||
|
||
self.UDP_IP = "192.168.1.201"#"192.168.3.100" | ||
self.UDP_PORT = 8308#8308 | ||
|
||
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
self.sock.bind(('', self.UDP_PORT)) | ||
#self.sock.setblocking(0) | ||
rospy.loginfo("Connected") | ||
rospy.sleep(1) | ||
|
||
while not rospy.is_shutdown(): | ||
self.get_and_pub_packet() | ||
|
||
def get_and_pub_packet(self): | ||
data, addr = self.sock.recvfrom(512) | ||
line = data[206:278] | ||
|
||
my_fix = NavSatFix() | ||
my_fix.header.stamp = rospy.Time.now() | ||
|
||
latitude_degrees = float(line[16:18]) | ||
latitude_minutes = float(line[18:25]) | ||
latitude = self.decimal_degrees(degs=latitude_degrees, mins=latitude_minutes) | ||
if (line[26] == 'S'): | ||
latitude = -1 * latitude | ||
|
||
longitude_degrees = float(line[28:31]) | ||
longitude_minutes = float(line[31:38]) | ||
longitude = self.decimal_degrees(degs=longitude_degrees, mins=longitude_minutes) | ||
if(line[39] == 'W'): | ||
longitude = -1 * longitude | ||
|
||
my_fix.latitude = latitude | ||
my_fix.longitude = longitude | ||
my_fix.altitude = 0.0 | ||
|
||
rospy.loginfo("Latitude: " + str(my_fix.latitude) + " Longitude: " + str(my_fix.longitude)) | ||
|
||
|
||
|
||
self.fix_pub.publish(my_fix) | ||
|
||
def decimal_degrees(self, degs=0, mins=0, secs=0): | ||
return degs + (mins/60.0) + (secs/3600.0) | ||
|
||
if __name__ == "__main__": | ||
GPS_Parser() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#!/usr/bin/env python | ||
|
||
# import gps | ||
# import speed | ||
import socketio | ||
import time | ||
import rospy | ||
import json | ||
# import camera | ||
# import destination | ||
from std_msgs.msg import Int8, String, Bool | ||
from geometry_msgs.msg import PoseStamped | ||
from navigation_msgs.msg import GoalWaypoint, EmergencyStop, VehicleState | ||
from speech_recognition_location import startRecognize,stopRecognize | ||
isConnected = False | ||
|
||
id = '1bcadd2fea88' | ||
|
||
sio = socketio.Client() | ||
|
||
|
||
|
||
@sio.event(namespace='/cart') | ||
def connect(): | ||
print('id: ', sio.sid) | ||
print('connection established') | ||
send('connect', '23423') | ||
|
||
|
||
|
||
isConnected = True | ||
# while isConnected: | ||
# send('video', camera.getVideo()) | ||
# time.sleep(.1) | ||
|
||
|
||
def send(msg, data): | ||
sio.emit(msg, data, namespace='/cart') | ||
|
||
@sio.on('transit_await',namespace='/cart') | ||
def onTransitAwait(data): | ||
location_speech_pub.publish(True) | ||
#startRecognize(sendAudio) | ||
|
||
def sendAudio(msg): | ||
json = { | ||
"msg": msg, | ||
"id":id | ||
} | ||
send('audio',JSON.dumps(json)) | ||
|
||
#audio call pullover | ||
def sendPullOver(): | ||
send('pull_over',id) | ||
|
||
#pose tracking send when unsafe | ||
def sendUnsafe(): | ||
send('passenger_unsafe',id) | ||
|
||
|
||
def sendPassengerExit(): | ||
send('passenger_exit',id) | ||
|
||
#pose tracking send when ready, AI start driving | ||
def sendReady(): | ||
send('passenger_ready',id) | ||
|
||
@sio.on('pull_over',namespace='/cart') | ||
def onPullOver(): | ||
print("help this needs changed") | ||
#do stuff for the AI | ||
|
||
@sio.on('resume_driving',namespace='/cart') | ||
def onResume(): | ||
print("help this needs changed") | ||
#do stuff for the AI | ||
|
||
#send index + lat/lng + string | ||
@sio.on('destination', namespace='/cart') | ||
def onDestination(data): | ||
#Get JSON data | ||
location_speech_pub.publish(False) | ||
#stopRecognize() | ||
## {latitude:123, longtidue:435} | ||
raw_waypoint = data | ||
|
||
#Prepare goal waypoint message | ||
requested_waypoint = GoalWaypoint() | ||
requested_waypoint.start = -1 | ||
requested_waypoint.goal = raw_waypoint | ||
|
||
#Send requested waypoint to planner | ||
req_pub.publish(requested_waypoint) | ||
|
||
|
||
@sio.on('stop',namespace='/cart') | ||
def onStop(data): | ||
stop_cart = EmergencyStop() | ||
stop_cart.emergency_stop = True | ||
stop_pub.publish(stop_cart) | ||
|
||
@sio.event(namespace='/cart') | ||
def disconnect(): | ||
#camera.cleanUp() | ||
isConnected = False | ||
print('disconnected from server') | ||
|
||
def sendPositionIndex(data): | ||
send("position", data.data) | ||
|
||
def arrivedDestination(data): | ||
send('arrived','','/cart') | ||
|
||
#Handles destination arrival as well as various other vehicle state changes | ||
def status_update(data): | ||
if data.is_navigating == False: | ||
if data.reached_destination == True: | ||
send("arrived", '/cart') | ||
|
||
def pulloverCallback(data): | ||
if data: | ||
sendPullOver() | ||
else: | ||
pass | ||
#sendReady() #is this how it should work? | ||
|
||
if __name__ == "__main__": | ||
rospy.init_node('network_node') | ||
stop_pub = rospy.Publisher('/emergency_stop', EmergencyStop, queue_size=10) | ||
req_pub = rospy.Publisher('/path_request', GoalWaypoint, queue_size=10) | ||
location_speech_pub = rospy.Publisher('/location_speech', Bool, queue_size=10) | ||
#pub = rospy.Publisher('network_node_pub', String, queue_size=10) | ||
rospy.Subscriber('/current_position', Int8, sendPositionIndex) | ||
rospy.Subscriber('/vehicle_state', VehicleState, status_update) | ||
rospy.Subscriber('/pullover', Bool, pulloverCallback) | ||
rospy.Subscriber('/speech_text', String, sendAudio) | ||
rate = rospy.Rate(10) # 10hz | ||
|
||
#rospy.spin() | ||
rospy.loginfo("Attempting connection with socketio server") | ||
sio.connect('http://35.238.125.238:8020', namespaces=['/cart']) | ||
while not rospy.is_shutdown(): | ||
rate.sleep() | ||
|
||
|
Oops, something went wrong.