-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_2.py
More file actions
49 lines (40 loc) · 1.3 KB
/
example_2.py
File metadata and controls
49 lines (40 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
# Example 2. Looping movements Maxon EPOS4 through UART.
# Operation mode: Profile Position Mode
# Date: 7.11.2022
# Author: Korzhak (GitHub)
# Ukraine
#
from epos4 import Epos4
from epos4 import definitions as df
e = Epos4('COM3')
def move(val):
if e.get_fault_state():
print("Fault state!")
print(repr(e.clear_fault_state()))
if not e.get_enable_state():
print(f"State is disabled.\nSetting enable state...")
print(e.set_enable_state())
print(e.move_to_position(val)) # <- Contains print inside method
if __name__ == "__main__":
# Setting operation mode
print("Set op mode")
om = e.get_operation_mode().get()
if om != df.OM_PPM:
print(f"Changing operation mode {om} to {df.OM_PPM}")
print(repr(e.set_operation_mode(df.OM_PPM)))
print("Operation mode has been set")
# Setting enable state
print("Checking enable state")
if not e.get_enable_state():
print(f"State is disabled.\nSetting enable state...")
print(e.set_enable_state())
print(f"Driver has been set to enable state")
# Moving to position
print("Moving to position:")
try:
for i in range(0xF, 0xFFFF, 0xFF):
move(i)
# Closing connection
except KeyboardInterrupt:
e.close()