wni.motor

Submodules

wni.motor.commands

A program is a list of commands; most of the methods relate to commands found in the Silverpak23C_R3566_Commands.PDF manual.

wni.motor.commands.adjust_microsteps(adjustment)[source]

Allows user to correct any unevenness in microstep size. Adjusts audible noise and should be executed while motor is running. Should only be adjusted in small increments and should not exceed 1650 and should not be set below 1400.

Range: [1400, 1650]

Command: o

wni.motor.commands.begin_loop()[source]

Beginning of a repeat loop

Command: g

wni.motor.commands.delay(milliseconds)[source]

Delay for given number of milliseconds

Range: [0, 30000]

Command: M

wni.motor.commands.end_loop(repetitions)[source]

End of a repeat loop. Loops can be nested up to 4 levels. A value of 0 causes the loop to be infinite.

Range: [0, 30000]

Command: G

wni.motor.commands.erase_programs()[source]

Commandes all commands/program stored in EPROM except for the any settings such as current, microstepping, velocity, acceleration and any other settings

Command: ?9

wni.motor.commands.execute_program(program)[source]

Executes the Stored Programs 0-15. You can execute one program within a program.

i.e. /1s0V500j2e1R, and /1s1gP1000M500G5e2R and /1s2f1Z100000R: This example will power on, execute speed of 500, 2x microstep and execute program #1: move 1000 steps and pause 0.5 seconds (5 times), then execute program 2 which will home the motor in the opposite direction.

Range: [0, 15]

Command: e

wni.motor.commands.get_controller_status()[source]

Query current status of the controller: 0 = No Error 1 = Initialization error 2 = Bad Command 3 = Operand out of range

wni.motor.commands.get_current_command()[source]

Recalls current command executed. To see what currently stored in a specific program, run the program and issue the /1$ example: /1e2R /1$

Command: $

wni.motor.commands.get_encoder_position()[source]

Returns the current encoder position (can be zeroed by “z” command)

Command: ?8

wni.motor.commands.get_firmware()[source]

Returns current Firmware revision and date

Command: &

wni.motor.commands.get_input_values()[source]

Returns the status of all four inputs, 0-15 representing a 4 bit binary pattern:

Bit 0 = Input 1 (Pin 13) Bit 1 = Input 2 (Pin 5) Bit 2 = Input 3 (Pin7) Bit 3 = Input 4 (Pin 14)

Command: ?4

wni.motor.commands.get_o_value()[source]

Returns the current ‘o’ value (TODO: microstep adjustment?)

Command: ?7

wni.motor.commands.get_position()[source]

Returns the current motor position

Command: ?0

wni.motor.commands.get_slew_speed()[source]

Returns the current Slew Speed for Position Mode

Command: ?2

wni.motor.commands.get_start_velocity()[source]

Returns the current Start Velocity

Command: ?1

wni.motor.commands.get_step_size()[source]

Returns the current step size

Command: ?6

wni.motor.commands.get_stop_speed()[source]

Returns the current Stop Speed

Command: ?3

wni.motor.commands.get_velocity()[source]

Returns the current Velocity mode speed

Command: ?5

wni.motor.commands.halt_wait(value, pin)[source]

Halt current command string and wait until condition specified.

Parameters:
  • value – 0 or 1; 0 for low, 1 for high
  • pin – one of 1-4, inclusive.

Causes the motor to delay executing commands until the condition is met.

01 Wait for low on input 1 (Pin 13) 11 Wait for high on input 1 (Pin 13) 02 Wait for low on input 2 (Pin 5) 12 Wait for high on input 2 (Pin 5) 03 Wait for low on input 3 (Pin 7) 13 Wait for high on input 3 (Pin 7) 04 Wait for low on input 4 (Pin 14) 14 Wait for high on input 4 (Pin 14)

  • Halted operation can also be resumed by typing /1R
  • If it is desired to stop motion rather than to wait for the input and move, one can use input 2 (pin 5) to stop motion of a P0 or D0 command. /1P0R and close input 2 to ground to stop motion.

Range (two arguments): [0, 1], [1, 4]

Commmand: H<value><pin>

wni.motor.commands.hold_current(current)[source]

Sets the Hold Current on a scale of 0 to 50% of the max current, 3.0 Amps. Default setting is h10.

Range: [0, 50]

Command: h

wni.motor.commands.home_and_initialize(num_steps)[source]

Motor goes toward 0 until opto sensor is interrupted. The motor will go num_steps steps to find the home sensor; if the sensor is not found, it will stop motion. Only opto #1 can be used with this.

