Created
November 27, 2018 13:50
-
-
Save StefanIGit/0dd3e022f37a180e672c3ce7dd8ac50d 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
''' | |
l293d speed ramp test | |
''' | |
import time | |
import socket | |
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) | |
server.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) | |
# Set a timeout so the socket does not block | |
# indefinitely when trying to receive data. | |
server.settimeout(0.2) | |
server.bind(("", 44444)) | |
message = b"" | |
print time.time() | |
lOfSpeed =[10, 60,100,-100,-80, -60, 0,60] | |
def motorA(speed): | |
print speed | |
server.sendto(str(speed), ('localhost', 37020)) | |
def motorB(speed): | |
print speed | |
server.sendto(str(speed) , ('localhost', 37020)) | |
currentSpeedA = 0 | |
currentSpeedB = 0 | |
for newSpeed in lOfSpeed: | |
print str(newSpeed) | |
#if newSpeed >= 0 and currentSpeedA >= 0: | |
if abs(currentSpeedA - newSpeed) > 5: | |
for step in range(0, abs(currentSpeedA - newSpeed), 5): | |
if newSpeed > currentSpeedA: | |
motorA(currentSpeedA + step) | |
else: | |
motorA(currentSpeedA - step) | |
time.sleep(0.5) | |
currentSpeedA = newSpeed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment