Skip to content

Commit 4ae395e

Browse files
authored
Feature/vcf can interface (#14)
* added in documentation for exact CAN specification for expected VCF outputs * initial version of VCF interface, new way to handle segregation of operations / function and VCR CAN Interface beginnings * added in VCF CAN interface *re-adjusting to new structure * changing naming
1 parent 6d62cee commit 4ae395e

23 files changed

+542
-162
lines changed

.clangd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
CompileFlags:
2-
CompilationDatabase: .
2+
CompilationDatabase: .
3+
Add: [-std=c++17]

include/VCR_SystemTasks.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef VCR_SYSTEMTASKS_H
2+
#define VCR_SYSTEMTASKS_H
3+
4+
#include <tuple>
5+
#include <utility>
6+
7+
#include "VCFInterface.h"
8+
9+
#include "SharedFirmwareTypes.h"
10+
11+
#include "VCRCANInterfaceImpl.h"
12+
#include "VehicleStateMachine.h"
13+
#include "DrivetrainSystem.h"
14+
15+
#include "shared_types.h"
16+
17+
struct VCRInterfaces
18+
{
19+
explicit VCRInterfaces(CANInterfaces& can_ints) : can_interfaces(can_ints) {}
20+
VCRInterfaces() = delete;
21+
22+
CANInterfaces& can_interfaces;
23+
};
24+
25+
struct VCRSystems
26+
{
27+
28+
};
29+
30+
struct InterfaceData_s
31+
{
32+
PedalsSystemData_s pedals_data;
33+
};
34+
35+
struct SystemData_s
36+
{
37+
38+
};
39+
40+
// outlining the main process that that is for handling the main systems
41+
// that need interface data and produce outputs that need to get sent
42+
43+
InterfaceData_s sample_async_data(unsigned long millis, VCRInterfaces& interface_ref_container);
44+
VCRData_s evaluate_systems(unsigned long curr_millis, const InterfaceData_s &interface_data, VCRSystems &systems_ref_container);
45+
CarState_e evaluate_state_machine(unsigned long millis, const VCRData_s& system_data, const InterfaceData_s& interface_data, VehicleStateMachine& state_machine);
46+
void update_interfaces(const VCRData_s& system_data, const InterfaceData_s& interface_data);
47+
48+
// void big_task(unsigned long curr_millis);
49+
#endif // __VCR_SYSTEMTASKS_H__

lib/interfaces/README.md

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
## Inverter Interface
22

3-
43
### GPIO connections
54

6-
75
### CAN parameter / message descriptions
86

97
#### VCR output / control messages:
@@ -128,4 +126,60 @@ message 2346 'Converter temperature error' after the warning time1) (ID32943) ha
128126
- AKA SERCOS parameter ID101
129127
- `uint16_t speed_control_kd`
130128
- inverter's internal value of (TD) kd
131-
- AKA SERCOS parameter ID102
129+
- AKA SERCOS parameter ID102
130+
131+
## VCF Interfaces
132+
133+
The VCR is connected over CAN and Ethernet to the VCF. We will use the CAN communication for latency-sensitive communication such as the driver input and controller input sensor signals. The Ethernet link will be used for the non-timing-sensitive data.
134+
135+
### CAN interface
136+
137+
VCF Outputs:
138+
- pedal data CAN packet (`0xC0`):
139+
- status bits: (8 bits)
140+
- `bool accel_implausible`
141+
- accel pedal value is out of range
142+
- `bool brake_implausible`
143+
- brake pedal value is out of range
144+
- `bool brake_pedal_active`
145+
- `bool accel_pedal_active`
146+
- `bool mech_brake_active`
147+
- brake pedal has reached zone in which the mechanical brake (the physical calipers) have started engaging
148+
- `bool brake_and_accel_pressed_implausibility`
149+
- `bool implausibility_exceeded_duration`
150+
- an implausibility been present for longer than allowed (>200ms by rules)
151+
- __note__: we should guard this to be over 180ms or some threshold below 200ms to allow for transmission delay to stay within rules as this is now being reacted to by the VCR
152+
- data (32 bits):
153+
- `brake` (16 bit unsigned) -> mapped between 0 and 1 (65,535)
154+
- `accel` (16 bit unsigned) -> mapped between 0 and 1 (65,535)
155+
156+
- __note__: the regen percentage that was present on MCU should instead be calculated by the controllers themselves instead of by the pedals system to centralize regen calculation at higher levels to allow for tuning / safe modification more easily
157+
158+
- __note__: the following data is all the raw, non-filtered data
159+
- steering data CAN packet:
160+
- `uint16_t analog_steering`
161+
- `float digital_steering` (32 bit)
162+
163+
- suspension data CAN packet:
164+
- `uint16_t fl_load_cell`
165+
- `uint16_t fr_load_cell`
166+
- `uint16_t fl_shock_pot`
167+
- `uint16_t fr_shock_pot`
168+
169+
### Ethernet Interface
170+
171+
`VCFOutputData`
172+
VCF Outputs:
173+
- user inputs
174+
- requested drive mode (0 through 5)
175+
- requesting drivebrain / VCR in control mode
176+
- requested torque limit mode
177+
- requesting drivetrain error reset
178+
- statuses:
179+
- buzzer status
180+
- info:
181+
- firmware version info
182+
- `bool dirty`
183+
- means that the firmware was flashed while there was changes made that had not been commited
184+
- `char git_short_hash[8]`
185+
- the git hash of the commit that was flashed to the
Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,8 @@
11
#ifndef INVERTERINTERFACE_H
22
#define INVERTERINTERFACE_H
3-
#include <stdint.h>
43

