Giter Site home page Giter Site logo

motorlib's Introduction

motorlib

Motorlib is a library for embedded motor control. It is designed to run an actuator from a host pc in a realtime manner, where realtime refers to low latency communication to and from the actuator. The actuator runs using a field oriented control (FOC) fast loop that can operate in current or voltage mode, and a slower main loop that runs position, torque or other controllers. The loops are intended to be able to run at speeds up to 100 kHz fast loop and 10 kHz main loop when run on a 170 MHz CortexM4F microcontroller. The loops are intended to be interrupt driven such that jitter is minimized. The default communication method with the host PC is USB which has been tested to speeds up to 10 kHz. A high speed USB hub (480 Mbps) allows for 10 kHz communication to many actuators by multiplexing the data to the full speed USB (12 Mbps) microcontrollers. A diagram of the loops is shown below. loop diagram loop diagram

The main loop is intended to run several different controllers that are identified by different modes. There is a minimal amount of state related to switching controllers and the controller mode is set in the realtime packet. Therefore, the controller can generally be switched instantaneously with no intermediate state machine transition steps. The expectation is when a fault occurs, the system will be forced into safe_mode that can be configured to any of the controller mode options. In order to exit the chosen safe mode, first the host must explicitly send a clear_faults command. This will clear the fault bits and as long as faults remain cleared, the host can then transition to any other mode. A diagram of this logic is shown below. state diagram state diagram

Motorlib has support for several different sensors and driver configurations. It is designed to be statically compiled for the specific hardware configuration including microcontroller, sensors, driver, and communication method. It is configured by means of the headers that you include and by typedefs. For example the MainLoop requires a MotorEncoder to operate. If your motor encoder is of type MA732Encoder you would configure as follows:

#include "ma732_encoder.h"
using MotorEncoder = MA732Encoder;
#include "main_loop.h"

Prior to settling on static/typedef configuration I considered several means for configuration including virtual functions and templates. Virtual functions tended to cause difficulty with execution speed and also added difficulty to optimization. A key embedded optimization is to place the fast loop in a specific place in memory called CCM_RAM. By using headers to configure, only one memory section statement is required. This approach avoids template programming with a static/typedef approach, which trades-off some boiler-plate coding with a simpler, more readable, and easier to debug approach for easy configurability and maintainability.

Examples using this library are found in the adjacent obot-controller repository.

Install/setup

The preferred compiler is gcc for the arm-none-eabi 32-bit target. The following shell script will download and install the compiler to a ./gcc sub-directory of the motorlib repo:

scripts/install_gcc.sh

The included build script configure_gcc.mk uses the default compiler location from the installation script.

motorlib's People

Contributors

bingjeff avatar leemagnusson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.