def setUp(self): self.axis = Axis("X", command_type="I", command_id=0, test_mode=True) self.axis.debug = True self.axis.frequency = 125000.0 self.axis.pulse_count = 4294967295 self.axis.direction = 1 self.axis.start_ramp = 1 self.axis.finish_ramp = 1 self.axis.ramp_divide = 100 self.axis.ramp_pause = 10 self.axis.link_to_adc = 0 self.axis.enable_line_polarity = 1 self.axis.pulse_count_change_direction = 0 self.axis.pulse_counts_sent_back = 0 self.axis.wait_delay = 0 self.axis.enable_disable_x_pulse_count_replies = 1 self.axis.enable_disable_y_pulse_count_replies = 0 self.axis.enable_disable_z_pulse_count_replies = 0 self.axis.enable_disable_e_pulse_count_replies = 0 self.axis.pause_all_return_x_pulse_count = 0 self.axis.pause_all_return_y_pulse_count = 0 self.axis.pause_all_return_z_pulse_count = 0 self.axis.pause_all_return_e_pulse_count = 0
axis.send_command(axis.change_speed(x)) # Check for both reply and complete responses to be returned wait_for_responses(xaxis, ["RI01QX*", "CI01QX*"], "") # Print the responses print(f"------- Speed changed to {new_rpm} - command responses -------") xaxis.parse_responses(resps) steps_per_rev = int(input("How many steps per revolution [1600]? ") or "1600") direction = 0 # Forward rpm = 300 # Start RPM pulse_count = 4294967295 # Set to max so we can start and stop it when desired xaxis = Axis("X", command_id=1, serial_device="/dev/ttyS0") xaxis.debug = True # Setup the axis with values to start the motor frequency = xaxis.rpm_to_frequency(rpm=rpm, steps_per_rev=steps_per_rev, round_digits=3) set_axis_cmd = xaxis.set_axis(frequency=frequency, pulse_count=pulse_count, direction=direction, start_ramp=1, finish_ramp=1, ramp_divide=100, ramp_pause=10, enable_line_polarity=1) xaxis.send_command(set_axis_cmd) # Get the responses - look for both responses to be returned before continuing wait_for_responses(xaxis, ["RI01CX*", "CI01CX*"], "------- Set axis command responses -------") # Start the motor xaxis.send_command(xaxis.start()) # Check for both reply and complete responses to be returned wait_for_responses(xaxis, ["RI01SX*"], "------- Start command responses -------")
steps_per_rev = int(input("How many steps per revolution [1600]? ") or "1600") total_revolutions = int(input("How many total revolutions [50]? ") or "50") rpm = int(input("How many RPMs [500]? ") or "500") rdc = int( rpm / 10 ) # Calculate ramp divide. 10% of rpm seems to work at least up to 1500 rpm ramp_divide = int(input(f"Ramp divide 0-255 [{rdc}]? ") or f"{rdc}") ramp_pause = int(input("Ramp pause 0-255 [10]? ") or "10") direct = input("Direction (Forward = F, Reverse = R) [F]? ") or "F" direction = 0 if direct.upper() == "F": direction = 0 else: direction = 1 xaxis = Axis("X", command_id=1, serial_device="/dev/ttyS0") xaxis.debug = True # Setup the axis with values to start the motor frequency = xaxis.rpm_to_frequency(rpm=rpm, steps_per_rev=steps_per_rev, round_digits=3) pulse_count = xaxis.calculate_pulse_count(steps_per_rev, total_revolutions) set_axis_cmd = xaxis.set_axis(frequency=frequency, pulse_count=pulse_count, direction=direction, start_ramp=1, finish_ramp=1, ramp_divide=ramp_divide, ramp_pause=ramp_pause, enable_line_polarity=0)
""" This just stops the motor in case a bug is encountered leaving the motor running. """ from pthat.pthat import Axis xaxis = Axis("X", test_mode=True) rpm = int(input("Enter RPM to calculate: ")) ramp_up_speed = int(input("Enter ramp up speed: ")) steps_per_rev = int(input("Enter the steps per revolution: ")) frequency = xaxis.rpm_to_frequency(rpm=rpm, steps_per_rev=steps_per_rev, round_digits=3) if ramp_up_speed == 0: ramp_up_freq = frequency else: ramp_up_freq = frequency / ramp_up_speed ramp_up_rpm = xaxis.frequency_to_rpm(frequency=ramp_up_freq, steps_per_rev=steps_per_rev) print(f"Ramp up: {ramp_up_freq} Hz = {ramp_up_rpm} RPM")
""" This just stops the motor in case a bug is encountered leaving the motor running. """ from pthat.pthat import Axis xaxis = Axis("X", command_id=1, serial_device="/dev/ttyS0") xaxis.auto_send_command = True xaxis.stop()
print(msg) xaxis.parse_responses(responses) steps_per_rev = int(input("How many steps per revolution [1600]? ") or "1600") total_revolutions = int(input("How many total revolutions [50]? ") or "50") rpm = int(input("How many RPMs [500]? ") or "500") direct = input("Direction (Forward = F, Reverse = R) [F]? ") or "F" direction = 0 if direct.upper() == "F": direction = 0 else: direction = 1 # X axis xaxis = Axis("X", command_id=1, serial_device="/dev/ttyS0") xaxis.debug = True xaxis.auto_send_command = True # Calculate frequency and pulse count frequency = xaxis.rpm_to_frequency(rpm=rpm, steps_per_rev=steps_per_rev, round_digits=3) pulse_count = xaxis.calculate_pulse_count(steps_per_rev, total_revolutions) # Setup the X axis rdc = int(rpm / 10) xaxis.set_axis(frequency=frequency, pulse_count=pulse_count, direction=direction, start_ramp=1, finish_ramp=1, ramp_divide=rdc, ramp_pause=10, enable_line_polarity=1) # Get the responses - look for both responses to be returned before continuing wait_for_responses(["RI01CX*", "CI01CX*"], "------- Set X axis command responses -------")
class TestAxis(unittest.TestCase): def setUp(self): self.axis = Axis("X", command_type="I", command_id=0, test_mode=True) self.axis.debug = True self.axis.frequency = 125000.0 self.axis.pulse_count = 4294967295 self.axis.direction = 1 self.axis.start_ramp = 1 self.axis.finish_ramp = 1 self.axis.ramp_divide = 100 self.axis.ramp_pause = 10 self.axis.link_to_adc = 0 self.axis.enable_line_polarity = 1 self.axis.pulse_count_change_direction = 0 self.axis.pulse_counts_sent_back = 0 self.axis.wait_delay = 0 self.axis.enable_disable_x_pulse_count_replies = 1 self.axis.enable_disable_y_pulse_count_replies = 0 self.axis.enable_disable_z_pulse_count_replies = 0 self.axis.enable_disable_e_pulse_count_replies = 0 self.axis.pause_all_return_x_pulse_count = 0 self.axis.pause_all_return_y_pulse_count = 0 self.axis.pause_all_return_z_pulse_count = 0 self.axis.pause_all_return_e_pulse_count = 0 def test_set_axis(self): self.assertEqual("I00CX125000.000429496729511110001001*", self.axis.set_axis()) def test_set_direction_forward(self): self.assertEqual("I00CX125000.000429496729501110001001*", self.axis.set_direction_forward()) def test_set_direction_reverse(self): self.assertEqual("I00CX125000.000429496729511110001001*", self.axis.set_direction_reverse()) def test_enable_start_ramp(self): self.assertEqual("I00CX125000.000429496729511110001001*", self.axis.enable_start_ramp()) def test_disable_start_ramp(self): self.assertEqual("I00CX125000.000429496729510110001001*", self.axis.disable_start_ramp()) def test_enable_finish_ramp(self): self.assertEqual("I00CX125000.000429496729511110001001*", self.axis.enable_finish_ramp()) def test_disable_finish_ramp(self): self.assertEqual("I00CX125000.000429496729511010001001*", self.axis.disable_finish_ramp()) def test_enable_line_polarity_0_volts(self): self.assertEqual("I00CX125000.000429496729511110001000*", self.axis.enable_line_polarity_0_volts()) def test_enable_line_polarity_5_volts(self): self.assertEqual("I00CX125000.000429496729511110001001*", self.axis.enable_line_polarity_5_volts()) def test_set_auto_direction_change(self): self.axis.pulse_count_change_direction = 100 self.assertEqual("I00BX0000000100*", self.axis.set_auto_direction_change()) def test_set_auto_count_pulse_out(self): self.axis.pulse_counts_sent_back = 100 self.axis.enable_disable_x_pulse_count_replies = 1 self.axis.enable_disable_y_pulse_count_replies = 0 self.axis.enable_disable_z_pulse_count_replies = 0 self.axis.enable_disable_e_pulse_count_replies = 0 self.assertEqual("I00JX00000001001000*", self.axis.set_auto_count_pulse_out()) def test_start(self): self.assertEqual("I00SX*", self.axis.start()) def test_start_all(self): self.assertEqual("I00SA*", self.axis.start_all()) def test_stop(self): self.assertEqual("I00TX*", self.axis.stop()) def test_stop_all(self): self.assertEqual("I00TA*", self.axis.stop_all()) def test_pause(self): self.assertEqual("I00PX0000*", self.axis.pause()) def test_pause_all(self): self.assertEqual("I00PA0000*", self.axis.pause_all()) def test_resume(self): self.assertEqual("I00PX0000*", self.axis.resume()) def test_resume_all(self): self.assertEqual("I00PA0000*", self.axis.resume_all()) def test_get_current_pulse_count(self): self.assertEqual("I00XP*", self.axis.get_current_pulse_count()) def test_change_speed(self): self.assertEqual("I00QX001000.000*", self.axis.change_speed(new_frequency=1000.000)) def test_enable_limit_switches(self): self.assertEqual("I00KX1*", self.axis.enable_limit_switches()) def test_disable_limit_switches(self): self.assertEqual("I00KX0*", self.axis.disable_limit_switches()) def test_enable_emergency_stop(self): self.assertEqual("I00KS1*", self.axis.enable_emergency_stop()) def test_disable_emergency_stop(self): self.assertEqual("I00KS0*", self.axis.disable_emergency_stop())
""" This is an example of setting up an Axis (motor) and starting it, revving it up to a specified RPM and letting it run for some time and then shutting it down. This example does not auto send the commands. It gets the command and then sends it to the send_command method. """ from pthat.pthat import Axis def wait_for_responses(axis, responses_to_check, msg): responses = axis.get_all_responses() while not all(x in responses for x in responses_to_check): responses = responses + axis.get_all_responses() # Print the responses print(msg) axis.parse_responses(responses) xaxis = Axis("X", command_id=1, serial_device="/dev/ttyS0") xaxis.debug = True # Get the firmware version firmware_version_cmd = xaxis.get_firmware_version() xaxis.send_command(firmware_version_cmd) # Show the responses wait_for_responses(xaxis, ["RI00FW*", "CI00FW*"], "------- Get firmware version command responses -------")