-
Notifications
You must be signed in to change notification settings - Fork 1
Android GPS Proxy script #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
antonxy
wants to merge
1
commit into
SimpleRobots:master
Choose a base branch
from
antonxy:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,80 @@ | ||
| #!/usr/bin/env python3 | ||
| import socket | ||
| from math import sqrt, pi | ||
| import time | ||
|
|
||
| # Receives GPS and Compass from the Sensorstream app via UDP and forwards it to alice via TCP | ||
| # Download app from here https://play.google.com/store/apps/details?id=de.lorenz_fenster.sensorstreamgps | ||
|
|
||
| last_gps = [-1.0, -1.0, -1.0] | ||
| last_angle = -1 | ||
|
|
||
| def send(sock): | ||
| global last_gps, last_angle | ||
| sock.send("{} {} {} {} {} {}\n".format(last_gps[0], last_gps[1], last_gps[2], last_angle, -1, -1).encode("utf-8")) | ||
|
|
||
| def main(): | ||
| global last_gps, last_angle | ||
| UDP_IP = "0.0.0.0" | ||
| UDP_PORT = 5555 | ||
|
|
||
| sock = socket.socket(socket.AF_INET, # Internet | ||
| socket.SOCK_DGRAM) # UDP | ||
| sock.bind((UDP_IP, UDP_PORT)) | ||
|
|
||
| OUTPUT_HOST = "localhost" | ||
| OUTPUT_PORT = 2323 | ||
|
|
||
|
|
||
| while True: | ||
| try: | ||
| outs = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| outs.connect((OUTPUT_HOST, OUTPUT_PORT)) | ||
|
|
||
| while True: | ||
| data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes | ||
| data_str = data.decode("utf-8") | ||
| #print(data_str) | ||
| splitted = data_str.split(',') | ||
| the_time = splitted[0] | ||
| splitted_no_time = splitted[1:] | ||
| #print('------') | ||
| #print(splitted_no_time) | ||
| i = 0 | ||
| while i < len(splitted_no_time): | ||
| num = int(splitted_no_time[i]) | ||
| if num == 1: | ||
| data = list(map(float, splitted_no_time[i+1:i+4])) | ||
| print("GPS:", data) | ||
| last_gps = data | ||
| send(outs) | ||
| elif num == 8: | ||
| i += 2 # Number 8 is has only one data field | ||
| continue | ||
| elif num == 81: | ||
| data = list(map(float, splitted_no_time[i+1:i+4])) | ||
| angle_to_north = data[0] | ||
| if angle_to_north > 180.0: | ||
| angle_to_north -= 360.0 | ||
| angle_to_north *= pi / 180.0 | ||
| print("Angle to north:", angle_to_north) | ||
| last_angle = angle_to_north | ||
| send(outs) | ||
| ''' | ||
| elif num == 84: | ||
| # https://developer.android.com/guide/topics/sensors/sensors_motion.html#sensors-motion-rotate | ||
| data = list(map(float, splitted_no_time[i+1:i+4])) | ||
| xyz = data | ||
| w = sqrt(1.0 - xyz[0] ** 2 - xyz[1] ** 2 - xyz[2] ** 2) # Apparently wrong | ||
| quat = xyz + [w] | ||
| print(quat) | ||
| ''' | ||
| i += 4 | ||
| except Exception as e: | ||
| print("Error \"{}\", will try to reconnect".format(e)) | ||
|
|
||
| outs.close() | ||
| time.sleep(2.0) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or 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,6 @@ | ||
| #!/bin/bash | ||
|
|
||
| cd /home/pi/git/alice-hardware | ||
|
|
||
| screen -dmS alice-hardware python main.py | ||
| screen -dmS alice-hardware-gps python android_gps_proxy.py |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you missed the accuracy.
see https://github.com/penguinmenac3/robotics-introduction/blob/master/robots/alice.py
If the app does not support accuracy, fake it. ;)
Also did you test it with the robotics-introduction implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put in -1 to indicate that accuracy is not known. I think that's better than putting in some arbitrary value.
I tested it with robotics-introduction, the values are being received.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So no accuracy support by that app? :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think so, every sensor has three values, and for GPS that is lat, lon and alt. But I guess for the introduction it's ok, it gets interesting for SLAM but for that we will have to use the big robot anyway.