Skip to content

Commit

Permalink
Added initial native iOS analog joysticks (Swift), added basic serial…
Browse files Browse the repository at this point in the history
… comm in python

* Basic analog joysticks in iOS using a Swift library
* Added basic serial communication in Python 3
* Updated to MQTT scripts for Python 3
* Updated esp8266 MQTT code
  • Loading branch information
DocVaughan committed May 27, 2016
1 parent a34cb23 commit ed76336
Show file tree
Hide file tree
Showing 38 changed files with 2,729 additions and 3 deletions.
7 changes: 4 additions & 3 deletions MQTT/MQTT_connectPub.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def on_connect(client, userdata, flags, rc):
counter += 1

timestamp = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
send_time = str(timestamp) + ' Count: ' + str(counter)

client.publish('CRAWLAB/from_python', send_time, qos = 0)
# send_time = str(timestamp) + ' Count: ' + str(counter)
send_time = str(counter % 8)
print(send_time)
client.publish('CRAWLAB/to_cable', send_time, qos = 0)
time.sleep(0.1)
Binary file added Misc Python Tools and Helpers/example_freq.pdf
Binary file not shown.
76 changes: 76 additions & 0 deletions Serial Communication/basic_serial_communication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#! /usr/bin/env python

###############################################################################
# basic_serial_communication.py
#
# script to achieve basic send/receive communication
#
# NOTE: Any plotting is set up for output, not viewing on screen.
# So, it will likely be ugly on screen. The saved PDFs should look
# better.
#
# Created: 05/27/16
# - Joshua Vaughan
# - [email protected]
# - http://www.ucs.louisiana.edu/~jev9637
#
# Modified:
# *
#
###############################################################################

import numpy as np
import logging
import serial
import time

logger = logging.getLogger(__name__)

# TODO: Make a nice class-based serial object for easier reuse
# class serial_comm(object):
# ''' Class for sending/receiving serial data'''
# def __init__(self, port):
# self.port = port
# self.ser = serial.Serial(port, 115200)
#
# # Sends throttle and steering angle commands to platform
# def send_string(self, string):
#
# if type(string) is str:
# # Write the data to the serial connection - to the Arudino for CAN bus formatting
# self.ser.write(str(string))
# else:
# logging.debug('The send_string method requires a str type argument.')
#
# def __del__(self):
# self.ser.close()
#

if __name__ == '__main__':
# serial port will have to change based on configuration
PORT = '/dev/tty.usbserial-A6001Ko5'

# define the serial communication parameters, 8 bits, no parity, 1 stop bit
BPS = 115200

ser = serial.Serial(PORT, BPS)

time_start = time.time()

try:
while True:
dt = time.time() - time_start

data = 100 * np.sin(0.5*np.pi * dt)

data_string = '{}\r\n'.format(int(data)).encode('utf-8')

ser.write(data_string)
print(data_string)

time.sleep(0.05)


except (KeyboardInterrupt, SystemExit):
ser.close()

1 change: 1 addition & 0 deletions esp8266/esp8266_MQTT/esp8266_MQTT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Created: 01/28/16
#include <ESP8266WiFi.h>
#include <PubSubClient.h>


// Update these with values suitable for your network.
const char* WIFI_SSID = "Doc_Vaughan";
const char* WIFI_PASSWORD = "rougeourobots";
Expand Down
Loading

0 comments on commit ed76336

Please sign in to comment.