当前位置:网站首页>Canoe - the third simulation project - bus simulation - 3-1 project implementation
Canoe - the third simulation project - bus simulation - 3-1 project implementation
2022-07-04 10:51:00 【picoasis】
Follow the simulation engineering process , And functional requirements , Divided into the following steps : Create a simulation project ,DBC File design and import , System variables , Panel design ,CAPL Code implementation , Automatic sequence , Analysis window (Graphics,State Tracker window ,Data window ),Trace Windows and Logging,Desktop Layout , Project operation test . Let's proceed one by one
Catalog ( Please skip to the remaining steps https://blog.csdn.net/lamanchas/article/details/122331103)
1. Create a simulation project
2.DBC Document design , Import
2.2 General attribute settings
2.6 Add signal , relation message、ValueTable
2.8 Configure the message receiving of the node
2.9 Import the database file into the project
4.1 Control panel ( simulation BCM,Gateway The relevant operation )
1. Create a simulation project
open CANoe, choice File→New, Select from the optional templates CAN500kBaud 1ch( The baud rate is 500kBaud,1 passageway ).
Save the project file , named Vehicle System CAN, Save in folder Vehicle_System_Simulation Next . Create the following subfolders under this folder :CANdb、Logging、Nodes and Panels etc. .
2.DBC Document design , Import
according to ECU Normal development process ,DBC Documents are generally provided by the vehicle manufacturer , In very few cases ECU Supplier according to Signal Matrix From row creation DBC file .
Create here from the signal matrix .
2.1 Template creation DBC
With Vector_IL_Basic Template Create a template named VehicleSystem Of CAN database . Of the network Networks name Will also be defined as VehicleSystem, And put it's Protocal Set to CAN.
2.2 General attribute settings
according to vehicleSystem Database Attribute List to set
2.3 Node Node set
There are three in this example ECU node ,NodeLayerModules All adopt CANoeILNLVector.dll To provide weeks Periodical and event driven message sending methods . To increase DBC The readability of the document , Node Comment Medium can Add the English full name of the relevant description or node name , As shown in the table 12.2 Shown .
2.4 Add message
2.5 add to ValueTable
The specific value description is shown in the figure below :
2.6 Add signal , relation message、ValueTable
Cluster_Info Message signal (IPC issue )
Driver_Info Message signal (BCM issue )
Ignition_Info Message signal (BCM issue )
Light_Info Message signal (BCM issue )
Lock_Info Message signal (BCM issue )
EngineData Message signal (GateWay issue )
VehicleData Message signal (Gateway issue )
Gear_Info Message signal (Gateway issue )
2.8 Configure the message receiving of the node
The signal Signal And message After the association is completed , Configure the message reception of the node :
2.9 Import the database file into the project
2.10 Import all nodes
3. Create system variables
Example :Cluster——Gear_Status
alike , Press the following to configure other system variables
4 Panel design
4.1 Control panel ( simulation BCM,Gateway The relevant operation )
4.1.1 Key module —— picture
Picture address : C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\LIN\LINGateway\Panels\Bitmaps\key.bmp
4.1.1 Key module —— Lock switch
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\LIN\LINGateway\Panels\Bitmaps\CarClosed_2.bmp
4.1.1 Key module —— Unlock switch
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\LIN\LINGateway\Panels\Bitmaps\CarOpen_2.bmp
4.1.1 Key module —— Driver1,Driver2
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\LIN\LINGateway\Panels\Bitmaps\ID1_2.bmp
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\LIN\LINGateway\Panels\Bitmaps\ID2_2.bmp
4.1.2 Ignition module -GroupBox
4.1.2 Ignition module - Text module
4.1.2 Ignition module - Key hole
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\CANopen\CANopenGateway\BITMAPS\Ignit_4.bmp
4.1.3 Gear module -GroupBox
4.1.3 Gear module - Gear control
4.1.3 Gear module - Gear text (4 individual )
With D For example :
4.1.4 Brake module -GroupBox
4.1.4 Brake module - Brake control
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\FlexRay\Scope\FlexRayBitMaskAnalysis\Panels\BITMAPS\brake.bmp
4.1.5 Vehicle speed module -GroupBox
4.1.5 Vehicle speed module - Speed control
4.1.6 Engine speed module -GroupBox
4.1.6 Engine speed module - control
4.1.7 Warning light module - static text
4.1.7 Warning light module - Warning signal display \ control
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\CANopen\CANopenGateway\BITMAPS\bmp_2\Warnb_2.bmp
4.1.8 Turn signal module - Turn left and right Text
4.1.8 Turn signal module - Exhibition 、 control
button behaviour To set up for False:
- When button behaviou The value is True, Controlled signal , Only when the left mouse button is pressed 1, Loosen it and it becomes 0
- When button behaviou The value is True, Controlled signal , Press the mouse to 1, Press the mouse again to 0
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\CANopen\CANopenGateway\BITMAPS\bmp_2\Blkl_2.bmp
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\CANopen\CANopenGateway\BITMAPS\bmp_2\Blkr_2.bmp
4.2 Display panel IPC panel
4.2.1 Background map -picture box
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\IO_HIL\VTSystem\User_FPGA\VT7820Demo\Panel\Bitmaps\DashboardCombi.bmp
4.2.2 Time to show
4.2.3 Gear display
4.2.4 Speed value display
Numerical demonstration :
written words (km/h)
4.2.5 Turn signal display -- Left 、 Right
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\Programming\Bitmap_Library\Automotive\Indicator_2States\lGreenBlinkerLeft_2.bmp
C:\Users\Public\Documents\Vector\CANoe\Sample Configurations 12.0.75\Programming\Bitmap_Library\Automotive\Indicator_2States\lGreenBlinkerRight_2.bmp
4.2.6 Engine temperature display
4.2.7 Engine speed display
4.2.8 Vehicle speed display —— The dashboard
4.2.9 Fuel quantity display —— The dashboard
5 CAPL Code
5.1 IPC Code
In this example , Use simulation mode to test IPC, In practice IPC To be tested ECU, Therefore, you need to set this node to Inactive state .( Node is Inactive state , Why set bus status busflag by 0? Global variables busflag wear a watch IPC The state of , Not the state of the external bus )
stay IPC.can in ,CAPL Mainly achieved Message sending mechanism . When the car is locked , The message cannot pass IL Layer send , After unlocking, the periodic message can pass IL Layer send out .(IL What is the floor ? Who sent the periodic message ?)
Mainly used ILControlStart) and ILControlStopO Two functions , Realized Nodes and buses The connection of .
/*@!Encoding:936*/
includes
{
}
variables
{
int busflag = 0;
// Bus status :0-Deactivate CANoe 1L;1-Activate CANoe 1L
}
on preStart
{
ILControlInit();// initialization CANoe IL
ILControlStop();// prohibit CANoe IL Message sending
}
on signal_update LockStatus
{
if(this!=busflag)
{
if(this==1)
{
ILControlStart();// Activate CANoe IL Message sending
}
else if(this == 0)
{
ILControlStop();// prohibit CANoe IL Message sending
}
busflag = this;
}
}
// stay PIC Gear information is displayed on
on signal_update Gear
{
@Cluster::Gear_Status = this;
}
5.2 BCM Code
/*@!Encoding:936*/
includes
{
}
variables
{
msTimer msTcrank;// Define a millisecond timer , be used for Crank Time delay
msTimer msTIL;// Used to turn off IL
int flashPeriod = 500;//Hazards Flash cycle
// Turn signal status :0-both off、1- left flash
//2-Right Flash,3- Hazards on
int TurnLightStatus;
msTimer msTleftflash,msTrightflash;// Turn left and right
message Driver_Info Msgdriver;// Define the message to send Driver Information
}
on preStart
{
ILControlInit();// initialization CANoe IL
ILControlStop();// prohibit CANoe IL Message sending
}
// Handle key position
on sysvar_update Vehicle_Key::Key_State
{
$Ignition_Info::KeyState = @this;
if(@this == 3)
{
@Vehicle_Control::Speed_Up =0;
setTimer(msTcrank,800);// simulation 800ms Time delay
}
}
// Simulate by timer 800ms The rear key automatically returns Run Location
on timer msTcrank
{
$KeyState = 2;
@sysvar::Vehicle_Key::Key_State =2;
}
// Handle Driver ID After the change , Update the message and send
on sysvar_update Vehicle_Key::Car_Driver
{
// According to the system variable , Update message
if(@this==1)
{
Msgdriver.byte(0) = 0;
}
else if(@this == 2)
{
Msgdriver.byte(0)=0x1;
}
output(Msgdriver);
}
// Handle unlock car event
on sysvar_update Vehicle_Key::Unlock_Car
{
if(@this==1)
{
ILControlStart();// Activate CANoe IL Send message
$LockStatus=1;
@Vehicle_Key::Car_Driver=2;//driver 2 For the initial value
}
}
// Handle Lock Car event
on sysvar_update Vehicle_Key::Lock_Car
{
if(@this==1)
{
$LockStatus=0;
setTimer(msTIL,1500);// wait for 1.5s, Make sure the other modules are turned off IL
}
}
on timer msTIL
{
ILControlStop();
}
void LightOFF(void)
{
$VehicleLight = 0;// Initialize the lamp status
TurnLightStatus = 0;
$LightStatus = 0;
}
Realize the dynamic flashing of steering lights and hazard warning lights
on sysvar Vehicle_Control::Left_Turn_Enable
{
if(@this==1)
{
@sysvar::Vehicle_Control::Right_Turn_Enable=0;
$VehicleLight =1;
TurnLightStatus=1;
setTimer(msTleftflash,flashPeriod);
}
else
{
if(@Vehicle_Control::Right_Turn_Enable==0 && @Vehicle_Control::Hazards_Enable==0)
{
LightOFF();
}
cancelTimer(msTleftflash);
@Cluster::Left_Turn_Indicator=0;
}
}
on timer msTleftflash
{
$LightStatus = !$LightStatus;
@Cluster::Left_Turn_Indicator = [email protected]::Left_Turn_Indicator;
setTimer(msTleftflash,flashPeriod);
}
on sysvar Vehicle_Control::Right_Turn_Enable
{
if(@this==1)
{
@sysvar::Vehicle_Control::Left_Turn_Enable=0;
$VehicleLight =2;
TurnLightStatus=2;
setTimer(msTrightflash,flashPeriod);
}
else
{
if(@Vehicle_Control::Left_Turn_Enable==0 && @Vehicle_Control::Hazards_Enable==0)
{
LightOFF();
}
cancelTimer(msTrightflash);
@Cluster::Right_Turn_Indicator=0;
}
}
on timer msTrightflash
{
$LightStatus = !$LightStatus;
@Cluster::Right_Turn_Indicator = [email protected]::Right_Turn_Indicator;
setTimer(msTrightflash,flashPeriod);
}
on sysvar Vehicle_Control::Hazards_Enable
{
if(@this==1)
{
$VehicleLight=3;
@Cluster::Left_Turn_Indicator=1;
@Cluster::Right_Turn_Indicator =1;
setTimer(msTleftflash,flashPeriod);
setTimer(msTrightflash,flashPeriod);
}
else
{
$VehicleLight = TurnLightStatus;
switch(TurnLightStatus)
{
case 1:// Left light flashing
cancelTimer(msTrightflash);
@Cluster::Right_Turn_Indicator=0;
break;
case 2:// The right light flashes
cancelTimer(msTleftflash);
@Cluster::Left_Turn_Indicator=0;
break;
case 0:// Double lights off
cancelTimer(msTleftflash);
cancelTimer(msTrightflash);
$LightStatus=0;
@Cluster::Left_Turn_Indicator=0;
@Cluster::Right_Turn_Indicator=0;
break;
}
}
}
5.3 GateWay Code
/*@!Encoding:936*/
includes
{
}
variables
{
msTimer msTVehSpeedDown;
msTimer msTEngSpeedDown;
Timer sTVehSpeedUp;
dword WritePage;
int busflag=0;//0 deactive;1 active
}
on preStart
{
ILControlInit();// initialization CANoeIL
ILControlStop();// Prohibit message sending
writeLineEx(WritePage,1,"----- This demo demonstrated the CAN bus simulation!!---");
//write Window output project simulation prompt information
writeLineEx(0,1,"Press <1> to start/stop CAN_Logging");
//write windowing output logging Prompt information
}
// control Logging_CAN The beginning and the end of
on key '1'
{
int flag;
if(flag==0)
{
flag=1;
write("CAN logging starts");
startLogging("CAN_Logging",500);//pretrigger The event is 500ms
}
else
{
flag =0;
write("CAN logging ends");
// Stop recording settings posttrigger The event is 1000ms
stopLogging("CAN_logging",1000);
}
}
// Start and end of control bus message
on signal_update LockStatus
{
if(this!=busflag)
{
if(this==1)
{
ILControlStart();
}
else if(this==0)
{
ILControlStop();
}
busflag=this;
}
}
// Set the gear information
// Also need to monitor lock Well , If the car doesn't unlock, Then you can't shift
// And the engine ? After starting , Before shifting
// More detailed —— You also need to monitor the brake signal ?
// Most automatic gears are equipped with shift lock function ,P When shifting from gear to other gears, you need to press the brake forcibly ,
// Switch to P Stall time , Forced deceleration is required
// If you force it into , May damage the transmission .
// Driving status : During driving , There is no need to step on the brake to switch between driving gears , such as D files 、S files 、L Between gears
//
on sysvar Vehicle_Control::Gear
{
if(busflag==1 && @Vehicle_Key::Key_State==2){
[email protected];
}
}
// Initialize engine data
void EngineData_Init(void)
{
$VehicleSpeed=0;
$EngSpeed=0;
$EngTemp=0;
$PetrolLevel=0;
}
// Key signal update event
on signal_update KeyState
{
if(this==0)
{
EngineData_Init();
}
if(this>0)
{
$PetrolLevel=255; // There is a problem , It's directly set to 255, follow-up speedup Yes petrolLevel The change of does not work
// Oil quantity , Fuel consumption ? I can't tell from the code
}
}
// Handle system variable updates -Eng_Speed
on sysvar_update Vehicle_Control::Eng_Speed
{
//Engine speed Only in Key by On Effective when
if(@Vehicle_Key::Key_State==2)
{
$EngineData::[email protected];
}
else
{
$EngineData::EngSpeed=0;
}
}
// Handle system variable updates -Veh_Speed
on sysvar_update Vehicle_Control::Veh_Speed
{
//key by on,drive gear
if((@Vehicle_Control::Gear==3)&&(@Vehicle_Key::Key_State==2))
{
$VehicleData::[email protected];
}
else
{
$VehicleData::VehicleSpeed=0;
}
}
//Speed_Up stay BCM.can When the key status is 2crank when , Initialize to 0,
// thereafter , There is no place to control Speed_Up The change of , So the oil temperature , The oil volume has not changed according to the original procedure
// according to [email protected]; infer ,Speed_Up It is speed control information
// infer speed_up Similar to stepping on the accelerator ----- Simplified understanding is acceleration
// infer 1×: Can be in Control The panel adds throttle , binding speed_up, Other settings and brake Agreement , But this speed_up The value of cannot be set as 0,1;
// infer 2√: When setting the system variable ,speed_up Of max=200, So it should be Set to a control similar to speed control
/// Simulate the speed 、 Engine speed 、 Oil temperature 、 Dynamic change of oil quantity
on sysvar_update Vehicle_Control::Speed_Up
{
if($EngTemp<90)
{
[email protected]*1.5;// The oil temperature change factor is 1.5
}
else
{
$EngTemp=90;
}
if($PetrolLevel<255)
{
[email protected]*8.5;// Fuel volume change factor
}
else
{
$PetrolLevel=255;
}
//[email protected];// Original code --- Incorrect , It should be the corresponding function
[email protected]*40;// Engine speed change factor
if(@this>120)
{
@this=60;
}
// New code ,picoasis,2022.1.18, Acceleration control
if (@this>0)
{
setTimer(sTVehSpeedUp,1);// Accelerate in seconds
}
// New code ,picoasis,2022.1.18, Acceleration control
if(@this==0){
cancelTimer(sTVehSpeedUp);
}
}
// New code ,picoasis,2022.1.18, Acceleration control
on timer sTVehSpeedUp
{
//Vt=Vo+a*t
//km/h =km/h +km/h2 *1s = km/h +km/h2 *(1/3600)h
//@Vehicle_Control::Veh_Speed += (1/3600)*@Vehicle_Control::Speed_Up;//-- It should be calculated like this , But the effect is not obvious , It may also be integer data in division , There was a type conversion problem ..; First use the following formula , Look at the results
@Vehicle_Control::Veh_Speed += @Vehicle_Control::Speed_Up;
// write('%f',@Vehicle_Control::Veh_Speed);
setTimer(this,1);
if(@Vehicle_Control::Veh_Speed>=300)
{
cancelTimer(msTVehSpeedDown);
@Vehicle_Control::Veh_Speed=300;
}
}
on sysvar Vehicle_Control::Brake
{
int i;
if(@this==1)
{
$Gear_Lock=0;
setTimer(msTVehSpeedDown,20);
setTimer(msTEngSpeedDown,2);
}
else
{
$Gear_Lock=1;
cancelTimer(msTVehSpeedDown);
cancelTimer(msTEngSpeedDown);
}
}
on timer msTVehSpeedDown
{
@Vehicle_Control::[email protected]_Control::Veh_Speed-1;
setTimer(this,50);
if(@Vehicle_Control::Veh_Speed<=0)
{
cancelTimer(msTVehSpeedDown);
@Vehicle_Control::Veh_Speed=0;
}
}
on timer msTEngSpeedDown
{
@Vehicle_Control::[email protected]_Control::Eng_Speed-40;
setTimer(this,50);
if(@Vehicle_Control::Eng_Speed<=0)
{
cancelTimer(msTEngSpeedDown);
@Vehicle_Control::Eng_Speed=0;
}
}
To be continued , Jump to --https://blog.csdn.net/lamanchas/article/details/122331103
边栏推荐
- IPv6 comprehensive experiment
- How do microservices aggregate API documents? This wave of show~
- Virtual machine configuration network
- JMeter Foundation
- Write a program to judge whether the two arrays are equal, and then write a similar program to compare the two vectors.
- How to use diff and patch to update the source code
- PHP programming language (1) - operators
- Recursive method to achieve full permutation (C language)
- If you don't know these four caching modes, dare you say you understand caching?
- Application and Optimization Practice of redis in vivo push platform
猜你喜欢
From programmers to large-scale distributed architects, where are you (I)
[Galaxy Kirin V10] [server] system partition expansion
Time complexity and space complexity
Si vous ne connaissez pas ces quatre modes de mise en cache, vous osez dire que vous connaissez la mise en cache?
Seven examples to understand the storage rules of shaped data on each bit
OSPF comprehensive experiment
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
Four characteristics and isolation levels of database transactions
[machine] [server] Taishan 200
leetcode842. Split the array into Fibonacci sequences
随机推荐
Collection of practical string functions
Summary of several job scheduling problems
VLAN part of switching technology
Error C4996 ‘WSAAsyncSelect‘: Use WSAEventSelect() instead or define _ WINSOCK_ DEPRECATED_ NO_ WARN
Application and Optimization Practice of redis in vivo push platform
Huge number (C language)
Snake (C language)
Interview and lecture summary 1
[Galaxy Kirin V10] [server] KVM create Bridge
Huge number multiplication (C language)
Static comprehensive experiment ---hcip1
[Galaxy Kirin V10] [server] failed to start the network
OSPF summary
Const's constant member function after the function; Form, characteristics and use of inline function
C language - stack
Student achievement management system (C language)
Three schemes of ZK double machine room
Postman interface test
The most detailed teaching -- realize win10 multi-user remote login to intranet machine at the same time -- win10+frp+rdpwrap+ Alibaba cloud server
Write a program to define an array with 10 int elements, and take its position in the array as the initial value of each element.