Range: [0, 2**31)

Command: Z

wni.motor.commands.move_relative_negative(num_steps)[source]

Move Motor relative number of steps in negative direction (Note: Motor will not run in the negative direction if the position is at 0. You can use the “z” command to set the 0 position to be further away in the negative direction. OR you can use the F command to reverse direction of rotation.) A “D0” command rotates motor infinitely, which enters into Velocity Mode. Any other finite number will set the mode to be in Position Mode.

Range: [0, 2**31)

Command: D

wni.motor.commands.move_relative_positive(num_steps)[source]

Move Motor relative number of steps in positive direction. A “P0” command rotates motor infinitely, which enters into Velocity Mode. Any other finite number will set the mode to be in Position Mode.

Range: [0, 2**31)

Command: P

wni.motor.commands.move_to(position)[source]

Move Motor to Absolute position. i.e. moves to the 10000th step. Issuing A10000 again will NOT move the motor because it is already at that value.

Range: [0, 2**31)

Command: A

wni.motor.commands.on_off_driver(value)[source]

On/Off Driver. Turns on or off the two outputs. (I/O’s are bidirectional) It’s a two bit Binary value: 3=0b11=Both Drivers On, 2=0b10=Driver2 on, Driver1 off, etc. (Drivers output 3VDC max)

Range: [0, 3]

Command: J

wni.motor.commands.recover_encoder()[source]

This will recover the encoder after there has been a timeout due to an overload timeout on the encoder (See Appendix 1)

Range: None

Command: r

wni.motor.commands.repeat_program()[source]

Repeat the current command string

Range: None

Command: X

wni.motor.commands.reverse(direction)[source]

Reverses the positive direction to be negative. The P and D commands will switch directions. Default is 0; valid values are 0 and 1.

Range: [0, 1]

Command: F

wni.motor.commands.run_program()[source]

Run the command string that is currently in the execution buffer – Always end commands with ‘R’.

Range: None

Command: R

wni.motor.commands.send_number(n)[source]

Sends out the number 66 or any number placed after p, mostly used for confirmation of when a move is done. For example /1P1000p66R will send out the number 66 when the motor has moved 1000 steps. (Any number can be used after p).

Command: p

wni.motor.commands.set_acceleration(a)[source]

This sets the Acceleration factor microsteps/sec^2 = (L Value) x (6103.5). i.e. /1L1R takes 16.384 Seconds to get to a speed of V=100000 (microsteps/sec) Default is L=1000, default speed V = 305175 microsteps/sec, so default acceleration = 6103500 microstepssec^2. I should take 0.05 seconds to get to to top speed.

Range: [0, 65000]

Command: L

wni.motor.commands.set_accuracy(a)[source]

When in position correction mode, set distance allowed to move before the motor corrects using encoder feedback. See Appendix 1

Range: [1, 65000]

Command: aC

wni.motor.commands.set_baud_rate(rate)[source]

This command will usually be stored as program zero and execute on power up. Default baud rate is 9600.

Range: 9600, 19200, 38400 Command: b

wni.motor.commands.set_current(current)[source]

Sets the running current on a scale of 0 to 100% of the max current, 3.0A. Default setting is m30.

Range: [0, 100]

Command: m

wni.motor.commands.set_current_position(position)[source]

Sets the current position without moving the motor. Works accurately when new position is divisible by 1024.

Range: [0, 2**31)

Command: z

wni.motor.commands.set_encoder_ratio(ratio)[source]

Set Encoder ratio. This sets the ratio between the encoder ticks/rev an the microsteps/rev for the motor. See Appendix 1

Range: [1000, 10^6]

Command:aE

wni.motor.commands.set_home_sensor_polarity(polarity)[source]

Sets polarity of direction of home sensor, default is 0.

Range: 0, 1

Command: f

wni.motor.commands.set_jog_distance(distance)[source]

Sets the distance for pulse jog mode (see n command)

Range: [0, 2**31)

Command: B

wni.motor.commands.set_microsteps_per_step(microsteps)[source]

Adjusts the resolution in micro-steps per step. Available resolutions: Full step, 2x, 4x, 8x, 16x, 32x, 64x, 128x, 256x.

Range: 1, 2, 4, 8, 16, 32, 64, 128, 256

Command: j

wni.motor.commands.set_mode(mode)[source]

Sets Modes - Interpret as combination of Binary Bits

