rollinggecko / vescuartcontrol Goto Github PK
View Code? Open in Web Editor NEWArduino library to interface with the VESC bldc over UART.
License: Other
Arduino library to interface with the VESC bldc over UART.
License: Other
Hello,
I was trying to use your new UART VESC 6 library and I can't figure out how to simply just pull the rpm member out of the struct. I read that something like Serial.println(measuredVal.rpm); should work but all I keep getting returned is 0.
Any idea what the issue is?
Now that the VESC6 is in Beta, the new VESC-Tool is out (Beta) and it includes new and improved firmware for the VESC4's. According to Vedder this new firmware requires some changes to UART. Can this library be modified to accommodate these changes? Or perhaps a new VescUartControl version is needed? Here is the summary (from Vedder) of what's required for the new firmware to work with VescUartControl:
"
The SetRpm and SetCurrent commands should work as before, but the GetValue command probably has to be updated. This is the way the values are sent in the latest firmware:
case COMM_GET_VALUES:
ind = 0;
send_buffer[ind++] = COMM_GET_VALUES;
buffer_append_float16(send_buffer, mc_interface_temp_fet_filtered(), 1e1, &ind);
buffer_append_float16(send_buffer, mc_interface_temp_motor_filtered(), 1e1, &ind);
buffer_append_float32(send_buffer, mc_interface_read_reset_avg_motor_current(), 1e2, &ind);
buffer_append_float32(send_buffer, mc_interface_read_reset_avg_input_current(), 1e2, &ind);
buffer_append_float32(send_buffer, mc_interface_read_reset_avg_id(), 1e2, &ind);
buffer_append_float32(send_buffer, mc_interface_read_reset_avg_iq(), 1e2, &ind);
buffer_append_float16(send_buffer, mc_interface_get_duty_cycle_now(), 1e3, &ind);
buffer_append_float32(send_buffer, mc_interface_get_rpm(), 1e0, &ind);
buffer_append_float16(send_buffer, GET_INPUT_VOLTAGE(), 1e1, &ind);
buffer_append_float32(send_buffer, mc_interface_get_amp_hours(false), 1e4, &ind);
buffer_append_float32(send_buffer, mc_interface_get_amp_hours_charged(false), 1e4, &ind);
buffer_append_float32(send_buffer, mc_interface_get_watt_hours(false), 1e4, &ind);
buffer_append_float32(send_buffer, mc_interface_get_watt_hours_charged(false), 1e4, &ind);
buffer_append_int32(send_buffer, mc_interface_get_tachometer_value(false), &ind);
buffer_append_int32(send_buffer, mc_interface_get_tachometer_abs_value(false), &ind);
send_buffer[ind++] = mc_interface_get_fault();
commands_send_packet(send_buffer, ind);
break;
"
Hi there, my name is Jessica.
I was wondering if anyone can provide me with some assistance. I made various endeavors to run the correct code given by RollingGrecko that allows my Arduino to communicate with my Vesc (Firmware V3.28 ) through UART. I managed to get my Arduino Mega working on a Vesc Firmware V3.28 by receiving information from my Vesc using UART. However for some odd reason, I am unable to get RollingGrecko's code to work on my Teensy 3.6.
This is the Error that I have received on my teensy 3.6(Seen below)
After hours of research, I have notice that the Teensy 3.6 runs a different processor than the Arduino Mega.
Can someone verify if they are having the same problem when using a Teensy 3.6??
Furthermore, any help with getting my Teensy 3.6 to work through UART with the new Firmware V3.28 is
greatly appreciated.
Thank you,
Sincerely
Jess :)
Hi,
I'm trying to get your code working with the ESP32, but I'm having this error:
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'int ReceiveUartMessage(uint8_t*)':
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:36:9: error: 'SERIALIO' was not declared in this scope
while (SERIALIO.available()) {
^
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'int PackSendPayload(uint8_t*, int)':
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:139:21: warning: converting to non-pointer type 'uint8_t {aka unsigned char}' from NULL [-Wconversion-null]
messageSend[count] = NULL;
^
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:147:2: error: 'SERIALIO' was not declared in this scope
SERIALIO.write(messageSend, count);
^
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'void SerialPrint(uint8_t*, int)':
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:253:3: error: 'DEBUGSERIAL' was not declared in this scope
DEBUGSERIAL.print(data[i]);
^
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:256:2: error: 'DEBUGSERIAL' was not declared in this scope
DEBUGSERIAL.println("");
^
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp: In function 'void SerialPrint(const bldcMeasure&)':
\\hrzfs01.hrz.isc.fh-kiel.de\home_st$\selnvett\Arduino\libraries\VescUartControl-master\VescUart.cpp:261:2: error: 'DEBUGSERIAL' was not declared in this scope
DEBUGSERIAL.print("avgMotorCurrent: "); DEBUGSERIAL.println(values.avgMotorCurrent);
This is my code:
/*
Name: VescUartSample.ino
Created: 9/26/2015 10:12:38 PM
Author: AC
*/
// the setup function runs once when you press reset or power the board
// To use VescUartControl stand alone you need to define a config.h file, that should contain the Serial or you have to comment the line
// #include Config.h out in VescUart.h
//Include libraries copied from VESC
#include "VescUart.h"
#include "datatypes.h"
#include <HardwareSerial.h>
HardwareSerial Serial1(1);
#define DEBUG
unsigned long count;
void setup() {
//Setup UART port
Serial1.begin(115200, SERIAL_8N1, 16, 17);
#ifdef DEBUG
//SEtup debug port
Serial.begin(115200);
#endif
}
struct bldcMeasure measuredValues;
// the loop function runs over and over again until power down or reset
void loop() {
//int len=0;
//len = ReceiveUartMessage(message);
//if (len > 0)
//{
// len = PackSendPayload(message, len);
// len = 0;
//}
if (VescUartGetValue(measuredValues)) {
Serial.print("Loop: "); Serial.println(count++);
SerialPrint(measuredValues);
}
else
{
Serial.println("Failed to get data!");
}
}
Do you have ideas? Your help is very much appreciated!
Hello.
Now, I'm interested in control the position of the motor.
I would like to know how the function setPosition is performed:
-it is possible without any hall sensor?
-it is possible to use one analog hall sensor (voltage proportional to angle) instead of three digital hall sensors.
I would like to know the meaning of the variable position, that is, this variable indicates how many degrees the motor rotates?
I can only imagine I must be wiring it wrong. I'm using a mega, with a 4.10 vesc running 2.16.
I have uart selected as the mode and baud rate is 115200 on the vesc.
I have vesc Rx -> Tx1 and vesc Tx -> Rx1. Serial 1 in the code also has a baud rate of 115200, to match the VESC's uart baud rate.
Just trying to run the example code. But I never get a connection. Just "Failed to get data!" over and over.
Do I need to wire anything else from the vesc uart? Can't understand why this won't work other wise.
Hello,
Has any one used this library to be able to change to maximum duty cycle, i ve been looking into this for the last month, but i was not able to success in doing it.
Apparently it should start from this function and go on : confgenerator_serialize_mcconf
But i ve been having problems passing the whole buffer or even jst part of it and every time t does not work.
It seems that using SoftwareSerial to communicate with the VESC doesn't work. It would be great to get this working so that we can use the HardwareSerial for usb while connected to the VESC.
I can not seem to figure out how to implement the use of SoftwareSerial instead of Serial1, is this even possible?
Hello,
Is it possible to include the VESC command "COMM_GET_MCCONF"? I tried it myself but get stuck at the comamnd "//ToDo: Add Message Handling > 255 (starting with 3)" from your "switch (messageReceived[0])".
Thank you very much.
Hi,
I'm wondering if it is possible to get VESC temperature and raw ppm information via VescUart Library.
Another question: is it possible to get the datas from a second VESC connected to the first one through CAN?
I mean:
VESC1 (CAN id 0) ===can=== VESC2 (CAN id 1) ===uart=== ARDUINO
Thank you by advance for the answers.
Hi,
First off. Thank you so much for this code. A huge help!
On line 49 of VescUart.cpp, you put //ToDo: Add Message Handling > 255 (starting with 3). I'm trying to read the mcconfig, which returns the starting byte of 3 (since the payload is > 255). As a result, my code goes into case 3, which has this todo marker, and fails.
I've been trying for the last few days to complete this code using all of the documentation given by you and vedder about the communication. With a simple get firmware command, I can see exactly what's going on (I get 2, 3, 0, 2, 18, 84, 17, 3), but with the mcconfig, I get (3, 1, 26, 1, 0, ect... 3). My understanding is, you have start byte of 2, so short packet, packet length of 3, so next 3 bytes for the packet body, then 84 and 17 are the checksum, and finally, 3 is the stop byte. I don't see this pattern because I get the 3 is the start byte, so we should have a long packet body with length 1 + 26 so 27. Not over 255, so why would it be a 3?
Could you either assist me in completing this part of the code or complete it?
Quite a few people are using your code and it's a bummer that it can't do a simple get mc config command.
Thank you
Luke
Hi there @RollingGecko
Have been searching for some code that has this function implemented so I can use it in the arduino, but so far without success. I don't know what are the transformations required in the messages to actually send such command, using the libraries that are currently created.
The idea here was to sent commands to a slave vesc, for instance, setting RPM's. I've tested the CAN master-slave communication through VESC tool and is working well. It is just the code adaptation in c++ that I have no idea how to perform. I don't even know how is supposed to work with such function, while sending a command.
I would appreciate the help of anyone who reads this. Have a nice day!
Hi,
I merged the updates to bldc fw 3.29 know with new functions and multi serial port support from the pull requests. Interface changed. Know the serial port must be initialized. Know the interface is much cleaner.
But I've know hardware to test the changes. Is somebody willing to test it before I merge it to the master??
Changes are in this branch: https://github.com/RollingGecko/VescUartControl/tree/VESC6
Please excuse the lack of knowledge.
I've been trying to program an Arduino controller for a Vesc V4 and I'm getting the following error.
I have tried to re-install the library sever times as well as uploading some of the example sketches from the Vesc UART library, and keep getting the aforementioned error on the IDE console.
Any input/help would be of great help. Thanks
Arduino: 1.8.15 (Linux), Board: "Arduino Nano, ATmega328P"
getVescValues:12:1: error: 'VescUart' does not name a type; did you mean 'getchar'?
VescUart UART;
^~~~~~~~
getchar
/home/thinkpad/Arduino/VescUart/examples/getVescValues/getVescValues.ino: In function 'void setup()':
getVescValues:20:3: error: 'Serial1' was not declared in this scope
Serial1.begin(19200);
^~~~~~~
/home/thinkpad/Arduino/VescUart/examples/getVescValues/getVescValues.ino:20:3: note: suggested alternative: 'Serial'
Serial1.begin(19200);
^~~~~~~
Serial
getVescValues:25:3: error: 'UART' was not declared in this scope
UART.setSerialPort(&Serial1);
^~~~
/home/thinkpad/Arduino/VescUart/examples/getVescValues/getVescValues.ino:25:3: note: suggested alternative: 'UDR0'
UART.setSerialPort(&Serial1);
^~~~
UDR0
/home/thinkpad/Arduino/VescUart/examples/getVescValues/getVescValues.ino: In function 'void loop()':
getVescValues:31:8: error: 'UART' was not declared in this scope
if ( UART.getVescValues() ) {
^~~~
/home/thinkpad/Arduino/VescUart/examples/getVescValues/getVescValues.ino:31:8: note: suggested alternative: 'UDR0'
if ( UART.getVescValues() ) {
^~~~
UDR0
exit status 1
'VescUart' does not name a type; did you mean 'getchar'?
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
fw 3.28 is out with the new vesc-tool and it breaks this library. I am going to try and debug it and if i get it working i'll mention it here, but it would be nice to have this working.
right now it is returning messages of length 54, which i'm guessing is some default response considering you're checking for len >55, but haven't gotten as far as to reading the messages.
I am getting an error after including the library into a sketch.
printf.h:28:29: error: 'fdevopen' was not declared in this scope fdevopen( &serial_putc, 0 );
Hi,
I made a fresh install on another computer than the usual one that don't have any issue while compiling.
Arduino IDE 1.8.5
VescUartControl VESC6 branch library (latest version on Github).
Compiler window of Arduino IDE :
xxxxxx\Documents\Arduino\libraries\VescUartControl\VescUart.cpp: In function 'int PackSendPayload(uint8_t*, int, int)':
xxxxxx\Documents\Arduino\libraries\VescUartControl\VescUart.cpp:188:21: warning: converting to non-pointer type 'uint8_t {aka unsigned char}' from NULL [-Wconversion-null]
messageSend[count] = NULL;
^
Sketch uses 11462 bytes (37%) of program storage space. Maximum is 30720 bytes.
Global variables use 981 bytes (47%) of dynamic memory, leaving 1067 bytes for local variables. Maximum is 2048 bytes.
For example - COMM_GET_VALUES in fw 3.55+ returns 65 bytes of data.
This code expects 54 bytes.
The crc etc will of course no longer work...
Hi,
I have been trying to use your library, with an Arduino Nano. However, I can't debug the output, while the Arduino is connected to a VESC over the hardware serial port. Is it possible to use SoftwareSerial as a means of debugging on a Nano, connecting the SoftwareSerial port to a USB to a serial device?
I have tried modifying your library, so that your VescUart.h defines DEBUGSERIAL as a SoftwareSerial, however without success.
Not quite sure what I am doing wrong, but I downloaded the zip, unpacked into the libraries folder. Then I tried to run the VescUartSample.ino file in the samples folder. But this is the error I get. I have the right board selected (uno) and the right port selected.
Any ideas or advice on getting started with this library?
Running from ubuntu 16.04 in the off-line IDE enviroment.
Is there any way to get this to work on Arduino Uno? I don't have a Mega or Nano.
Have been trying to edit the code to make it compatible for Uno but it doesn't seem to work.
Hey can someone please explain me why i can virtify the program but when i upload the error
"
An error occurred while uploading the sketch Invalid library found in C:\Users\Simon Voss\Documents\Arduino\libraries\test: no headers files (.h)
"
comes up but no error is shown until I try to upload the programming
regards
Simon
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.