-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
94 lines (74 loc) · 2.67 KB
/
main.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# Imports - Logging
import logger
import logging
# Imports - Handle exiting
from sys import exit as sys_exit
# Imports - Control
from odriveMotorController import odriveMotorController
import easy_scpi as scpi
import pyvisa
from powerSupply import DP832
# Start Logger
logger = logging.getLogger("DynamometerControl")
logger.setLevel(logging.DEBUG)
# VISA Configuration
# TODO: Unended if using easy_scpi
# https://pypi.org/project/easy-scpi/
# https://pyvisa.readthedocs.io/en/latest/introduction/configuring.html
# Keysight / Agilent Technologies VISA
#KATVisaRM = pyvisa.highlevel.ResourceManager("C:\\Program Files (x86)\\IVI Foundation\\VISA\\WinNT\\agvisa\\agbin\\visa32.dll")
KATVisaRM = pyvisa.highlevel.ResourceManager()
#a = pyvisa.ResourceManager() #? # Alt method? # TODO
logger.info("Keysight / Agilent Technologies VISA: " + str(KATVisaRM.visalib))
logger.info("Keysight / Agilent Technologies VISA Resources: " + str(KATVisaRM.list_resources()))
# National Instruments VISA
NI_VISA = 'C:\\Windows\\system32\\visa32.dll'
NIVisaRM = pyvisa.highlevel.ResourceManager(NI_VISA)
logger.info("National Instruments VISA: " + str(NIVisaRM.visalib))
logger.info("National Instruments VISA Resources: " + str(NIVisaRM.list_resources()))
# Connect to & Configure Power supply
powerSupply = DP832("USB0", 12.0, 3.0)
powerSupply.enable()
# Connect to & Configure Odrive motor controller
try:
motor1 = odriveMotorController()
motor1.configure()
motor1.verifyConfig()
except AttributeError as e:
logger.fatal("Failed to connect to odrive controller: " + str(e))
logger.info("Shutting off the power supply.")
powerSupply.write(":OUTP CH1,OFF") # Turn off the power supply
sys_exit(-1)
except NotImplementedError as e:
logger.fatal("Error when connecting odrive controller du to incomplete script (Yes, you may blame programming this time): " + str(e))
logger.info("Shutting off the power supply.")
powerSupply.write(":OUTP CH1,OFF") # Turn off the power supply
sys_exit(-1)
# Connect to & Configure Multimeter
multimeter = scpi.Instrument(port=None)
# TODO: finish
# Connect to & Configure Digital Load
load = scpi.Instrument(port=None, backend=NI_VISA)
# TODO: finish
# To start:
#"""
try:
motor1.startSensorless()
except SystemExit as e:
logger.debug("Failed to start motor: " + str(e))
logger.info("Shutting off the power supply.")
powerSupply.write(":OUTP CH1,OFF") # Turn off the power supply
sys_exit(-1)
#"""
# TODO: finish
# Main loop
#"""
powerSupply.updateOutputStats()
powerSupply.getOutputVoltage()
powerSupply.getOutputCurrent()
powerSupply.getOutputPower()
#"""
# Stop
## TODO: Verify that this is correct
motor1.stop()
powerSupply.disable()