8

Recently bought an Adafruit Industries board which controls stepper motors over i2c. It has a Phython library, but my code is in C++. Decided to convert the Python code to C++ to get started quickly. Behold the magic line that made everything work:

std::this_thread::sleep_for(std::chrono::milliseconds(10));

I can't believe Python's ridiculous performance is being harnessed to let the field generated by electromagnets in a stepper motor to grow to sufficient proportions to affect movement. Without the said sleep(), the stepper motor just vibrates with my C++ code. Not sure if the library was created with Python's performance in mind, or they simply didn't think about back EMF in electromagnets...

Comments
  • 3
    Your name is fuckjava, but in a roundabout way you wrote fuckpython here.

    What gives? No hate left for java?
  • 4
    You need to do timers and interrupts if you want your other code to be performant. Or you can track how long it takes between loops and make updates. Sleep will bite you later.
  • 1
    @Wisecrack Well, Java has its special place in hell but Python receives honorable mention
  • 1
    @Demolishun

    This sleep() is in the thread dealing with the stepper motor only.
  • 0
Add Comment