Bit0: Enable Pulse Jog Mode. Jog distance is given by “B” command. Velocity is given by command. The Switch Inputs 1 and 2 become the Jog Inputs. Press input 1 to rotate CW for a given distance, B. Press input 2 to rotate CCW for a given distance, B. If also in position correction mode, “B” will will be in microsteps and not encoder counts.

Bit1: Enable Limit. The opto input #3, pin 7, becomes one limit switch for rotating CW (using P command). The opto input #4, pin 14, becomes the other limit switch for rotating CCW (using D command). Use /1P0R to rotate towards the limit switch. Can be combined with other commands like: /1P0P500R: rotate continuously until input 3 is low, then move 500 more steps.

Bit2: /1n4R Enable Continuous Jog Mode. Continuous run of motor while switch is depressed. Velocity is given by the “V” command. Note that the jog mode allows moves below zero, which will be interpreted by any subsequent “A” commands as a large positive number. If this is undesirable, please use the “z” command to define zero position to be some positive number so that underflow will not occur.

Bit3: Enables Position Correction Mode.

Bit4: Enabled Overload Report Mode.

Bit5: Enable Step And Direction Mode A value of 1 for this mode, or enable Dual Encoder Mode if value of 0. i.e. /1n96<CR> (96=32+64) Enables step and dir mode and slaves the motor to it.

Bit6: Enable Motor slave to encoder/step-dir.

Range: [0, 4095]

Command:n

wni.motor.commands.set_overload_timeout(timeout)[source]

Set Overload Timeout. This sets the number of times the move is retried in case a move stalls. See Appendix 1

Range: [1, 10^6]

Command: au

wni.motor.commands.set_velocity(v)[source]

In Position Mode, this sets the Top Speed of the Motor in microsteps/sec. During velocity mode, speed can be changed on the fly (during rotation).

Range: [0, 2**31)

Command: V

wni.motor.commands.skip_next_if(value, pin)[source]

Skip command: will skip the command following it if the input is high or low.

Useful for executing different programs based on a high or low signal on an input.

The args are the same as in halt_wait

Range (two arguments): [0, 1], [1, 4]

Command: S<value><pin>

wni.motor.commands.special_modes(mode)[source]

Special Modes potential values:

  1. Encoder with no index (default). Motor will home to the opto
    sensor #1, pin 7.
  2. Encoder with index. Homes to the index.

Range: 1, 2

Command: N

wni.motor.commands.start(address)[source]

The command required to start a program.

Command: /[address]

wni.motor.commands.store_program(program)[source]

Stores a program. Program 0 is executed on power up (Total of 14 commands max per string when storing, but if not storing you can send 256 characters max).

Range: [0, 15]

Command: s

wni.motor.commands.terminate_current_command()[source]

Terminate current command

Range: None

Command: T

wni.motor.r356

Python code for controlling the Lin Engineering R356 Motor Controller

class wni.motor.r356.FakeR356(address=1, dev='/dev/ttyUSB0', baudrate=9600)[source]

Bases: wni.motor.r356.R356

A fake R356 motor so that testing can be done without a motor hooked up.

This emulates a motor as best as I could.

do(cmd)[source]

Not going to actually do anything

get_actual_position()[source]
get_degrees_per_second()[source]
get_position(now=None)[source]

This function, along with self._calc_movement(), are the most important functions for the FakeR356.

go_home(num_steps=1000000)[source]
is_spinning
negative(steps)[source]
positive(steps)[source]
run_current_program()[source]

Don’t run the current program

set_initial_position(pos)[source]
stop()[source]
zero()[source]

Sets current position to 0

class wni.motor.r356.Motor(motor, home_angle=0)[source]

Bases: object

An abstraction over the R356, so the user can think in degrees instead of stepper positions

acceleration(acc)[source]
degrees_per_second(deg)[source]
get_acceleration()[source]
get_actual_position()[source]
get_degrees_per_second()[source]
get_position()[source]

Return the current position, in degrees.

home()[source]
is_spinning
negative(degrees)[source]
point(degrees)[source]

From a stopped state, point a different direction.

positive(degrees)[source]
spin()[source]
stop()[source]
class wni.motor.r356.R356(address=1, dev=None, baudrate=9600)[source]

Bases: object

An R356 motor controller hooked up by USB.

Default settings (from user manual)

