-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathVescUart.h
125 lines (91 loc) · 4.41 KB
/
VescUart.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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