Skip to content

experiments.drum.motors_api

Jack Sankey edited this page Sep 2, 2020 · 6 revisions

Getting Started

mcphysics.experiments.drum.motors_api provides a scriptable interface for the Arduino in charge of moving the stepper motors in the drum experiments. To create an instance, you will first want to know which COM ports are available on your system:

import mcphysics
mcphysics.experiments.drum.list_com_ports()

This will list them all, and you can pick the arduino in charge of moving the motors (e.g. "COM5" or something), then create an instance of the motors_api with

m = mcphysics.experiments.drum.motors_api('COM5', shape='circle')

Importantly, you must specify either 'circle' or 'square', and this is used to avoid crashing the sensor into the walls clamping the plate.

Now if you type m. the auto-completion will show what options are available; you can read about how they work with the built-in help function, but here are some brief descriptions of the most important for this lab:

  • home(): Runs the radial motor and angular motors backwards (reducing radius and angle) until they hit their limit switches. Henceforth, the program will refer to this location as "zero steps" in both radius (variable name r_steps) and angle (a_steps). When you create an instance of motors_api() as above, this function is immediately called to prevent a "no knowledge" situation.
  • set_xy(), set_xy_steps(): Attempts to set the (x,y) position of the sensor in units of millimeters (set_xy()) and motor steps (set_xy_steps()). This will raise an exception if the position is not allowed.
  • set_ra(), set_ra_steps(): Attempts to set the radius and angle (r,a) coordinates of the sensor head, in units of millimeters/degrees (set_ra()) and motor steps (set_ra_steps()). Note the angular motor nominally turns the arm by one degree for every two steps. This will also raise an exception if the position is not allowed.
  • get_xy(), get_xy_steps(), get_ra(), get_ra_steps(): Returns the current location of the sensor head, as counted by the arduino.
  • is_safe_xy(), is_safe_xy_steps(), is_safe_ra(), is_safe_ra_steps(): Returns True of the supplied coordinates are safe (won't crash into the wall). This relies on you having correctly set the shape parameter when creating the instance of motors_api above. Pro-tip: you can use these functions to mask or otherwise skip coordinates that cause a problem. Ask us how!