Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,14 @@ TOOD coming sooner or later
### Wiring-Diagram

![Wiring diagram](https://github.com/penguinmenac3/alice-hardware/blob/master/Wiring%20Alice.png?raw=true)

## Android GPS and Compass
You can use an Android smartphone as GPS and compass.

Download this app: <https://play.google.com/store/apps/details?id=de.lorenz_fenster.sensorstreamgps> / <https://sourceforge.net/projects/smartphone-imu/>

Enter your robots IP, set the stream type to UDP, select the GPS and Orientation sensor and enable "Include User-Checked Sensor Data in Stream".

Mount the smartphone on the robot upwards with the back side facing in driving direction.

Run the `android_gps_proxy.py` script on your robot or start with the `launch_with_gps.sh` shell script. The script will forward the UDP packets from the app to the `main.py` script.
80 changes: 80 additions & 0 deletions android_gps_proxy.py
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"))

Copy link
Copy Markdown
Member

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 tags[0] == "gps":
    # lat, lon, alt, angle_to_north, ?, accuracy, ?
    self._update_global_position(float(tags[1]), float(tags[2]), float(tags[4]), float(tags[6]))

If the app does not support accuracy, fake it. ;)

Also did you test it with the robotics-introduction implementation?

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Member

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? :(

Copy link
Copy Markdown
Author

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.


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()
6 changes: 6 additions & 0 deletions launch_with_gps.sh
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