-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_motor.py
30 lines (25 loc) · 1.12 KB
/
test_motor.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
from example.MotorControllerExample.MotorHardware import CommandVelocity, Motor, MotorVelocity, ReferenceVelocity, \
VelocityPID
from architecture.scheduler import Scheduler
if __name__ == "__main__":
motor = Motor(is_sim=False)
velocity_pid = VelocityPID(is_sim=False)
motor_velocity = MotorVelocity(is_sim=False)
reference_velocity = ReferenceVelocity(is_sim=False, reference_velocity=1)
# set relationships
reference_velocity.add_subscriber(velocity_pid)
motor_velocity.add_subscriber(velocity_pid)
velocity_pid.add_subscriber(motor)
# set commands
command_velocity = CommandVelocity(reference_velocity, reference_velocity=1)
# set scheduler
scheduler = Scheduler(False)
scheduler.set_command_group(command_velocity)
scheduler.add_subscribers(motor)
scheduler.add_topics(reference_velocity, motor_velocity, velocity_pid)
scheduler.initialize()
# run schedule3r
for i in range(1000):
scheduler.periodic()
print("Motor Voltage: {}".format(motor.voltage_hardware))
print("Reference Velocity: {}".format(reference_velocity.reference_velocity))