Dynam Labs VCU+ Plugin Reference Manual
March 22, 2026
Firmware Version 2.0.13
Overview
Plugins enable users to add custom functionality to the VCU+ while keeping its core firmware lightweight and efficient. By allowing customization without modifying the core, plugins ensure the system remains maintainable and adaptable to a wide range of application-specific needs.
With plugins, users can implement tailored features, such as custom control algorithms or data processing workflows, without the overhead of embedding these directly into the core firmware. This flexibility empowers users to quickly adapt the VCU to their unique requirements.
This reference manual provides a comprehensive guide to using plugins, including an overview of available functions, configuration options, and instructions for writing, testing, and deploying custom Lua-based logic.
The plugin language is Lua, chosen for its simplicity, low learning curve, and lightweight nature. Lua is widely regarded for its ease of integration into embedded systems and its ability to execute scripts efficiently, making it ideal for the resource-constrained environment of the VCU+. Its straightforward syntax and minimal setup allow both novice and experienced developers to quickly write and test custom logic.
For more information about Lua, refer to the official documentation:
This reference manual provides a comprehensive guide to using plugins, including an overview of available functions, configuration options, and instructions for writing, testing, and deploying custom Lua-based logic.
Core Loop
The core logic of a plugin is implemented within the onTick() function. This function is automatically called by the VCU at a fixed interval, serving as the main loop for your script. All continuous tasks, such as reading sensors, making decisions, and controlling outputs, should be placed within this function.
onTick()
This function is called repeatedly by the VCU firmware. Implement your main control logic inside this function.
Example Use Case:Continuously monitoring battery temperature and activating a cooling fan if it exceeds a threshold.
-- This function will be called on every tick of the plugin execution cycle
function onTick()
local temp = getSensor(BatteryTemp)
if temp > 80 then
setOut(HS1) -- Turn on cooling fan
else
clearOut(HS1) -- Turn off cooling fan
end
endonSleep()
This optional callback is called by the VCU just before the device enters sleep mode. Use it to perform any necessary cleanup, save state, or send a final CAN message before power is removed. The VCU waits for this function to complete before proceeding with the sleep sequence.
Example Use Case:Sending a final CAN message or saving state before the VCU goes to sleep.
function onSleep()
sendCAN(CAN2, 0x7FF, {0x00}) -- notify other devices we're going to sleep
endFunctions
The following is a list of all currently supported functions available for use in plugins. These functions form the building blocks for creating powerful and highly customized logic within your plugins, giving you full control over VCU outputs, sensor data, communication, and control algorithms. The list is continuously growing as more functions are added.
setOut(pin)
This function sets the specified output pin to its active state:
- High-Side Outputs: The pin transitions to a high state (voltage applied).
- Low-Side Outputs: The pin transitions to a low state (connected to ground).
Activating a high-side output pin to power a relay or a low-side output pin for devices requiring a ground-side switch.
-- Activate a high-side output 1
setOut(HS1)
-- Activate a low-side output 2
setOut(LS2)clearOut(pin)
This function clears the specified output pin, setting it to its inactive state:
- High-Side Outputs: The pin transitions to a low state (voltage removed).
- Low-Side Outputs: The pin transitions to a high state (disconnected from ground).
Deactivating a relay or turning off a light connected to the VCU.
-- Deactivate the high-side output 1
clearOut(HS1)
-- Deactivate the low-side output 2
clearOut(LS2)getSensor(sensorID)
Retrieves the current value of the specified sensor. This allows the plugin to access real-time data, such as temperature, a speed, or pressure. Returns nil if the sensor state is invalid. Always check the return value before performing arithmetic operations. The return value is always a floating point number, so it must be rounded or converted to an integer before using it in bitwise operations.
Example Use Case:Reading a temperature sensor value for dynamic control logic.
List of available Sensors:
AcceleratorPedalAcceleratorPedalPrimaryAcceleratorPedalSecondaryBatteryCurrentBatteryVoltageBatteryTempBatteryChargeInverterCurrDI_inverterTempDI_statorTempDI_heatSinkTempDI_inletTempDIS_inverterTempDIS_statorTempDIS_heatSinkTempDIS_inletTempTemp1Temp2Temp3Temp4
RPMRPMPrimaryRPMSecondaryDin1Din2Din3Din4Din5Din6Din7Din8Din9Din10Din11Din12Din13Din14Din15DinNoneLVBatt
CAN_KEYPAD_B1CAN_KEYPAD_B2CAN_KEYPAD_B3CAN_KEYPAD_B4CAN_KEYPAD_B5CAN_KEYPAD_B6CAN_KEYPAD_B7CAN_KEYPAD_B8IgnitionAin1Ain2Ain3Ain4Ain5Ain6Ain7Ain8Gear
-- Retrieve the value from Temperature sensor 1
local temperature = getSensor(Temp1)
-- Retrieve Accelerator pedal value and use it in logic
local pedal = getSensor(AcceleratorPedal)sendCAN(canBus, canID, data)
Sends a CAN message with the specified ID and data payload. Enables communication with other devices on the CAN bus.
Note: Only CAN2 and CAN3 are supported. Calls with CAN1 are silently ignored.
canBus: The physical bus to send the message on. (CAN2 or CAN3 only)canID: The identifier of the CAN message.data: The payload, a byte array of up to 8 bytes.
Sending commands to external controllers or reporting custom data.
-- Send a CAN message on CAN2 with ID 0x123 and data payload {0x01, 0x02, 0x03}
sendCAN(CAN2, 0x123, {0x01, 0x02, 0x03})
-- Example of sending a command to an external device on CAN3
sendCAN(CAN3, 0x200, {0xFF, 0xAA, 0x55})receiveCAN(canBus, canID, handler)
Registers a CAN handler that gets called when a CAN message is received. Only gets called when a
message on the bus with correct canID is received. This function only needs to be called once,
from global scope. The message handler gets called at the loop rate - prior to the onTick()
function, not at the exact moment the CAN message is received.
canBus: The physical bus to send the message on. (CAN1/CAN2/CAN3)canID: The identifier of the CAN message.handler: function that gets called when CAN message is received
function handleMessage(data)
local temp = (data[2] << 8) | data[1]
print("Temp DLC: " .. #data .. " Temp: " .. temp)
end
receiveCAN(CAN2, 0x123, handleMessage)newPID(p, i, d)
Creates a new PID controller instance with the specified tuning parameters.
p: Proportional gaini: Integral gaind: Derivative gain
Initializing a PID controller to maintain target speeds or stabilize temperatures.
-- Create a PID controller with P=1.0, I=0.5, D=0.1
local pid = newPID(1.0, 0.5, 0.1)pid:compute(target, actual)
Computes the control output of an existing PID controller based on a target value and the actual measured value. This function is supposed to be called in a loop.
target: The desired setpoint value.actual: The current measured value.
-- Create a PID controller
local pid = newPID(1.0, 0.5, 0.1)
-- Compute the control output
local targetTemp = 100 -- Target temperature
local actualTemp = getSensor(Temp1) -- Assume Temp1 provides actual temperature
local controlOutput = pid:compute(targetTemp, actualTemp)setPWMFreq(channel, frequency)
Sets the frequency of the specified PWM (Pulse Width Modulation) channel in Hertz (Hz). This determines how many PWM cycles are generated per second.
channel: The PWM channel to configure (e.g., PWM1, PWM2).frequency: The desired frequency in Hertz.
setPWMFreq(PWM1, 750)setPWMDuty(channel, duty)
Sets the duty cycle of the specified PWM (Pulse Width Modulation) a channel in percent (%).
channel: The PWM channel to configure (e.g., PWM1, PWM2).duty: The desired duty cycle in percent.
setPWMDuty(PWM1, 25)print(string)
Prints a message to the plugin log inside of Bolt.
string: String to print
local ain3_val = getSensor(Ain3)
print("Ain3 Value: " .. ain_val)printStatistics()
Prints detailed memory usage and system statistics to the plugin log.
Example Use Case:Useful for debugging memory leaks and monitoring performance.
-- Print memory and performance stats to the log
printStatistics()getTime()
Returns elapsed time in ms since the VCU booted. Example Use Case: Handle timing operations
if getTime() > 2500 then
someFunction()
endrequestGear(gear)(Requires firmware v1.1.6 or later)
Requests a new gear.
gear: Requested Gear (GEAR_P, GEAR_R, GEAR_N, GEAR_D)
if someVar == 2500 then
requestGear(GEAR_D)
endsetDrivemode(mode)(Requires firmware v1.1.7 or later)
Sets a new drive-mode.
mode: New drive mode (CHILL, NORMAL, SPORT, VALET)
if msg[1] == 100 then
setDrivemode(SPORT)
endconfigureBmsVolt(bus, canId, startBit, length, isSigned, scale, offset, encoding)
Configures decoding of the battery pack voltage from a CAN message. Once configured, the VCU will automatically decode the specified signal and use it as the BMS voltage input.
Note: The BMS type must be set to Custom (Plugin) for this function to take effect. This function can be global and does not have to be called repeatedly.
bus: CAN bus to read the message from (CAN1, CAN2, or CAN3)canId: CAN ID containing the voltage signalstartBit: start decoding data at this bit of the CAN framelength: number of bits to decodeisSigned: decode value as a signed numberscale: encoded data scaled by this factoroffset: encoded data offsetencoding: CAN_MOTOROLA or CAN_INTEL
configureBmsVolt(CAN2, 0x301, 0, 16, false, 1, 0.0, CAN_INTEL)configureBmsCurr(bus, canId, startBit, length, isSigned, scale, offset, encoding)
Configures decoding of the battery pack current from a CAN message. The decoded value will be used as the BMS current measurement within the VCU.
Note: The BMS type must be set to Custom (Plugin) for this function to take effect. This function can be global and does not have to be called repeatedly.
bus: CAN bus to read the message from (CAN1, CAN2, or CAN3)canId: CAN ID containing the current signalstartBit: start decoding data at this bit of the CAN framelength: number of bits to decodeisSigned: decode value as a signed numberscale: encoded data scaled by this factoroffset: encoded data offsetencoding: CAN_MOTOROLA or CAN_INTEL
configureBmsCurr(CAN2, 0x302, 0, 16, true, 0.1, 0.0, CAN_INTEL)configureBmsSoc(bus, canId, startBit, length, isSigned, scale, offset, encoding)
Configures decoding of the battery state of charge (SOC) from a CAN message. The decoded value will be used by the VCU for SOC display.
Note: The BMS type must be set to Custom (Plugin) for this function to take effect. This function can be global and does not have to be called repeatedly.
bus: CAN bus to read the message from (CAN1, CAN2, or CAN3)canId: CAN ID containing the SOC signalstartBit: start decoding data at this bit of the CAN framelength: number of bits to decodeisSigned: decode value as a signed numberscale: encoded data scaled by this factoroffset: encoded data offsetencoding: CAN_MOTOROLA or CAN_INTEL
configureBmsSoc(CAN2, 0x303, 0, 8, false, 1.0, 0.0, CAN_INTEL)configureBmsDisLim(bus, canId, startBit, length, isSigned, scale, offset, encoding)
Configures decoding of the battery discharge current limit (DCL) from a CAN message. The decoded value defines the maximum allowable discharge current reported by the BMS.
Note: The BMS type must be set to Custom (Plugin) for this function to take effect. This function can be global and does not have to be called repeatedly.
bus: CAN bus to read the message from (CAN1, CAN2, or CAN3)canId: CAN ID containing the DCL signalstartBit: start decoding data at this bit of the CAN framelength: number of bits to decodeisSigned: decode value as a signed numberscale: encoded data scaled by this factoroffset: encoded data offsetencoding: CAN_MOTOROLA or CAN_INTEL
configureBmsDisLim(CAN2, 0x304, 0, 16, false, 0.1, 0.0, CAN_INTEL)configureBmsChgLim(bus, canId, startBit, length, isSigned, scale, offset, encoding)
Configures decoding of the battery charge current limit (CCL) from a CAN message. The decoded value defines the maximum allowable charging current reported by the BMS.
Note: The BMS type must be set to Custom (Plugin) for this function to take effect. This function can be global and does not have to be called repeatedly.
bus: CAN bus to read the message from (CAN1, CAN2, or CAN3)canId: CAN ID containing the CCL signalstartBit: start decoding data at this bit of the CAN framelength: number of bits to decodeisSigned: decode value as a signed numberscale: encoded data scaled by this factoroffset: encoded data offsetencoding: CAN_MOTOROLA or CAN_INTEL
configureBmsChgLim(CAN2, 0x304, 16, 16, false, 0.1, 0.0, CAN_INTEL)GPSFixAcquired()(Requires firmware v1.1.7 or later)
Checks if a valid GPS fix has been acquired. Example Use Case: Custom CAN message implementations. Returns: True if a valid GPS fix has been acquired, false otherwise.
if GPSFixAcquired() then
send_GPS_data()
endgetGPSData(data)(Requires firmware v1.1.7 or later)
Fetches GPS data.
data: GPS data requested. Supported types:- LATITUDE (deg)
- LONGITUDE (deg)
- ALTITUDE (m)
- GROUNDSPEED (km/h)
- HEADING (deg)
- TIME (unix timestamp, seconds since epoch)
Example Use Case: Custom CAN message implementations. Returns: Value of the data requested, nil if no valid GPS fix has been acquired.
local heading = getGPSData(HEADING)canEncode(payload, data, startBit, length [, scale [, offset [, encoding]]])
Encodes data into a CAN message payload. The payload table is modified in-place.
All parameters after length are optional.
payload: CAN message data (byte array to write into)data: Data to encodestartBit: start encoding data at this bit of the CAN framelength: number of bits in the CAN framescale (optional): scale data to be encoded (default: 1.0)offset (optional): value offset for the encoded data (default: 0.0)encoding (optional): CAN_MOTOROLA or CAN_INTEL (default: CAN_MOTOROLA)
local sensorPayload = {0, 0, 0, 0, 0, 0, 0, 0}
local rpm = 2500
canEncode(sensorPayload, rpm, 0, 16, 1.0, 0.0, CAN_INTEL)
sendCAN(CAN2, 0x123, sensorPayload)canDecode(payload, startBit, length [, isSigned [, scale [, offset [, encoding]]]])
Decodes data from a CAN message. Should be called from a CAN receive callback.
All parameters after length are optional.
payload: CAN data (byte array)startBit: start decoding data at this bit of the CAN framelength: number of bits to decodeisSigned (optional): decode as a signed number (default: false)scale (optional): encoded data scaled by this factor (default: 1.0)offset (optional): value offset for the encoded data (default: 0.0)encoding (optional): CAN_MOTOROLA or CAN_INTEL (default: CAN_INTEL)
Example Use Case: Custom CAN message implementations. Returns: Decoded value
local rpm = canDecode(canData, 0, 16, false, 1.0, 0.0, CAN_INTEL)
-- Minimal form — unsigned, scale 1.0, offset 0.0, Intel byte order
local soc = canDecode(canData, 0, 8)getPrechargeState()(Requires firmware v1.1.8 or later)
Retrieves the current state of the pre-charge sequence.
Example Use Case:Check if the pre-charge sequence is complete before closing contactors.
Returns: A number representing the pre-charge state (e.g., 0 for inactive, 1 for in-progress, 2 for complete).
if getPrechargeState() == 2 then
-- Precharge is complete, ready to close contactors
setOut(HS1)
endsetPrechargeDone()(Requires firmware v1.1.8 or later)
Manually marks the pre-charge sequence as complete.
Example Use Case:Used in custom pre-charge logic where the completion criteria is determined by the plugin.
-- If custom conditions are met, mark precharge as done
if getSensor(BatteryVoltage) > 300 then
setPrechargeDone()
endsetAnalogOut(channel, voltage)
Sets the output voltage on an analog output channel. The voltage is clamped to the 0–5 V range.
Note: This function is unavailable when:
- The drive inverter type is set to Tesla Large, Tesla Small, or Tesla 3 Rear (these inverter types require the analog outputs for their own operation).
- The pedal output type is set to Analog, Tesla S/X, or Tesla 3/Y.
In either case, the call is rejected with an error logged to the plugin console.
channel: Analog output channel (AOUT1 or AOUT2).voltage: Output voltage in Volts (0.0–5.0 V). Values outside this range are clamped.
Driving an analog gauge or an external controller that accepts a 0–5 V signal.
-- Set AOUT1 to 2.5 V
setAnalogOut(AOUT1, 2.5)Constants
The plugin environment provides a set of predefined constants for easy access to pins, channels, and system states.
Output Pins
- High-Side Outputs:
HS1,HS2,HS3,HS4,HS5,HS6,HS7,HS8 - Low-Side Outputs:
LS1,LS2,LS3,LS4,LS5,LS6,LS7,LS8,LS9,LS10,LS11,LS12 - CAN Keypad LEDs:
CAN-KEY1,CAN-KEY2,CAN-KEY3,CAN-KEY4,CAN-KEY5,CAN-KEY6,CAN-KEY7,CAN-KEY8
PWM Channels
PWM1,PWM2,PWM3,PWM4,PWM5,PWM6,PWM7- Hardware revision v1 only:
PWM8,PWM9,PWM10
CAN Buses
CAN1,CAN2,CAN3
Gear Selection
GEAR_P(Park)GEAR_R(Reverse)GEAR_N(Neutral)GEAR_D(Drive)
Drive Modes
CHILLNORMALSPORTVALET
GPS Data Types
LATITUDELONGITUDEALTITUDEGROUNDSPEEDHEADINGTIME
Analog Outputs
AOUT1,AOUT2
CAN Encoding
CAN_INTEL(little-endian)CAN_MOTOROLA(big-endian)