cleanup Code
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
double degreeY = 0;
|
double degreeY = 0;
|
||||||
String rxData = ""; //Empfangen
|
String rxData = ""; //Empfangen
|
||||||
|
|
||||||
CheapStepper stepper (8,9,10,11);
|
CheapStepper stepper (8,9,10,11);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
@@ -11,7 +10,6 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
stepper.run();
|
stepper.run();
|
||||||
// send data only when you receive data:
|
// send data only when you receive data:
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0) {
|
||||||
@@ -37,17 +35,11 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String moveMotor(double y){
|
String moveMotor(double y){
|
||||||
|
|
||||||
|
|
||||||
if(y < degreeY){
|
if(y < degreeY){
|
||||||
stepper.newMoveDegrees (true, calculateMove(y)); //true = im Uhrzeigersinn drehen
|
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{
|
else{
|
||||||
stepper.newMoveDegrees (false, calculateMove(y)); //false = gegen Uhrzeigersinn drehen
|
stepper.newMoveDegrees (false, calculateMove(y)); //false = gegen Uhrzeigersinn drehen
|
||||||
//motor.step((int)calculateStepps(y - degreeY), FORWARD, INTERLEAVE);
|
|
||||||
//motor.release();
|
|
||||||
}
|
}
|
||||||
degreeY = y;
|
degreeY = y;
|
||||||
return "<move><" + (String)y + ">";
|
return "<move><" + (String)y + ">";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# Importing Libraries
|
# Importing Libraries
|
||||||
import serial
|
import serial
|
||||||
import time
|
import time
|
||||||
import lidar3
|
import PyLidar3
|
||||||
import asyncio
|
import asyncio
|
||||||
import websockets
|
import websockets
|
||||||
import threading
|
import threading
|
||||||
@@ -37,7 +37,7 @@ async def init():
|
|||||||
ws_message_queue.appendleft("can not connect to arduino! " + arduino_port)
|
ws_message_queue.appendleft("can not connect to arduino! " + arduino_port)
|
||||||
arduino_status = False
|
arduino_status = False
|
||||||
try:
|
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()):
|
if(lidar.Connect()):
|
||||||
lidar_status = True
|
lidar_status = True
|
||||||
ws_message_queue.appendleft("lidar connected " + lidar_port)
|
ws_message_queue.appendleft("lidar connected " + lidar_port)
|
||||||
@@ -51,19 +51,16 @@ async def init():
|
|||||||
else:
|
else:
|
||||||
ws_message_queue.appendleft("<connection>false")
|
ws_message_queue.appendleft("<connection>false")
|
||||||
|
|
||||||
def arduino_write_read(x):
|
def setY(y):
|
||||||
arduino.write(bytes(x, 'utf-8'))
|
arduino.write(bytes("<set><"+str(y)+">", 'utf-8'))
|
||||||
data1 = arduino.readline()
|
data1 = arduino.readline()
|
||||||
return filterY(str(data1))
|
return filterY(str(data1))
|
||||||
|
|
||||||
def setY(y):
|
|
||||||
tmp = arduino_write_read("<set><"+str(y)+">")
|
|
||||||
|
|
||||||
def filterY(data):
|
def filterY(data):
|
||||||
temp = data[data.find("<"):data.find(">")]
|
temp = data[data.find("<"):data.find(">")]
|
||||||
return temp + data[data.find("><"):data.find(">", data.find("><")+2)+1]
|
return temp + data[data.find("><"):data.find(">", data.find("><")+2)+1]
|
||||||
|
|
||||||
def senddata(data,posy):
|
def sendData(data,posy):
|
||||||
global scan_id
|
global scan_id
|
||||||
temp ="{\"Id\": \""+scan_id+"\",\"ScanPoints\":["
|
temp ="{\"Id\": \""+scan_id+"\",\"ScanPoints\":["
|
||||||
for x,y in data.items():
|
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) + "},")
|
# f.write("{\"RAY\":" + str(posy) + ",\"RAX\":" + str(x) + ",\"DistanceMM\":" + str(y) + "},")
|
||||||
l = len(temp)
|
l = len(temp)
|
||||||
temp = temp[:l-1] + "]}"
|
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'})
|
r = requests.put(url='http://localhost:35588/scandata', data=temp, headers={'content-type': 'application/json'})
|
||||||
#print(r.status_code)
|
#print(r.status_code)
|
||||||
|
|
||||||
|
|
||||||
def startScaner(mode):
|
def startScanner(mode):
|
||||||
global scan_progress, lidar, stop_scan, scan_id
|
global scan_progress, lidar, stop_scan, scan_id, arduino_status
|
||||||
if lidar_status == True:
|
if lidar_status == True and arduino_status == True:
|
||||||
ws_message_queue.appendleft(str(lidar.GetDeviceInfo()))
|
ws_message_queue.appendleft(str(lidar.GetDeviceInfo()))
|
||||||
scan_id = str(uuid.uuid4())
|
scan_id = str(uuid.uuid4())
|
||||||
ws_message_queue.appendleft("Scan ID: " + scan_id)
|
ws_message_queue.appendleft("Scan ID: " + scan_id)
|
||||||
@@ -90,8 +87,7 @@ def startScaner(mode):
|
|||||||
for y in range(19):
|
for y in range(19):
|
||||||
if(stop_scan == True):
|
if(stop_scan == True):
|
||||||
break
|
break
|
||||||
print("send data")
|
sendData(next(gen),y*10)
|
||||||
senddata(next(gen),y*10)
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
setY(y*10)
|
setY(y*10)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
@@ -105,7 +101,7 @@ def startScaner(mode):
|
|||||||
for y in range(91):
|
for y in range(91):
|
||||||
if(stop_scan == True):
|
if(stop_scan == True):
|
||||||
break
|
break
|
||||||
senddata(next(gen),y*2)
|
sendData(next(gen),y*2)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
setY(y*2)
|
setY(y*2)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@@ -119,7 +115,7 @@ def startScaner(mode):
|
|||||||
for y in range(361):
|
for y in range(361):
|
||||||
if(stop_scan == True):
|
if(stop_scan == True):
|
||||||
break
|
break
|
||||||
senddata(next(gen),y*0.5)
|
sendData(next(gen),y*0.5)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
setY(y*0.5)
|
setY(y*0.5)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
@@ -151,21 +147,21 @@ async def wsaction(command, value):
|
|||||||
if command == "start":
|
if command == "start":
|
||||||
if value == "0":
|
if value == "0":
|
||||||
ws_message_queue.appendleft("start scan on low resolution")
|
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()
|
x.start()
|
||||||
elif value =="1":
|
elif value =="1":
|
||||||
ws_message_queue.appendleft("start scan on medium resolution")
|
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()
|
x.start()
|
||||||
elif value =="2":
|
elif value =="2":
|
||||||
ws_message_queue.appendleft("start scan on high resolution")
|
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()
|
x.start()
|
||||||
else:
|
else:
|
||||||
ws_message_queue.appendleft("mode error")
|
ws_message_queue.appendleft("mode error")
|
||||||
elif command == "connect" and arduino and lidar != None:
|
# elif command == "connect" and arduino and lidar != None:
|
||||||
ws_message_queue.appendleft("try to connect to Adruino and LIDAR")
|
# ws_message_queue.appendleft("try to connect to Adruino and LIDAR")
|
||||||
await init()
|
# await init()
|
||||||
elif command == "status":
|
elif command == "status":
|
||||||
ws_message_queue.appendleft("progress: " + scan_progress)
|
ws_message_queue.appendleft("progress: " + scan_progress)
|
||||||
elif command == "stop":
|
elif command == "stop":
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<!--<button v-on:click="connection_status = !connection_status" >test</button>-->
|
|
||||||
<button v-on:click="progress = 0, logs = []" >clear logs</button>
|
<button v-on:click="progress = 0, logs = []" >clear logs</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -71,7 +70,6 @@ export default {
|
|||||||
if(message.search("<") != -1){
|
if(message.search("<") != -1){
|
||||||
that.command = message.substr(message.search("<")+1, message.search(">")-1)
|
that.command = message.substr(message.search("<")+1, message.search(">")-1)
|
||||||
that.value = message.substr(message.search(">")+1)
|
that.value = message.substr(message.search(">")+1)
|
||||||
//console.log("command: " + that.command + " / value: " + that.value)
|
|
||||||
this.action(that.command, that.value)
|
this.action(that.command, that.value)
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -143,19 +141,17 @@ li {
|
|||||||
.progressbar {
|
.progressbar {
|
||||||
background-color: grey;
|
background-color: grey;
|
||||||
border-radius: 7px;
|
border-radius: 7px;
|
||||||
/* (height of inner div) / 2 + padding */
|
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.progressbar>div {
|
.progressbar>div {
|
||||||
/* Adjust with JavaScript */
|
|
||||||
height: 20px;
|
height: 20px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
background-color: #4CAF50; /* Green */
|
background-color: #4CAF50;
|
||||||
border: none;
|
border: none;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 15px 32px;
|
padding: 15px 32px;
|
||||||
@@ -173,6 +169,6 @@ li {
|
|||||||
|
|
||||||
.button2 {background-color: #00ba9b;}
|
.button2 {background-color: #00ba9b;}
|
||||||
.button3 {background-color: #008cff}
|
.button3 {background-color: #008cff}
|
||||||
.button4 {background-color: #f44336;} /* Red */
|
.button4 {background-color: #f44336;}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user