started my own tcmc lib
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{"std_test_mov": [-10, 10],
|
||||
{"std_test_mov": [-10, 0],
|
||||
"std_test_wait": [10, 50],
|
||||
"backlsh_meas_mov": [10, -10, -10, 10],
|
||||
"backlash_meas_wait": [1]}
|
||||
@@ -1,29 +1,90 @@
|
||||
import ctypes.wintypes
|
||||
from ctypes import c_ubyte, c_double
|
||||
|
||||
import numpy as np
|
||||
import pyads
|
||||
import time
|
||||
import struct
|
||||
|
||||
import struct
|
||||
from ctypes import (
|
||||
memmove,
|
||||
addressof,
|
||||
c_ubyte,
|
||||
Array,
|
||||
Structure,
|
||||
sizeof,
|
||||
create_string_buffer,
|
||||
)
|
||||
from datetime import datetime
|
||||
from functools import partial
|
||||
from typing import Optional, Union, Tuple, Any, Type, Callable, Dict, List, cast, OrderedDict
|
||||
|
||||
from pyads import StructureDef, size_of_structure, dict_from_bytes
|
||||
from sklearn.externals.array_api_compat.dask.array import astype
|
||||
|
||||
simpleMove = (
|
||||
("axisNr", pyads.PLCTYPE_UINT,1),
|
||||
("targetPos", pyads.PLCTYPE_LREAL,1),
|
||||
("velocity", pyads.PLCTYPE_LREAL,1)
|
||||
)
|
||||
|
||||
AMS_NET_ID = "5.67.222.118.1.1"
|
||||
PLC_IP = "129.129.181.164"
|
||||
PORT = 501#852 # your port (not the runtime port like 851)
|
||||
PORT = 851 # your port (not the runtime port like 851)
|
||||
|
||||
IGRP = 0xF030
|
||||
IOFFS = 0x47C
|
||||
LENGTH = 8 # bytes
|
||||
|
||||
with pyads.Connection(AMS_NET_ID, PORT,PLC_IP) as plc:
|
||||
while True:
|
||||
t = plc.read(IGRP, IOFFS, pyads.PLCTYPE_UDINT*4)
|
||||
#t= (plc.read_by_name( "GVL.astAxes[1].Axis.NcToPlc.CoupleState"))
|
||||
if t > 0.0:
|
||||
print(f"Torque is {t}")
|
||||
# Axis ADS variables (TwinCAT NC axis interface)
|
||||
AXIS1_REF = 1 # Axis ID for axis 1
|
||||
AXIS2_REF = 4 # Axis ID for axis 2
|
||||
|
||||
# Interpret the raw bytes, e.g. as 64-bit integer or double
|
||||
# Here: unpack as little-endian unsigned 64-bit integer
|
||||
import struct
|
||||
plc = pyads.Connection(AMS_NET_ID, PORT,PLC_IP)
|
||||
|
||||
#value = struct.unpack("<d", data)[0]
|
||||
def gearin(connection):
|
||||
print(connection.write_by_name("GVL.GerarInCmd", True, pyads.PLCTYPE_BOOL))
|
||||
print(connection.write_by_name("GVL.GerarOutCmd", False, pyads.PLCTYPE_BOOL))
|
||||
|
||||
def gearout(connection):
|
||||
print(connection.write_by_name("GVL.GerarInCmd", False, pyads.PLCTYPE_BOOL))
|
||||
print(connection.write_by_name("GVL.GerarOutCmd", True, pyads.PLCTYPE_BOOL))
|
||||
|
||||
def enableAxis(connection):
|
||||
connection.write_by_name("GVL.EnableAxis", True, pyads.PLCTYPE_BOOL)
|
||||
|
||||
def disableAxis(connection):
|
||||
connection.write_by_name("GVL.EnableAxis", False, pyads.PLCTYPE_BOOL)
|
||||
|
||||
def stopAxis(connection):
|
||||
while connection.read_by_name("GVL.Axis1Stoping", pyads.PLCTYPE_BOOL) == False:
|
||||
connection.write_by_name("GVL.StopCmd", True, pyads.PLCTYPE_BOOL)
|
||||
connection.write_by_name("GVL.StopCmd", False, pyads.PLCTYPE_BOOL)
|
||||
|
||||
def moveAbsolut(connection, Axis_ref, TargetPos, velocity):
|
||||
stopAxis(connection)
|
||||
connection.write_by_name("GVL.moveInterface.targetPos", TargetPos,pyads.PLCTYPE_LREAL)
|
||||
connection.write_by_name("GVL.moveInterface.axisNr", Axis_ref, pyads.PLCTYPE_UINT)
|
||||
connection.write_by_name("GVL.moveInterface.velocity", velocity, pyads.PLCTYPE_LREAL)
|
||||
|
||||
def executeCmd(connection):
|
||||
while connection.read_by_name("GVL.Done", pyads.PLCTYPE_BOOL) == False:
|
||||
connection.write_by_name("GVL.StartCmd", True, pyads.PLCTYPE_BOOL)
|
||||
connection.write_by_name("GVL.Done", False, pyads.PLCTYPE_BOOL)
|
||||
connection.write_by_name("GVL.StartCmd", False, pyads.PLCTYPE_BOOL)
|
||||
|
||||
|
||||
|
||||
time.sleep(0.1) # adjust read interval
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("Testing torque")
|
||||
plc.open()
|
||||
#enableAxis(plc)
|
||||
#disableAxis(plc)
|
||||
enableAxis(plc)
|
||||
#gearout(plc)
|
||||
#stopAxis(plc)
|
||||
#plc.write_by_name("GVL.StopCmd", False, pyads.PLCTYPE_BOOL)
|
||||
moveAbsolut(plc, 0, 100, 0.5)
|
||||
#executeCmd(plc)
|
||||
plc.close()
|
||||
|
||||
|
||||
Binary file not shown.
@@ -317,36 +317,50 @@ def run_repeatability_series(
|
||||
|
||||
# enable axis clean up later
|
||||
|
||||
axis1.setAcceleration(50.0)
|
||||
axis1.setDeceleration(50.0)
|
||||
axis1.setAcceleration(5.0)
|
||||
axis1.setDeceleration(5.0)
|
||||
axis1.setVelocity(3)
|
||||
axis1.disableAxis()
|
||||
sleep(1)
|
||||
axis1.enableAxis()
|
||||
axis1.
|
||||
|
||||
|
||||
sleep(1)
|
||||
|
||||
axis4.setAcceleration(50.0)
|
||||
axis4.setDeceleration(50.0)
|
||||
axis4.setAcceleration(5.0)
|
||||
axis4.setDeceleration(5.0)
|
||||
axis4.setVelocity(3)
|
||||
|
||||
axis4.disableAxis()
|
||||
sleep(1)
|
||||
axis4.enableAxis()
|
||||
sleep(1)
|
||||
exit(1)
|
||||
|
||||
# --------------------------------------load coordinates from file-----------------------
|
||||
x_coordinates_json = myu.load_object(measurement_mov_path)
|
||||
x_coordinates = x_coordinates_json.get('std_test_mov')
|
||||
wait_x_json = myu.load_object(measurement_mov_path)
|
||||
wait_x = wait_x_json.get('std_test_wait')
|
||||
print(wait_x)
|
||||
print("WaitPattern: ",wait_x)
|
||||
print("movPattern",x_coordinates)
|
||||
start1 = axis1.getActPos()
|
||||
print("start1",start1)
|
||||
print("target1",start1+x_coordinates[0])
|
||||
start4 = axis4.getActPos()
|
||||
|
||||
for i in range(ntries):
|
||||
# ---------------------------------------------move------------------------------------------
|
||||
# add multithreading for simultanious movement of y and x axis
|
||||
for mov, wait in zip(x_coordinates, wait_x):
|
||||
axis1.moveRelative(mov)
|
||||
axis4.moveRelative(mov)
|
||||
t1 = start1+mov
|
||||
print("t1",t1)
|
||||
while axis1.getMovingStatus() or axis4.getMovingStatus():
|
||||
print("waiting on axis")
|
||||
axis4.moveAbsolute(start4+(mov))
|
||||
axis1.moveAbsolute(t1)
|
||||
sleep(0.05)
|
||||
|
||||
|
||||
sleep(wait)
|
||||
start_pos_rbv = 4 # ????
|
||||
meas_pos_rbv = 5 # ????
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
0 4.000000 5.000000 141.123 146.690 1755614646.922
|
||||
1 4.000000 5.000000 141.018 146.333 1755614670.329
|
||||
@@ -0,0 +1 @@
|
||||
{"Number_of_cycles": 2, "Amplitude_mm": 1, "Time_in_beam_s": 5, "Time_out_of_beam_s": 10, "Exposure_time": 0.0001, "Img_Processing": 1, "pixel_size_mu": 0.275, "long_time_interval": 50}
|
||||
@@ -0,0 +1,2 @@
|
||||
1 0.000000 0.000000 141.041 146.367 1755614680.327
|
||||
2 0.000000 0.000000 141.143 146.189 1755614680.489
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
0 4.000000 5.000000 142.147 145.180 1755616306.703
|
||||
1 4.000000 5.000000 142.537 145.074 1755616330.020
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
0 4.000000 5.000000 -902.174 96.387 1755616897.370
|
||||
1 4.000000 5.000000 189.994 114.706 1755616942.127
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
0 4.000000 5.000000 131.931 456.240 1755617197.650
|
||||
1 4.000000 5.000000 1012.102 102.046 1755617230.496
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
0 4.000000 5.000000 124.419 127.096 1755617903.859
|
||||
1 4.000000 5.000000 114.836 134.107 1755617929.067
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
0 4.000000 5.000000 115.654 186.859 1755620593.486
|
||||
1 4.000000 5.000000 -436.682 105.386 1755620625.926
|
||||
2 4.000000 5.000000 90.086 205.844 1755620657.317
|
||||
3 4.000000 5.000000 -768.041 115.024 1755620687.385
|
||||
4 4.000000 5.000000 -2110.679 -411.303 1755620714.897
|
||||
5 4.000000 5.000000 6326.494 109.449 1755620747.264
|
||||
6 4.000000 5.000000 88.276 125.691 1755620775.516
|
||||
7 4.000000 5.000000 -688.586 133.320 1755620807.006
|
||||
8 4.000000 5.000000 151.561 59.660 1755620833.231
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
0 4.000000 5.000000 91.946 112.013 1755621000.760
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
0 4.000000 5.000000 -1007.293 175.311 1755621354.107
|
||||
1 4.000000 5.000000 1275.260 81.079 1755621431.851
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
0 4.000000 5.000000 152.714 111.319 1755673840.713
|
||||
1 4.000000 5.000000 149.607 111.895 1755673904.511
|
||||
2 4.000000 5.000000 152.606 110.521 1755673971.075
|
||||
3 4.000000 5.000000 154.080 110.783 1755674035.423
|
||||
4 4.000000 5.000000 151.047 111.064 1755674099.762
|
||||
5 4.000000 5.000000 127.727 104.807 1755674166.338
|
||||
6 4.000000 5.000000 129.495 109.062 1755674232.720
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
0 4.000000 5.000000 153.749 106.743 1755674642.599
|
||||
1 4.000000 5.000000 152.676 107.505 1755674706.410
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user