5-
namespace HTUnits
6-
{
7-
using celcius = float;
8-
using watts = float;
9-
using var = float;
10-
using torque_nm = float;
11-
using speed_rpm = float;
12-
using volts = float;
13-
};
14-
15-
// for the most part these are mirrors of the lower-level CAN struct data, except with already fully float-ized data
16-
17-
struct InverterStatus_s
18-
{
19-
bool system_ready : 1;
20-
bool error : 1;
21-
bool warning : 1;
22-
bool quit_dc_on : 1;
23-
bool dc_on : 1;
24-
bool quit_inverter_on : 1;
25-
bool inverter_on : 1;
26-
bool derating_on : 1;
27-
HTUnits::volts dc_bus_voltage;
28-
uint16_t diagnostic_number;
29-
};
4+
#include "shared_types.h"
305

31-
struct InverterTemps_s
32-
{
33-
HTUnits::celcius motor_temp;
34-
HTUnits::celcius inverter_temp;
35-
HTUnits::celcius igbt_temp;
36-
};
37-
38-
struct InverterPower_s
39-
{
40-
HTUnits::watts active_power;
41-
HTUnits::var reactive_power;
42-
};
43-
44-
struct MotorMechanics_s
45-
{
46-
HTUnits::watts actual_power;
47-
HTUnits::torque_nm actual_torque;
48-
HTUnits::speed_rpm actual_speed;
49-
};
50-
51-
struct InverterControlParams_s
52-
{
53-
uint16_t speed_control_kp;
54-
uint16_t speed_control_ki;
55-
uint16_t speed_control_kd;
56-
};
57-
58-
struct InverterFeedbackData_s
59-
{
60-
InverterStatus_s status;
61-
InverterTemps_s temps;
62-
InverterPower_s power;
63-
MotorMechanics_s motor_mechanics;
64-
InverterControlParams_s control_params;
65-
};
666

677
// struct InverterMotorControl_s
688
// {
@@ -71,6 +11,7 @@ struct InverterFeedbackData_s
7111

