cleanup Code

This commit is contained in:
Lukas Droste
2021-09-05 11:31:09 +02:00
parent c2ac30ac2c
commit 5c98948af5
3 changed files with 21 additions and 37 deletions

View File

@@ -2,7 +2,6 @@
double degreeY = 0;
String rxData = ""; //Empfangen
CheapStepper stepper (8,9,10,11);
void setup() {
@@ -11,7 +10,6 @@ void setup() {
}
void loop() {
stepper.run();
// send data only when you receive data:
if (Serial.available() > 0) {
@@ -37,17 +35,11 @@ void loop() {
}
String moveMotor(double y){
if(y < degreeY){
stepper.newMoveDegrees (true, calculateMove(y)); //true = im Uhrzeigersinn drehen
//motor.step((int)calculateStepps(degreeY - y), BACKWARD, INTERLEAVE); //"interleave" means that it alternates between single and double to get twice the resolution (but of course its half the speed)
//motor.release(); // Strom sparen und Überhitzung des Controllers vorbeugen!
}
else{
stepper.newMoveDegrees (false, calculateMove(y)); //false = gegen Uhrzeigersinn drehen
//motor.step((int)calculateStepps(y - degreeY), FORWARD, INTERLEAVE);
//motor.release();
}
degreeY = y;
return "<move><" + (String)y + ">";

View File

@@ -1,7 +1,7 @@
# Importing Libraries
import serial
import time
import lidar3
import PyLidar3
import asyncio
import websockets
import threading
@@ -37,7 +37,7 @@ async def init():
ws_message_queue.appendleft("can not connect to arduino! " + arduino_port)
arduino_status = False
try:
lidar = lidar3.YdLidarX4(port=lidar_port,chunk_size=lidar_chunk_size) #PyLidar3.your_version_of_lidar(port,chunk_size)
lidar = PyLidar3.YdLidarX4(port=lidar_port,chunk_size=lidar_chunk_size) #PyLidar3.your_version_of_lidar(port,chunk_size)
if(lidar.Connect()):
lidar_status = True
ws_message_queue.appendleft("lidar connected " + lidar_port)
@@ -51,19 +51,16 @@ async def init():
else:
ws_message_queue.appendleft("<connection>false")
def arduino_write_read(x):
arduino.write(bytes(x, 'utf-8'))
def setY(y):
arduino.write(bytes("<set><"+str(y)+">", 'utf-8'))
data1 = arduino.readline()
return filterY(str(data1))
def setY(y):
tmp = arduino_write_read("<set><"+str(y)+">")
def filterY(data):
temp = data[data.find("<"):data.find(">")]
return temp + data[data.find("><"):data.find(">", data.find("><")+2)+1]
def senddata(data,posy):
def sendData(data,posy):
global scan_id
temp ="{\"Id\": \""+scan_id+"\",\"ScanPoints\":["
for x,y in data.items():
@@ -72,14 +69,14 @@ def senddata(data,posy):
# f.write("{\"RAY\":" + str(posy) + ",\"RAX\":" + str(x) + ",\"DistanceMM\":" + str(y) + "},")
l = len(temp)
temp = temp[:l-1] + "]}"
f.write(temp)
#f.write(temp)
r = requests.put(url='http://localhost:35588/scandata', data=temp, headers={'content-type': 'application/json'})
#print(r.status_code)
def startScaner(mode):
global scan_progress, lidar, stop_scan, scan_id
if lidar_status == True:
def startScanner(mode):
global scan_progress, lidar, stop_scan, scan_id, arduino_status
if lidar_status == True and arduino_status == True:
ws_message_queue.appendleft(str(lidar.GetDeviceInfo()))
scan_id = str(uuid.uuid4())
ws_message_queue.appendleft("Scan ID: " + scan_id)
@@ -90,8 +87,7 @@ def startScaner(mode):
for y in range(19):
if(stop_scan == True):
break
print("send data")
senddata(next(gen),y*10)
sendData(next(gen),y*10)
time.sleep(2)
setY(y*10)
time.sleep(2)
@@ -105,7 +101,7 @@ def startScaner(mode):
for y in range(91):
if(stop_scan == True):
break
senddata(next(gen),y*2)
sendData(next(gen),y*2)
time.sleep(1)
setY(y*2)
time.sleep(1)
@@ -119,7 +115,7 @@ def startScaner(mode):
for y in range(361):
if(stop_scan == True):
break
senddata(next(gen),y*0.5)
sendData(next(gen),y*0.5)
time.sleep(1)
setY(y*0.5)
time.sleep(1)
@@ -151,21 +147,21 @@ async def wsaction(command, value):
if command == "start":
if value == "0":
ws_message_queue.appendleft("start scan on low resolution")
x = threading.Thread(target=startScaner, args=(value))
x = threading.Thread(target=startScanner, args=(value))
x.start()
elif value =="1":
ws_message_queue.appendleft("start scan on medium resolution")
x = threading.Thread(target=startScaner, args=(value))
x = threading.Thread(target=startScanner, args=(value))
x.start()
elif value =="2":
ws_message_queue.appendleft("start scan on high resolution")
x = threading.Thread(target=startScaner, args=(value))
x = threading.Thread(target=startScanner, args=(value))
x.start()
else:
ws_message_queue.appendleft("mode error")
elif command == "connect" and arduino and lidar != None:
ws_message_queue.appendleft("try to connect to Adruino and LIDAR")
await init()
# elif command == "connect" and arduino and lidar != None:
# ws_message_queue.appendleft("try to connect to Adruino and LIDAR")
# await init()
elif command == "status":
ws_message_queue.appendleft("progress: " + scan_progress)
elif command == "stop":

View File

@@ -22,7 +22,6 @@
</div>
</ul>
</div>
<!--<button v-on:click="connection_status = !connection_status" >test</button>-->
<button v-on:click="progress = 0, logs = []" >clear logs</button>
</div>
</template>
@@ -71,7 +70,6 @@ export default {
if(message.search("<") != -1){
that.command = message.substr(message.search("<")+1, message.search(">")-1)
that.value = message.substr(message.search(">")+1)
//console.log("command: " + that.command + " / value: " + that.value)
this.action(that.command, that.value)
}
else{
@@ -143,19 +141,17 @@ li {
.progressbar {
background-color: grey;
border-radius: 7px;
/* (height of inner div) / 2 + padding */
padding: 3px;
margin: auto;
}
.progressbar>div {
/* Adjust with JavaScript */
height: 20px;
border-radius: 4px;
}
.button {
background-color: #4CAF50; /* Green */
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
@@ -173,6 +169,6 @@ li {
.button2 {background-color: #00ba9b;}
.button3 {background-color: #008cff}
.button4 {background-color: #f44336;} /* Red */
.button4 {background-color: #f44336;}
</style>