Last active
March 17, 2016 02:50
-
-
Save adnan2911/89e393bc8670cea6ac93 to your computer and use it in GitHub Desktop.
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
#code for Reciever | |
import socket | |
import atexit | |
import time | |
import pigpio | |
pi = pigpio.pi() # Connect to local Pi | |
pi.set_mode(14, pigpio.OUTPUT) | |
pi.set_servo_pulsewidth(15, 0) | |
pi.set_mode(15, pigpio.OUTPUT) | |
pi.set_servo_pulsewidth(18, 1500) | |
pi.set_mode(17, pigpio.OUTPUT) | |
pi.set_servo_pulsewidth(17, 1500) | |
pi.set_mode(18, pigpio.OUTPUT) | |
pi.set_servo_pulsewidth(18, 1500) | |
TCP_IP = "173.75.180.60" | |
TCP_PORT = 50050 | |
BUFFER_SIZE = 50 | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
s.connect((TCP_IP, TCP_PORT)) | |
while 1: | |
data = s.recv(BUFFER_SIZE) | |
data = data.split(',') | |
print data | |
if len(data) == 7: | |
if len(data[5]) == 6 and len(data[6])== 6 and len(data[3])== 6 and len(data[4])== 6: | |
throttle_data = int(data[5][:-2]) | |
yaw_data = int(data[6][:-2]) | |
roll_data = int(data[3][:-2]) | |
pitch_data = int(data[4][:-2]) | |
pi.set_servo_pulsewidth(14, throttle_data) | |
pi.set_servo_pulsewidth(15, roll_data) | |
pi.set_servo_pulsewidth(17, pitch_data) | |
pi.set_servo_pulsewidth(18, yaw_data) | |
else: | |
print "Data lenghth not correct" | |
def exit_handler(): | |
s.shutdown() | |
s.close() | |
pi.set_servo_pulsewidth(15, 0) | |
pi.set_servo_pulsewidth(18, 0) | |
pi.stop() | |
atexit.register(exit_handler) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment