A simple I2C library for ESCs using the Blue Robotics version of SimonK's TGY firmware (https://github.com/bluerobotics/tgy). This library supports the BlueESC, but also the Afro Nfet 30A. I2C is an alternative interface for micro-controllers, rather than using PWM (as a servo) -- this provides some additional features like temperature level, RPM, etc.

Dependents:   SimonK_I2C_ESC_Example

Example program here:

Import programSimonK_I2C_ESC_Example

Simple example for the SimonK_I2C_ESC. Tested on the FRDM K64F.

Additional guidance is provided in the Wiki

Committer:
azazeal88
Date:
Fri Apr 01 20:18:41 2016 +0000
Revision:
2:8adc426cbe31
Parent:
0:41ddae212f64
Child:
3:d74e7df56379
Updating comment documentation to Mbed style

Who changed what in which revision?

UserRevisionLine numberNew contents of line
azazeal88 2:8adc426cbe31 1 /** SimonK I2C ESC Control Library
azazeal88 0:41ddae212f64 2 ------------------------------------------------
azazeal88 0:41ddae212f64 3
azazeal88 0:41ddae212f64 4 Title: Mbed I2C ESC Library
azazeal88 0:41ddae212f64 5 Description: This library provide methods to control I2C capable ESCs
azazeal88 0:41ddae212f64 6 using the Blue Robotics fork of the tgy firmware. It's designed for the
azazeal88 0:41ddae212f64 7 "BlueESC" but will work with an tgy compatible ESC (this code was tested on the Afro nfet 30A).
azazeal88 0:41ddae212f64 8 The code is designed for the Mbed boards.
azazeal88 0:41ddae212f64 9
azazeal88 0:41ddae212f64 10 Inspired by the Arduino I2C library provided by the blue robotics team (https://github.com/bluerobotics/Arduino_I2C_ESC).
azazeal88 0:41ddae212f64 11 -------------------------------
azazeal88 0:41ddae212f64 12 The MIT License (MIT)
azazeal88 0:41ddae212f64 13 Copyright (c) 2016 Daniel Knox.
azazeal88 0:41ddae212f64 14 Permission is hereby granted, free of charge, to any person obtaining a copy
azazeal88 0:41ddae212f64 15 of this software and associated documentation files (the "Software"), to deal
azazeal88 0:41ddae212f64 16 in the Software without restriction, including without limitation the rights
azazeal88 0:41ddae212f64 17 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
azazeal88 0:41ddae212f64 18 copies of the Software, and to permit persons to whom the Software is
azazeal88 0:41ddae212f64 19 furnished to do so, subject to the following conditions:
azazeal88 0:41ddae212f64 20 The above copyright notice and this permission notice shall be included in
azazeal88 0:41ddae212f64 21 all copies or substantial portions of the Software.
azazeal88 0:41ddae212f64 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
azazeal88 0:41ddae212f64 23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
azazeal88 0:41ddae212f64 24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
azazeal88 0:41ddae212f64 25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
azazeal88 0:41ddae212f64 26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
azazeal88 0:41ddae212f64 27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
azazeal88 0:41ddae212f64 28 THE SOFTWARE.
azazeal88 0:41ddae212f64 29 -------------------------------*/
azazeal88 0:41ddae212f64 30
azazeal88 0:41ddae212f64 31 #ifndef SimonK_I2C_ESC_H
azazeal88 0:41ddae212f64 32 #define SimonK_I2C_ESC_H
azazeal88 0:41ddae212f64 33
azazeal88 0:41ddae212f64 34 #include "SimonK_I2C_ESC.h"
azazeal88 0:41ddae212f64 35
azazeal88 0:41ddae212f64 36 #define MAX_ESCS 16
azazeal88 0:41ddae212f64 37
azazeal88 0:41ddae212f64 38 // THERMISTOR SPECIFICATIONS
azazeal88 0:41ddae212f64 39 // resistance at 25 degrees C
azazeal88 0:41ddae212f64 40 #define THERMISTORNOMINAL 10000
azazeal88 0:41ddae212f64 41 // temp. for nominal resistance (almost always 25 C)
azazeal88 0:41ddae212f64 42 #define TEMPERATURENOMINAL 25
azazeal88 0:41ddae212f64 43 // The beta coefficient of the thermistor (usually 3000-4000)
azazeal88 0:41ddae212f64 44 #define BCOEFFICIENT 3900
azazeal88 0:41ddae212f64 45 // the value of the 'other' resistor
azazeal88 0:41ddae212f64 46 #define SERIESRESISTOR 3300
azazeal88 0:41ddae212f64 47
azazeal88 0:41ddae212f64 48 #include "mbed.h"
azazeal88 0:41ddae212f64 49
azazeal88 0:41ddae212f64 50 class SimonK_I2C_ESC {
azazeal88 0:41ddae212f64 51 public:
azazeal88 2:8adc426cbe31 52 /** Constructor for ESC instance. Requires input of I2C address (ESC 0,1...16 is address
azazeal88 0:41ddae212f64 53 * 0x29,0x2A...0x39). Optionally accepts pole count for RPM measurements. T100 is 6 and
azazeal88 0:41ddae212f64 54 * T200 is 7. */
azazeal88 0:41ddae212f64 55 SimonK_I2C_ESC(I2C &_i2c, char address, char poleCount = 6);
azazeal88 0:41ddae212f64 56
azazeal88 2:8adc426cbe31 57 /** Sends updated throttle setting for the motor. Throttle input range is 16 bit
azazeal88 0:41ddae212f64 58 * (-32767 to +32767). */
azazeal88 0:41ddae212f64 59 void set(short throttle);
azazeal88 0:41ddae212f64 60
azazeal88 2:8adc426cbe31 61 /** Alternate function to set throttle using standard servo pulse range (1100-1900) */
azazeal88 0:41ddae212f64 62 void setPWM(short pwm);
azazeal88 0:41ddae212f64 63
azazeal88 2:8adc426cbe31 64 /** The update function reads new data from the ESC. */
azazeal88 0:41ddae212f64 65 void update();
azazeal88 0:41ddae212f64 66
azazeal88 2:8adc426cbe31 67 /** Returns true if the ESC is connected */
azazeal88 0:41ddae212f64 68 bool isAlive();
azazeal88 0:41ddae212f64 69
azazeal88 2:8adc426cbe31 70 /** Returns voltage measured by the ESC in volts */
azazeal88 0:41ddae212f64 71 float voltage();
azazeal88 0:41ddae212f64 72
azazeal88 2:8adc426cbe31 73 /** Returns current measured by the ESC in amps */
azazeal88 0:41ddae212f64 74 float current();
azazeal88 0:41ddae212f64 75
azazeal88 2:8adc426cbe31 76 /** Returns temperature measured by the ESC in degree Celsius */
azazeal88 0:41ddae212f64 77 float temperature();
azazeal88 0:41ddae212f64 78
azazeal88 2:8adc426cbe31 79 /** Returns RPM of the motor. Note that this measurement will be
azazeal88 0:41ddae212f64 80 * more accurate if the I2C data is read slowly. */
azazeal88 0:41ddae212f64 81 short rpm();
azazeal88 0:41ddae212f64 82
azazeal88 0:41ddae212f64 83 private:
azazeal88 0:41ddae212f64 84 I2C _i2c;
azazeal88 0:41ddae212f64 85 char _address;
azazeal88 0:41ddae212f64 86 unsigned short _voltage_raw, _current_raw, _temp_raw;
azazeal88 0:41ddae212f64 87 short _rpm;
azazeal88 0:41ddae212f64 88 unsigned short _rpmTimer;
azazeal88 0:41ddae212f64 89 Timer mbed_rpm_timer;
azazeal88 0:41ddae212f64 90 char _identifier;
azazeal88 0:41ddae212f64 91 char _poleCount;
azazeal88 0:41ddae212f64 92
azazeal88 0:41ddae212f64 93 void readBuffer(char buffer[]);
azazeal88 0:41ddae212f64 94
azazeal88 0:41ddae212f64 95 void readSensors(char address, unsigned short *rpm, unsigned short *vbat, unsigned short *temp, unsigned short *curr);
azazeal88 0:41ddae212f64 96 };
azazeal88 0:41ddae212f64 97
azazeal88 0:41ddae212f64 98 #endif