-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add library for communication with the motor controller (#8)
This commit also adds a "fake" implementation of the required UART abstraction needed by the third party library. That is, an implementation that has the correct API for building with, but that won't be useful at runtime. Additionally, this commit adds support for making `clang-format` ignore specified directories, and then proceeds to make it ignore the third-party vesc-uart library. This commit also updates `clang-tidy` so that system include are correctly ordered when using `--spawn_strategy=local`. Change-Id: I350bf62912454d7b815a9dedcc048a63c2107c46
- Loading branch information
Showing
20 changed files
with
1,479 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Third party code | ||
================ | ||
This directory contains a collection of third party code that is being checked | ||
into this repository rather than downloaded as dependencies referenced in the | ||
WORKSPACE file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Checks: > | ||
-*, | ||
# dummy, see below, | ||
misc-definitions-in-headers, | ||
CheckOptions: | ||
- key: HeaderFileExtensions | ||
value: "x" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
||
cc_library( | ||
name = "vesc_uart", | ||
srcs = [ | ||
"src/VescUart.cpp", | ||
"src/buffer.cpp", | ||
"src/compatability/WProgram.h", | ||
"src/crc.cpp", | ||
"src/includes/buffer.h", | ||
"src/includes/crc.h", | ||
"src/includes/datatypes.h", | ||
"src/includes/local_datatypes.h", | ||
], | ||
hdrs = ["VescUart.h"], | ||
copts = [ | ||
"-Wno-conversion", | ||
"-Wno-double-promotion", | ||
"-Wno-old-style-cast", | ||
"-Wno-unused-but-set-parameter", | ||
"-xc++", | ||
], | ||
includes = [ | ||
".", | ||
"src/compatability", | ||
"src/includes", | ||
], | ||
visibility = ["//:__subpackages__"], | ||
deps = [ | ||
"//uart_abstraction:fake", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Interface library for UART interaction with the VESC motor controller | ||
===================================================================== | ||
The library has a high-level API for sending commands to the motor controller. | ||
It requires a UART abstraction library with the following API in order to | ||
build. | ||
|
||
```cpp | ||
// HardwareSerial.hpp | ||
|
||
struct HardwareSerial { | ||
auto available() const -> bool; | ||
|
||
auto read() const -> std::uint8_t; | ||
|
||
auto write(std::uint8_t* buffer, std::size_t size) const -> void; | ||
}; | ||
``` | ||
A global variable named `Serial` of the above type has to be provided when | ||
linking the code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
Copyright 2015 - 2017 Andreas Chaitidis [email protected] | ||
This program is free software : you can redistribute it and / or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program.If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef _VESCUART_h | ||
#define _VESCUART_h | ||
|
||
//#include "Config.h" | ||
|
||
/*TThis library was created on an Adruinio 2560 with different serial ports to have a better possibility | ||
to debug. The serial ports are define with #define: | ||
#define SERIALIO Serial1 for the UART port to VESC | ||
#define DEBUGSERIAL Serial for debuging over USB | ||
So you need here to define the right serial port for your arduino. | ||
If you want to use debug, uncomment DEBUGSERIAL and define a port.*/ | ||
|
||
|
||
#ifndef _CONFIG_h | ||
|
||
#ifdef __AVR_ATmega2560__ | ||
#define SERIALIO Serial1 | ||
#define SERIALIO2 Serial2 | ||
#define SERIALIO3 Serial3 | ||
#define DEBUGSERIAL Serial | ||
#endif | ||
|
||
#ifdef ARDUINO_AVR_NANO | ||
#define SERIALIO Serial | ||
#define DEBUGSERIAL Serial | ||
#endif | ||
#endif | ||
|
||
#if defined(ARDUINO) && ARDUINO >= 100 | ||
#include "Arduino.h" | ||
#else | ||
#include "WProgram.h" | ||
#endif | ||
|
||
#include "datatypes.h" | ||
#include "local_datatypes.h" | ||
///PackSendPayload Packs the payload and sends it over Serial. | ||
///Define in a Config.h a SERIAL with the Serial in Arduino Style you want to you | ||
///@param: payload as the payload [unit8_t Array] with length of int lenPayload | ||
///@return the number of bytes send | ||
|
||
int PackSendPayload(uint8_t* payload, int lenPay, int num); | ||
|
||
///ReceiveUartMessage receives the a message over Serial | ||
///Define in a Config.h a SERIAL with the Serial in Arduino Style you want to you | ||
///@parm the payload as the payload [unit8_t Array] | ||
///@return the number of bytes receeived within the payload | ||
|
||
int ReceiveUartMessage(uint8_t* payloadReceived, int num); | ||
|
||
///Help Function to print struct bldcMeasure over Serial for Debug | ||
///Define in a Config.h the DEBUGSERIAL you want to use | ||
|
||
void SerialPrint(const struct bldcMeasure& values); | ||
|
||
///Help Function to print uint8_t array over Serial for Debug | ||
///Define in a Config.h the DEBUGSERIAL you want to use | ||
|
||
void SerialPrint(uint8_t* data, int len); | ||
|
||
///Sends a command to VESC and stores the returned data | ||
///@param bldcMeasure struct with received data | ||
//@return true if success | ||
bool VescUartGetValue(struct bldcMeasure& values, int num); | ||
bool VescUartGetValue(bldcMeasure& values); | ||
|
||
///Sends a command to VESC to control the motor current | ||
///@param current as float with the current for the motor | ||
///@param num as integer with the serial port in use (0=Serial; 1=Serial1; 2=Serial2; 3=Serial3;) | ||
|
||
void VescUartSetCurrent(float current, int num); | ||
void VescUartSetCurrent(float current); | ||
|
||
///Sends a command to VESC to control the motor brake | ||
///@param breakCurrent as float with the current for the brake | ||
///@param num as integer with the serial port in use (0=Serial; 1=Serial1; 2=Serial2; 3=Serial3;) | ||
|
||
void VescUartSetCurrentBrake(float brakeCurrent, int num); | ||
void VescUartSetCurrentBrake(float brakeCurrent); | ||
|
||
///Sends values of a joystick and 2 buttons to VESC to control the nunchuk app | ||
|
||
void VescUartSetNunchukValues(remotePackage& data, int num); | ||
void VescUartSetNunchukValues(remotePackage& data); | ||
|
||
///Sends a command to VESC to control the motor position | ||
///@param position as float with the position in degrees for the motor | ||
///@param num as integer with the serial port in use (0=Serial; 1=Serial1; 2=Serial2; 3=Serial3;) | ||
|
||
void VescUartSetPosition(float position, int num) ; | ||
void VescUartSetPosition(float position) ; | ||
|
||
///Sends a command to VESC to control the motor duty cycle | ||
///@param duty as float with the duty cycle for the motor | ||
///@param num as integer with the serial port in use (0=Serial; 1=Serial1; 2=Serial2; 3=Serial3;) | ||
|
||
void VescUartSetDuty(float duty, int num) ; | ||
void VescUartSetDuty(float duty) ; | ||
|
||
///Sends a command to VESC to control the motor rotational speed | ||
///@param rpm as float with the revolutions per second for the motor | ||
///@param num as integer with the serial port in use (0=Serial; 1=Serial1; 2=Serial2; 3=Serial3;) | ||
|
||
void VescUartSetRPM(float rpm, int num); | ||
void VescUartSetRPM(float rpm); | ||
|
||
#endif |
Oops, something went wrong.