CAN communication
Software » CAN communication
The Revision 2 main board supports CAN communication. The CAN bus can be used for configuration and for obtaining values like voltages, input states etc. The CAN messages are configurable and can be adjusted to be compatible with existing equipment.
Since firmware 3.75 throttle and digital inputs can be controlled via CAN.
Controlling throttle via CAN
If you want to send the throttle and regen magnitude commands via CAN rather then via analog inputs you have to set "potmode" to "CAN" (=2). Next you have to map a CAN message to pot and optionally pot2. So say you have a digital throttle that sends values from 0 to 1000 for 0 to 100% travel on CAN-Id 100 in the first two bytes.
- Configure potmin=0 and potmax=1000
- Map CAN message to pot: can rx pot 100 0 16 32
The last parameter, 32, tells the CAN module to apply the internal fixed point scaling.
CAN messages must be received every 500ms, otherwise throttle times out and is set to 0.
Controlling Digital IO via CAN
6 signals, namely cruise, start, brake, forward, backward and bms can be controlled via CAN. The CAN message is ORed to the physical inputs so you can have mixed signals also. Digital CAN IO doesn't need to be explicitely configured, it works as soon as you map a CAN message to "canio". "canio" is bit-encoded:
- Bit 0: cruise
- Bit 1: start
- Bit 2: brake
- Bit 3: forward
- Bit 4: reverse
- Bit 5: bms
So say you have a BMS that transmits an over/under voltage bit on CAN Id 200, 2nd data bit
can rx canio 200 2 1 1024
Note the 1024x gain that shifts the bit into the correct position (5 fraction bits plus 5th data bit). In this case all other IOs remain traditional, only BMS is controlled via CAN. Note that you cannot map multiple CAN messages onto "canio" as they would overwrite each other.
If you have a managed to mangle all 5 bits into one message, say CAN Id 300, first 5 bits the mapping is done like so
can rx canio 300 0 5 32
The same timeout mechanism is used as for throttle control, so after 500ms with no message the CAN-mapped inputs are assumed off. Traditional inputs remain unaffected.
Setting and reading parameters via SDO
The abbreviation SDO is taken from the CANOpen protocol. It assigns a certain meaning to the 8 data bits of a CAN frame.
Purpose | CAN-Id | Byte 1 (Cmd) | Bytes 2-3 (Index) | Byte 4 (Subindex) | Bytes 5-8 (Data) |
---|---|---|---|---|---|
Set Value | 0x601 | 0x40 | 0x2000 | Value Index | Value x 32 |
Set Value Reply | 0x581 | 0x23 | 0x2000 | Value Index | Value x 32 |
Get Value | 0x601 | 0x22 | 0x2000 | Value Index | don't care |
Get Value Reply | 0x581 | 0x43 | 0x2000 | Value Index | Value x 32 |
Abort - invalid index | 0x581 | 0x80 | 0x2000 | Value Index | Abort Code = 0x06020000 |
Abort - value out of range | 0x581 | 0x80 | 0x2000 | Value Index | Abort Code = 0x06090030 |
The value index must be determined by counting the output of the list command. E.g. "boost" at the very top has index 0, potnom has index 77. The indexes can change over firmware versions as new parameters are added somewhere in between.
Mapping values to arbitrary CAN messages
Values can be mapped into a certain bit range of the 64 payload bits of a CAN message. They can either be read from the message or sent via a message. To do so enter
can tx udc 123 0 16 10
This maps the value of udc to a CAN message with id 123 bits 0..15 (start at bit 0, span over 16 bits) with a gain of 10.
can tx din_forward 123 24 1 1
would map the pin state of the forward input to bit 24 of CAN message with id 123
To save your can map simply type "save".
To clear you can map type "can clear".
Limits
- A maximum of 10 messages can be defined
- Per message a maximum of 8 values can be mapped
- a value can not span across the 32-bit boundary, i.e. it must be fully contained in the first or second 32 bits of the message. E.g. "can tx udc 123 16 32 10" is not allowed
- A value can span maximum 32 bits