-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ff27c3
commit 4b05c03
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This file is executed on every boot (including wake-boot from deepsleep) | ||
import esp | ||
esp.osdebug(None) | ||
|
||
import wifi | ||
import controller |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import socket | ||
from time import sleep | ||
|
||
from machine import ADC, Pin | ||
|
||
SPEED = ADC(Pin(1, Pin.IN), atten=ADC.ATTN_11DB) | ||
STEER = ADC(Pin(2, Pin.IN), atten=ADC.ATTN_11DB) | ||
|
||
debug = True | ||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | ||
server_addr = ("192.168.4.1", 7913) | ||
|
||
def getProcent(pot): | ||
return round(pot.read_uv()/1000/3027*100) | ||
|
||
def getCmd(speed, steer): | ||
if steer <= 50: | ||
lspeed = speed-abs(50-steer) | ||
rspeed = speed | ||
else: | ||
lspeed = speed | ||
rspeed = speed-abs(50-steer) | ||
return f"{lspeed} {rspeed}" | ||
|
||
while True: | ||
msg = getCmd(getProcent(SPEED), getProcent(STEER)) | ||
#print(msg) | ||
sock.sendto(msg, server_addr) | ||
sleep(0.05) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sys | ||
import time | ||
import network | ||
|
||
wifi = network.WLAN(network.STA_IF) | ||
|
||
if not wifi.isconnected(): | ||
wifi.active(True) | ||
try: | ||
wifi.config(dhcp_hostname="RC Controller") | ||
wifi.connect("RoverNumber1", "qwerty123456") | ||
except Exception as err: | ||
wifi.active(False) | ||
print("Error:", err) | ||
sys.exit() | ||
print("Connecting", end="") | ||
n = 0 | ||
while not wifi.isconnected(): | ||
print(".", end="") | ||
time.sleep(1) | ||
n += 1 | ||
if n == 60: | ||
break | ||
if n == 60: | ||
wifi.active(False) | ||
print("\nGiving up! Not connected!") | ||
else: | ||
print("\nNow connected with IP: ", wifi.ifconfig()[0]) | ||
|