The program about CAN-bus on the board PX2 run well, recently I update to Xavier,and do some change. Then the program run well on the Xavier, and can read message from CAN, but when called dwSensorCAN_sendMessage it return DW_TIME_OUT. i don’t known why, can anyone help me? i tried to set the time of timeout to 1000, the function dwSensorCAN_sendMessage returned DW_TIME_OUT too.
Dear @jiangyaxi,
Could you share the sample code and sensor connection details for initial triage.
Thank you very much for your reply.
- the next function is the code, i can read message from CAN but can not send message over CAN. and this code is run well in Nvidia PX2 platform.
when the function called, the error debug log “[CAN send] error stat: DW_TIME_OUT” is show.
int SendESC_CombinationSensorStatus(dw_msg_center::Radar_Send_EscCombinationSensorStatus &msg, DwCAN &cansend)
{
dwCANInterpreterHandle_t parser = cansend.getCANSendInterpreter();
dwStatus status;
dwCANMessage SendMsg;
unsigned char crc = 0;
status = dwCANInterpreter_createMessage(&SendMsg, ESC_COMBINATIONSENSORSTATUS_ID, parser);
if (DW_SUCCESS != status) {
ROS_ERROR("[CAN send] create ESC_COMBINATIONSENSORSTATUS message with id: %d failed", ESC_COMBINATIONSENSORSTATUS_ID);
ROS_ERROR("[CAN send] error stat: %s", dwGetStatusName(status));
return -1;
}
dwCANInterpreter_encodef32(msg.RollingCounter, "ESC_CombinationSensorStatus.RollingCounter", &SendMsg, parser);
dwCANInterpreter_encodef32(msg.LongitlAcceSensorSts, "ESC_CombinationSensorStatus.LongitlAcceSensorSts", &SendMsg, parser);
dwCANInterpreter_encodef32(msg.LongitlAcce, "ESC_CombinationSensorStatus.LongitlAcce", &SendMsg, parser);
dwCANInterpreter_encodef32(msg.YawRate, "ESC_CombinationSensorStatus.YawRate", &SendMsg, parser);
dwCANInterpreter_encodef32(msg.LateralAcceSensorSts, "ESC_CombinationSensorStatus.LateralAcceSensorSts", &SendMsg, parser);
dwCANInterpreter_encodef32(msg.LateralAcce, "ESC_CombinationSensorStatus.LateralAcce", &SendMsg, parser);
dwCANInterpreter_encodef32(msg.YawRateSensorSts, "ESC_CombinationSensorStatus.YawRateSensorSts", &SendMsg, parser);
crc = crcAutosar(SendMsg.data, 7, 0);
msg.CheckSUM = crc;
dwCANInterpreter_encodef32(msg.CheckSUM, "ESC_CombinationSensorStatus.CheckSUM", &SendMsg, parser);
SendMsg.size = DW_SENSORS_CAN_MAX_MESSAGE_LEN;
status = dwSensorCAN_sendMessage(&SendMsg, CAN_SEND_TIMEOUT, cansend.getCanSensor());
if (DW_SUCCESS != status) {
ROS_ERROR("[CAN send] send error: %s", dwGetStatusName(status));
return -1;
}
return 0;
}
- Some main CAN connection and start detail code:
DwCAN can_rear;
params = “device=can0”;
if (0 != StartCanBus(can_rear, params, DW_CAN_DRIVE_MODE_SOCKET, recv_dbc, send_dbc)) {
ROS_ERROR(“start can0 canbus failed”);
return -1;
}
int StartCanBus(DwCAN &bus, std::string params, std::string protocol, std::vectorstd::string &recv_dbc, std::vectorstd::string &send_dbc)
{
std::string out_str_files;
std::string merged_file;
if (0 != bus.init(params, protocol)) {
ROS_ERROR(“init can sensor failed”);
return -1;
}
merged_file = DwMergeDbc(recv_dbc);
if (0 != bus.DW_init_Recv(merged_file)) {
ROS_ERROR(“init can receive parser failed”);
return -1;
}
out_str_files += merged_file;
merged_file = DwMergeDbc(send_dbc);
if (0 != bus.DW_init_Send(merged_file)) {
ROS_ERROR(“init can send parser failed”);
return -1;
}
out_str_files += " " + merged_file;
if ( 0!= bus.start()) {
ROS_ERROR(“init can start failed”);
return -1;
}
ROS_INFO_STREAM("init with string: " << params << " dbc files: " << out_str_files << " can protocol: " << protocol);
return 0;
}
======the bus.init function:
int DwCAN::init(std::string in_params, std::string protocol)
{
…
if (DW_SUCCESS != (status = dwGetVersion(&version))) {
ROS_ERROR(“get version error: %s”, dwGetStatusName(status));
return -1;
}
/** init recv sensor */
dwInitialize(&CanSensorSdk, version, &sdkParams);
dwSAL_initialize(&CanSensorHal, CanSensorSdk);
if (DW_CAN_DRIVE_MODE_AURIX != protocol) {
params.protocol = protocol.c_str();
params.parameters = in_params.c_str();
ROS_DEBUG(“use protocol: %s, input param: %s”, params.protocol, params.parameters);
status = dwSAL_createSensor(&CanSensor, params, CanSensorHal);
if (DW_SUCCESS != status) {
ROS_ERROR(“[CAN] Cannot create sensor %s width %s”, params.protocol, params.parameters);
ROS_ERROR(“[CAN] error info: %s”, dwGetStatusName(status));
dwSAL_release(CanSensorHal);
dwRelease(CanSensorSdk);
setCanbusDriverFlag(0);
return -1;
}
}
return 0;
}
=====the bus.start function:
int DwCAN::start()
{
dwStatus status;
status = dwSensor_start(CanSensor);
if (DW_SUCCESS != status) {
ROS_ERROR(“[CAN ] Cannot start sensor, %s”, dwGetStatusName(status));
dwSAL_release(CanSensorHal);
dwRelease(CanSensorSdk);
if ( canRecvParser )
{
dwCANInterpreter_release(canRecvParser);
}
if ( canSendParser )
{
dwCANInterpreter_release(canSendParser);
}
return -1;
}
return 0;
}
Dear @jiangyaxi,
The code you have provided looks not complete. So I have PMed to share complete reproducible code. Please share the code like a DW sample if you still have issue.