Working version of databaseCreator and RobotLib 1.0

Signed-off-by: L. Bogner <lars.bogner@outlook.de>
This commit is contained in:
2019-05-13 15:43:55 +02:00
parent f239148c8c
commit d822c6af78
2 changed files with 29 additions and 4 deletions
+19 -3
View File
@@ -88,9 +88,9 @@ class Robot:
self.x = x
self.y = y
self.effi = effi
self.s1 = s1
self.s2 = s2
self.s3 = s3
self.s1 = s1.deg
self.s2 = s2.deg
self.s3 = s3.deg
def pos_is_equal_to(self, other_entry):
return self.x == other_entry.x and self.y == other_entry.y
@@ -120,6 +120,22 @@ class Robot:
else:
self.database.append(entry)
def serialize(self):
string = ""
for entry in self.database:
string += "{},{}:{},{},{}\n".format(str(entry.x), str(entry.y), str(entry.s1.deg), str(entry.s2.deg),
str(entry.s3.deg))
return string
def deserialize(self, string):
entries = string.split("\n")
for entry in entries:
coordinates = entry.split(":")[0]
servos = entry.split(":")[1]
new = self.Entry(float(coordinates[0]), float(coordinates[1]), float(servos[0]), float(servos[1]),
float(servos[2]))
self.database.append(new)
def __init__(self, s1, s2, s3, coordinatessystem):
self.servo1 = s1
self.servo2 = s2
+10 -1
View File
@@ -1,6 +1,7 @@
from RobotLib import *
import numpy as npy
from RobotLib import *
class Looper:
def __init__(self, Robot):
@@ -21,6 +22,13 @@ class Looper:
self.robot.servo3))
print("A database with {} entries has been created.".format(len(self.robot.data.database)))
def export(self):
file = open("database.data", 'w')
file.write(self.robot.data.serialize())
file.flush()
file.close()
print("Exported")
test = Robot(Robot.Servo(1, Robot.Servo.Geometry(0.55, 2.3, 1.4)),
Robot.Servo(2, Robot.Servo.Geometry(2.5, 0.55, 1.55)),
@@ -31,5 +39,6 @@ test.init_depending(Robot.Arm(test.servo1, 10.26, 0.84), Robot.Arm(test.servo2,
looper = Looper(test)
looper.run()
looper.export()
print("finished")
print("test")