Hi!
I'm new to VESC and have some troubles to get the right data when using PYVESC over UART. When I loop thru the GET_VALUE response package I get ok variable names but the data seems wrong. Could some one please make sense out of this?!
{'measurement': 'temp_mos1', 'fields': {'value': 27.0}}
{'measurement': 'watt_hours_charged', 'fields': {'value': 6.5535}}
{'measurement': 'temp_mos6', 'fields': {'value': 2.7}}
{'measurement': 'mc_fault_code', 'fields': {'value': b'B'}}
{'measurement': 'temp_mos5', 'fields': {'value': 0.0}}
{'measurement': 'amp_hours', 'fields': {'value': 117.9648}}
{'measurement': 'current_motor', 'fields': {'value': 655.35}}
{'measurement': 'temp_mos2', 'fields': {'value': -85.6}}
{'measurement': 'tachometer_abs', 'fields': {'value': 1661796352.0}}
{'measurement': 'tachometer', 'fields': {'value': -739835904.0}}
{'measurement': 'temp_mos3', 'fields': {'value': 0.0}}
{'measurement': 'temp_mos4', 'fields': {'value': 7.4}}
{'measurement': 'amp_hours_charged', 'fields': {'value': 0.0}}
{'measurement': 'v_in', 'fields': {'value': 0.0}}
{'measurement': 'current_in', 'fields': {'value': -47845.52}}
{'measurement': 'temp_pcb', 'fields': {'value': 0.0}}
{'measurement': 'rpm', 'fields': {'value': -249364175.0}}
{'measurement': 'duty_now', 'fields': {'value': -0.001}}
{'measurement': 'watt_hours', 'fields': {'value': 3722.4448}}
while True:
# Request the current measurement from the vesc
ser.write(pyvesc.encode_request(GetValues))
# Check if there is enough data back for a measurement
if ser.in_waiting > 63:
(response, consumed) = pyvesc.decode(ser.read(63))
packets = []
for sensor, value in response.__dict__.items():
data = {}
data['measurement'] = sensor
data['fields'] = {}
data['fields']['value'] = value
packets.append(data)
print(data)
Cheers
Göran Jonasson
In the VESC6 firmware the read response seem to have changed, in case the question is related to that.
see https://github.com/vedderb/bldc/blob/master/commands.c
Thanks for the info!
I have sorted out the most important signal mapping now. Some from looking at the commands.c but the rest had to be reverse engineered. I don´t fully understand how the message is created and how the variables end up in a certain order in the message?!
This is from my source code. You have the packet structure and above buffer_append_.... fill the payload.
Note: As any network code it is MSB-first.
To get the actual decimal value you have to divide by the factor, e.g. v_in_10 might have the int16_t value of 113, divided by 10 returns the correct 11.3Volt.
That is how far I got. It is working though.
https://github.com/wernerdaehn/CC3D-CableCam-Controller/blob/master/inc/...
https://github.com/wernerdaehn/CC3D-CableCam-Controller/blob/master/src/...
@whdaehn In that list of bytes your sending the first 01 1a after com_get_values' 04 is that for getting the temp_fet value to be sent back from the vesc? So include the corresponding byte in the payload from that struct you have there to get a desired value back? or will a raw data set automatically be sent back if just 04 is sent as the payload? I'm having trouble getting a response from the VESC and this it may be an incorrect request on my part. Your detailed source code is sort of clearing things up.
Thanks
The com_get_values command requests all values. You cannot tell which parts to return, it returns the full data. Hence I load that into that struct and then I pick the variable I want.
You got the point that above example lists the response only, not what I am sending.
Does that answer it?
Yes, that was my interpretation of how it works. I am sending 02 01 04 40 84 03 but am not getting anything back form the VESC when checking my receive buffer. Any thoughts?
Looks good, checksum I can't tell. The only idea I have is big endian/little endian. Can you send 02 01 04 84 40 03 (CRC bytes swapped) for a test? The VESC does not respond if anything is wrong, hence we don't know what it is. Could also be hardware, TX versus RX, VESC configuration (Uart activated??)...
UPDATE: The packet I am sending was correct and I receive a similar 58 byte packet back to what ou posted above. My receive buffer was/is not triggering correctly but from the VESC end it is transmitting perfectly. I have an arduino piggy backing on the tx so I can see the output and the problem is rx on my nxp board. Thanks for the guidance.
Hey @whdaehn, another follow up question regarding the UART.
The packets that are Tx from the VESC end with a 3, but do they contain a \0 \r or \n after that? I cannot pick up either and can only catch the com values correctly when hardcoding my buffer to stop at 63 bytes (58 payload plus the 5 info bytes), this does work fine but the same would have to be done with each other get command individually.
Can it be confirmed there are no interrupting chars sent after the stop byte, or am I just missing them somehow?
Also I'm looking to use the set_rpm command for control of my motor, I should be able to set 12000 rpm for example and if correctly tuned the vesc should vary its amperage to hold that value correct?
Thanks
This is all binary communication. So no \r \n or \0 chars are being sent. (At least I am not aware of and I have not noticed any.)
My logic is primarily timing driven:
The point is, the VESC never sends any data unless you request it by sending a command. So as long as you are not sending commands faster than 500ms, above works. And many commands like the set_rpm do not return anything even.
Above logic should cope with all issues like an accidental correct byte due to noise, data loss and the such.
Regarding your second point., yes, I control the VESC with rpm commands as well (with the exception of rpm=0, which I translate into brake_current and handbrake commands for now. Still testing though.). There is an enhancement request to let the VESC handle rpm=0 as well, so it should do everything that is needed to stop and stay at speed=0. Would appreciate if you would support this request by raising your voice there. http://vesc-project.com/node/146
Hello,
I tried to get all the data from VESC 6.0 too. I am getting no good data at all. However I can set RPM and duty cycles.
Can you please tell me what should I change in PyVESC files?
Thanks
Thanks for the information wdaehn. I updated pyvesc/messages/getters.py and now the GetValues message appears to be working. I don't use all the other messages though, so they may still need tweaking.
To update pyvesc, in getters.py in the GetValues class, change "fields" to the following:
PS, i've been using these new values on Firmware 3.4, and it's been working well for me too. Should get updated in the github repo.