Function Description
Running Current (m) 25% of 3.0 Amps (0.75 Amps)
Holding Current (h) 10% of the running current
Step Resolution (j) 256x
Top Velocity (v) 305175 pps (microsteps / sec)
Acceleration (L) L = 1000, 6103500 usteps/sec^2
Position 0
Microstep Smoothness (o) 1500
Outputs (J) Both are turned off, J0, Outputs 1 & 2
Baud Rate 9600 bps
ACCELERATION = 25
ACCELERATION_RATIO = 5850
CPR = 2000
CURRENT = 40
DEGREES_PER_SECOND = 60
MICROSTEPS = 256
MOTOR_STEPS_PER_REVOLUTION = 200
REDUCTION = 40
TICKS_PER_REVOLUTION = 8000
acceleration(a)[source]

Sets the acceleration immediately.

adjust_microsteps(adjustment)[source]
baudrate(rate)[source]
current(current)[source]
degrees_per_second(dps)[source]

Define velocity in degrees per second

do(command)[source]
encoder_ratio(ratio)[source]
erase_programs()[source]
get_acceleration()[source]
get_actual_position()[source]
get_controller_status()[source]
get_current_command()[source]
get_degrees_per_second()[source]
get_encoder_position()[source]
get_firmware()[source]
get_input_values()[source]
get_int(data)[source]
get_o_value()[source]
get_position()[source]
get_requested_velocity()[source]
get_slew_speed()[source]
get_start_velocity()[source]
get_step_size()[source]
get_stop_speed()[source]
get_velocity()[source]
go_home(num_steps=2000000)[source]
hold_current(current)[source]
home(num_steps=2000000)[source]
home_sensor_polarity(p)[source]
init_settings(microsteps=None, current=None, degps=None, acc=None)[source]

Set the settings we want the radar to operate under

is_spinning
jog_distance(distance)[source]
loop(repetitions)[source]
max_velocity

The highest allowed velocity. Anything higher could cause problems.

microsteps_per_step(microsteps)[source]
mode(mode)[source]
move_to(position)[source]
negative(steps)[source]
on_off_driver(value)[source]
one_revolution_per_second

Returns the command to velocity required for doing one revolution per second

overload_timeout(timeout)[source]
pacceleration(a)[source]
padjust_microsteps(adjustment)[source]
pbaudrate(rate)[source]
pcurrent(current)[source]
pdegrees_per_second(dps)[source]

Define velocity in degrees per second

pdelay(milliseconds)[source]
pencoder_ratio(ratio)[source]
perase_programs()[source]
pexecute_program(program)[source]
pgo_home(num_steps=2000000)[source]
phalt_wait(value, pin)[source]
phold_current(current)[source]
phome(num_steps=2000000)[source]
phome_sensor_polarity(p)[source]
pjog_distance(distance)[source]
pmicrosteps_per_step(microsteps)[source]
pmode(mode)[source]
pmove_to(pos)[source]
pnegative(steps)[source]
pnew_program()[source]

This is the first function that must be called when starting a new program.

pon_off_driver(value)[source]
positive(steps)[source]
poverload_timeout(timeout)[source]
ppositive(steps)[source]
precover_encoder()[source]
prepeat_program()[source]
programmify(command)[source]

Turn the specified command into a program by prepending the “start” command and appending the “run” command. This does not actually run the program, just returns bytes that are ready to run.

prpm(desired_rpm)[source]

Sets the velocity so that the desired rpm will be achieved.

pset_accuracy(a)[source]
pset_position(pos)[source]
pskip_next_if(value, pin)[source]
pspecial_modes(mode)[source]
pspin()[source]
pstop()[source]
pstore_program(program)[source]
pvelocity(v)[source]
pzero()[source]

Sets current position to 0

read()[source]
recover_encoder()[source]
repeat_program()[source]
revolve(times=1)[source]
rpm(desired_rpm)[source]

Sets the velocity so that the desired rpm will be achieved.

run_current_program()[source]
send_number(n)[source]
set_accuracy(a)[source]
set_position(pos)[source]
special_modes(mode)[source]
spin()[source]
stop()[source]
velocity(v)[source]

Sets the velocity immediately.

write(data, append_newline=True)[source]

Write data to the motor controller

write_then_read(data)[source]
zero()[source]

Sets current position to 0

wni.motor.r356.compare(fake, real, times=80, sleep=0.1)[source]
wni.motor.r356.decode_motor_response(resp)[source]

Returns status as a string

wni.motor.r356.deg_to_ticks(degrees)[source]

Translates degrees to ticks

wni.motor.r356.fake_spin(fake, times=80, sleep=0.1)[source]
wni.motor.r356.ticks_to_deg(ticks)[source]

Translates ticks to degrees

Module contents