7212
class InverterInterface
7313
{
74-
14+
public:
15+
InverterInterface() = default;
7516
};
7617
#endif // __INVERTERINTERFACE_H__
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef __VCFINTERFACE_H__
2+
#define __VCFINTERFACE_H__
3+
4+
#include "FlexCAN_T4.h"
5+
6+
#include "shared_types.h"
7+
#include "SharedFirmwareTypes.h"
8+
// this struct just contains the data we need from pedals
9+
// within VCR. the implaus check is done in the state machine.
10+
11+
struct LoadCellData_s : TimestampedData_s
12+
{
13+
14+
};
15+
16+
struct VCFCANInterfaceData_s {
17+
StampedPedalsSystemData_s stamped_pedals;
18+
};
19+
20+
class VCFInterface {
21+
public:
22+
VCFInterface() = default;
23+
24+
void receive_pedals_message(const CAN_message_t& msg, unsigned long curr_millis);
25+
26+
VCFCANInterfaceData_s get_latest_data();
27+
28+
private:
29+
30+
VCFCANInterfaceData_s _curr_data;
31+
32+
};
33+
#endif // __VCFINTERFACE_H__
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef __VCRCANINTERFACEIMPL_H__
2+
#define __VCRCANINTERFACEIMPL_H__
3+
4+
#include <cstdint>
5+
6+
#include <tuple>
7+
#include <utility>
8+
9+
#include "FlexCAN_T4.h"
10+
11+
#include "etl/delegate.h"
12+
13+
#include "CANInterface.h"
14+
15+
16+
#include "InverterInterface.h"
17+
18+
#include "SharedFirmwareTypes.h"
19+
20+
#include "shared_types.h"
21+
#include "hytech.h" // generated CAN library
22+
23+
#include "VCFInterface.h"
24+
25+
using CANRXBufferType = Circular_Buffer<uint8_t, (uint32_t)16, sizeof(CAN_message_t)>;
26+
using CANTXBufferType = Circular_Buffer<uint8_t, (uint32_t)128, sizeof(CAN_message_t)>;
27+
28+
/* RX buffers for CAN extern declarations*/
29+
extern CANRXBufferType CAN1_rxBuffer;
30+
extern CANRXBufferType inverter_can_rx_buffer;
31+
extern CANRXBufferType telem_can_rx_buffer;
32+
33+
/* TX buffer for CAN1 */
34+
extern CANTXBufferType CAN1_txBuffer;
35+
/* TX buffer for CAN2 */
36+
extern CANTXBufferType inverter_can_tx_buffer;
37+
/* TX buffer for CAN3 */
38+
extern CANTXBufferType telem_can_tx_buffer;
39+
40+
void on_can1_receive(const CAN_message_t &msg);
41+
void on_inverter_can_receive(const CAN_message_t &msg);
42+
void on_telem_can_receive(const CAN_message_t &msg);
43+
44+
45+
struct CANInterfaces
46+
{
47+
explicit CANInterfaces(VCFInterface& vcf_int): vcf_interface(vcf_int) {}
48+
49+
VCFInterface& vcf_interface;
50+
};
51+
52+
namespace VCRCANInterfaceImpl
53+
{
54+
void vcr_CAN_recv(CANInterfaces& interfaces, const CAN_message_t& msg, unsigned long millis);
55+
};
56+
57+
58+
#endif // __VCRCANINTERFACEIMPL_H__

lib/interfaces/library.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "interfaces",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"dependencies": {
6+
"vcr_shared_types": "*",
7+
"shared_firmware_types": "*",
8+
"FlexCAN_T4": "*",
9+
"can_lib": "*",
10+
"Embedded Template Library": "*",
11+
"QNEthernet": "*",
12+
"shared-interfaces-lib": "*"
13+
},
14+
"frameworks": "*",
15+
"platforms": "*"
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "VCFInterface.h"
2+
#include "hytech.h"
3+
4+
void VCFInterface::receive_pedals_message(const CAN_message_t& msg, unsigned long curr_millis)
5+
{
6+
PEDALS_SYSTEM_DATA_t pedals_msg;
7+
Unpack_PEDALS_SYSTEM_DATA_hytech(&pedals_msg, &msg.buf[0], msg.len);
8+
_curr_data.stamped_pedals.pedals_data.implausibility_has_exceeded_max_duration = pedals_msg.implaus_exceeded_max_duration;
9+
10+
_curr_data.stamped_pedals.pedals_data.brake_and_accel_pressed_implausibility_high = pedals_msg.brake_accel_implausibility;
11+
12+
_curr_data.stamped_pedals.pedals_data.accel_is_implausible = pedals_msg.accel_implausible;
13+
_curr_data.stamped_pedals.pedals_data.brake_is_implausible = pedals_msg.brake_implausible;
14+
15+
_curr_data.stamped_pedals.pedals_data.mech_brake_is_active = pedals_msg.mechanical_brake_active;
16+
_curr_data.stamped_pedals.pedals_data.brake_is_pressed = pedals_msg.brake_pedal_active;
17+
_curr_data.stamped_pedals.pedals_data.accel_is_pressed = pedals_msg.accel_pedal_active;
18+
19+
_curr_data.stamped_pedals.pedals_data.accel_percent = HYTECH_accel_pedal_ro_fromS(static_cast<float>(pedals_msg.accel_pedal_ro));
20+
_curr_data.stamped_pedals.pedals_data.brake_percent = HYTECH_brake_pedal_ro_fromS(static_cast<float>(pedals_msg.brake_pedal_ro));
21+
_curr_data.stamped_pedals.last_recv_millis = curr_millis;
22+
23+
// TODO need to ensure that the pedals data timestamp is within a tollerance within the state machine
24+
}
25+

0 commit comments

Comments
 (0)