repo_id
stringlengths 19
138
| file_path
stringlengths 32
200
| content
stringlengths 1
12.9M
| __index_level_0__
int64 0
0
|
|---|---|---|---|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/ch_vehicle_factory_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/ch_vehicle_factory.h"
#include "gtest/gtest.h"
#include "modules/canbus/proto/canbus_conf.pb.h"
#include "modules/canbus/proto/vehicle_parameter.pb.h"
#include "cyber/common/file.h"
namespace apollo {
namespace canbus {
class ChVehicleFactoryTest : public ::testing::Test {
public:
virtual void SetUp() {
std::string canbus_conf_file =
"/apollo/modules/canbus_vehicle/ch/testdata/ch_canbus_conf_test.pb.txt";
cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_);
params_ = canbus_conf_.vehicle_parameter();
params_.set_brand(apollo::common::CH);
ch_factory_.SetVehicleParameter(params_);
}
virtual void TearDown() {}
protected:
ChVehicleFactory ch_factory_;
CanbusConf canbus_conf_;
VehicleParameter params_;
};
TEST_F(ChVehicleFactoryTest, Init) {
apollo::cyber::Init("vehicle_factory_test");
EXPECT_EQ(ch_factory_.Init(&canbus_conf_), true);
}
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/ch_vehicle_factory.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file ch_vehicle_factory.h
*/
#pragma once
#include <memory>
#include "modules/canbus/proto/canbus_conf.pb.h"
#include "modules/canbus/proto/vehicle_parameter.pb.h"
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
#include "cyber/cyber.h"
#include "modules/canbus/vehicle/abstract_vehicle_factory.h"
#include "modules/canbus/vehicle/vehicle_controller.h"
#include "modules/common/status/status.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_comm/can_receiver.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
/**
* @namespace apollo::canbus
* @brief apollo::canbus
*/
namespace apollo {
namespace canbus {
/**
* @class ChVehicleFactory
*
* @brief this class is inherited from AbstractVehicleFactory. It can be used to
* create controller and message manager for ch vehicle.
*/
class ChVehicleFactory : public AbstractVehicleFactory {
public:
/**
* @brief destructor
*/
virtual ~ChVehicleFactory() = default;
/**
* @brief init vehicle factory
* @returns true if successfully initialized
*/
bool Init(const CanbusConf *canbus_conf) override;
/**
* @brief start canclient, cansender, canreceiver, vehicle controller
* @returns true if successfully started
*/
bool Start() override;
/**
* @brief stop canclient, cansender, canreceiver, vehicle controller
*/
void Stop() override;
/**
* @brief update control command
*/
void UpdateCommand(
const apollo::control::ControlCommand *control_command) override;
/**
* @brief publish chassis messages
*/
Chassis publish_chassis() override;
/**
* @brief publish chassis for vehicle messages
*/
void PublishChassisDetail() override;
private:
/**
* @brief create ch vehicle controller
* @returns a unique_ptr that points to the created controller
*/
std::unique_ptr<VehicleController<::apollo::canbus::Ch>>
CreateVehicleController();
/**
* @brief create ch message manager
* @returns a unique_ptr that points to the created message manager
*/
std::unique_ptr<MessageManager<::apollo::canbus::Ch>> CreateMessageManager();
std::unique_ptr<::apollo::cyber::Node> node_ = nullptr;
std::unique_ptr<apollo::drivers::canbus::CanClient> can_client_;
CanSender<::apollo::canbus::Ch> can_sender_;
apollo::drivers::canbus::CanReceiver<::apollo::canbus::Ch> can_receiver_;
std::unique_ptr<MessageManager<::apollo::canbus::Ch>> message_manager_;
std::unique_ptr<VehicleController<::apollo::canbus::Ch>> vehicle_controller_;
std::shared_ptr<::apollo::cyber::Writer<::apollo::canbus::Ch>>
chassis_detail_writer_;
};
CYBER_REGISTER_VEHICLEFACTORY(ChVehicleFactory)
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/ch_message_manager_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/ch_message_manager.h"
#include "gtest/gtest.h"
#include "modules/canbus_vehicle/ch/protocol/brake_command_111.h"
#include "modules/canbus_vehicle/ch/protocol/brake_status__511.h"
#include "modules/canbus_vehicle/ch/protocol/ecu_status_1_515.h"
#include "modules/canbus_vehicle/ch/protocol/ecu_status_2_516.h"
#include "modules/canbus_vehicle/ch/protocol/ecu_status_3_517.h"
#include "modules/canbus_vehicle/ch/protocol/gear_command_114.h"
#include "modules/canbus_vehicle/ch/protocol/gear_status_514.h"
#include "modules/canbus_vehicle/ch/protocol/steer_command_112.h"
#include "modules/canbus_vehicle/ch/protocol/steer_status__512.h"
#include "modules/canbus_vehicle/ch/protocol/throttle_command_110.h"
#include "modules/canbus_vehicle/ch/protocol/throttle_status__510.h"
#include "modules/canbus_vehicle/ch/protocol/turnsignal_command_113.h"
#include "modules/canbus_vehicle/ch/protocol/turnsignal_status__513.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::canbus::Ch;
using ::apollo::drivers::canbus::ProtocolData;
class ChMessageManagerTest : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(ChMessageManagerTest, Brakecommand111) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Brakecommand111::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Brakecommand111 *>(pd)->ID, Brakecommand111::ID);
}
TEST_F(ChMessageManagerTest, Brakestatus511) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Brakestatus511::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Brakestatus511 *>(pd)->ID, Brakestatus511::ID);
}
TEST_F(ChMessageManagerTest, Ecustatus1515) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Ecustatus1515::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Ecustatus1515 *>(pd)->ID, Ecustatus1515::ID);
}
TEST_F(ChMessageManagerTest, Ecustatus2516) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Ecustatus2516::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Ecustatus2516 *>(pd)->ID, Ecustatus2516::ID);
}
TEST_F(ChMessageManagerTest, Ecustatus3517) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Ecustatus3517::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Ecustatus3517 *>(pd)->ID, Ecustatus3517::ID);
}
TEST_F(ChMessageManagerTest, Gearcommand114) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Gearcommand114::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Gearcommand114 *>(pd)->ID, Gearcommand114::ID);
}
TEST_F(ChMessageManagerTest, Gearstatus514) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Gearstatus514::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Gearstatus514 *>(pd)->ID, Gearstatus514::ID);
}
TEST_F(ChMessageManagerTest, Steercommand112) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Steercommand112::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Steercommand112 *>(pd)->ID, Steercommand112::ID);
}
TEST_F(ChMessageManagerTest, Steerstatus512) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Steerstatus512::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Steerstatus512 *>(pd)->ID, Steerstatus512::ID);
}
TEST_F(ChMessageManagerTest, Throttlecommand110) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Throttlecommand110::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Throttlecommand110 *>(pd)->ID, Throttlecommand110::ID);
}
TEST_F(ChMessageManagerTest, Throttlestatus510) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Throttlestatus510::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Throttlestatus510 *>(pd)->ID, Throttlestatus510::ID);
}
TEST_F(ChMessageManagerTest, Turnsignalcommand113) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Turnsignalcommand113::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Turnsignalcommand113 *>(pd)->ID,
Turnsignalcommand113::ID);
}
TEST_F(ChMessageManagerTest, Turnsignalstatus513) {
ChMessageManager manager;
ProtocolData<Ch> *pd =
manager.GetMutableProtocolDataById(Turnsignalstatus513::ID);
EXPECT_NE(pd, nullptr);
EXPECT_EQ(static_cast<Turnsignalstatus513 *>(pd)->ID,
Turnsignalstatus513::ID);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/ch_controller.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/ch_controller.h"
#include <string>
#include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h"
#include "cyber/common/log.h"
#include "cyber/time/time.h"
#include "modules/canbus_vehicle/ch/ch_message_manager.h"
#include "modules/canbus/vehicle/vehicle_controller.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::common::ErrorCode;
using ::apollo::control::ControlCommand;
using ::apollo::drivers::canbus::ProtocolData;
namespace {
const int32_t kMaxFailAttempt = 10;
const int32_t CHECK_RESPONSE_STEER_UNIT_FLAG = 1;
const int32_t CHECK_RESPONSE_SPEED_UNIT_FLAG = 2;
} // namespace
ErrorCode ChController::Init(
const VehicleParameter& params,
CanSender<::apollo::canbus::Ch>* const can_sender,
MessageManager<::apollo::canbus::Ch>* const message_manager) {
if (is_initialized_) {
AINFO << "ChController has already been initiated.";
return ErrorCode::CANBUS_ERROR;
}
vehicle_params_.CopyFrom(
common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
params_.CopyFrom(params);
if (!params_.has_driving_mode()) {
AERROR << "Vehicle conf pb not set driving_mode.";
return ErrorCode::CANBUS_ERROR;
}
if (can_sender == nullptr) {
AERROR << "Canbus sender is null.";
return ErrorCode::CANBUS_ERROR;
}
can_sender_ = can_sender;
if (message_manager == nullptr) {
AERROR << "protocol manager is null.";
return ErrorCode::CANBUS_ERROR;
}
message_manager_ = message_manager;
// sender part
brake_command_111_ = dynamic_cast<Brakecommand111*>(
message_manager_->GetMutableProtocolDataById(Brakecommand111::ID));
if (brake_command_111_ == nullptr) {
AERROR << "Brakecommand111 does not exist in the ChMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
gear_command_114_ = dynamic_cast<Gearcommand114*>(
message_manager_->GetMutableProtocolDataById(Gearcommand114::ID));
if (gear_command_114_ == nullptr) {
AERROR << "Gearcommand114 does not exist in the ChMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
steer_command_112_ = dynamic_cast<Steercommand112*>(
message_manager_->GetMutableProtocolDataById(Steercommand112::ID));
if (steer_command_112_ == nullptr) {
AERROR << "Steercommand112 does not exist in the ChMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
throttle_command_110_ = dynamic_cast<Throttlecommand110*>(
message_manager_->GetMutableProtocolDataById(Throttlecommand110::ID));
if (throttle_command_110_ == nullptr) {
AERROR << "Throttlecommand110 does not exist in the ChMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
turnsignal_command_113_ = dynamic_cast<Turnsignalcommand113*>(
message_manager_->GetMutableProtocolDataById(Turnsignalcommand113::ID));
if (turnsignal_command_113_ == nullptr) {
AERROR << "Turnsignalcommand113 does not exist in the ChMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
vehicle_mode_command_116_ = dynamic_cast<Vehiclemodecommand116*>(
message_manager_->GetMutableProtocolDataById(Vehiclemodecommand116::ID));
if (vehicle_mode_command_116_ == nullptr) {
AERROR << "Vehiclemodecommand116 does not exist in the ChMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
can_sender_->AddMessage(Brakecommand111::ID, brake_command_111_, false);
can_sender_->AddMessage(Gearcommand114::ID, gear_command_114_, false);
can_sender_->AddMessage(Steercommand112::ID, steer_command_112_, false);
can_sender_->AddMessage(Throttlecommand110::ID, throttle_command_110_, false);
can_sender_->AddMessage(Turnsignalcommand113::ID, turnsignal_command_113_,
false);
can_sender_->AddMessage(Vehiclemodecommand116::ID, vehicle_mode_command_116_,
false);
// need sleep to ensure all messages received
AINFO << "ChController is initialized.";
is_initialized_ = true;
return ErrorCode::OK;
}
ChController::~ChController() {}
bool ChController::Start() {
if (!is_initialized_) {
AERROR << "ChController has NOT been initiated.";
return false;
}
const auto& update_func = [this] { SecurityDogThreadFunc(); };
thread_.reset(new std::thread(update_func));
return true;
}
void ChController::Stop() {
if (!is_initialized_) {
AERROR << "ChController stops or starts improperly!";
return;
}
if (thread_ != nullptr && thread_->joinable()) {
thread_->join();
thread_.reset();
AINFO << "ChController stopped.";
}
}
Chassis ChController::chassis() {
chassis_.Clear();
Ch chassis_detail;
message_manager_->GetSensorData(&chassis_detail);
// 21, 22, previously 1, 2
// if (driving_mode() == Chassis::EMERGENCY_MODE) {
// set_chassis_error_code(Chassis::NO_ERROR);
// }
chassis_.set_driving_mode(driving_mode());
chassis_.set_error_code(chassis_error_code());
// 3
chassis_.set_engine_started(true);
// 4 engine rpm ch has no engine rpm
// chassis_.set_engine_rpm(0);
// 5 ch has no wheel spd.
if (chassis_detail.has_ecu_status_1_515() &&
chassis_detail.ecu_status_1_515().has_speed()) {
chassis_.set_speed_mps(
static_cast<float>(chassis_detail.ecu_status_1_515().speed()));
} else {
chassis_.set_speed_mps(0);
}
// 6 ch has no odometer
// chassis_.set_odometer_m(0);
// 7 ch has no fuel. do not set;
// chassis_.set_fuel_range_m(0);
// 8 throttle
if (chassis_detail.has_throttle_status__510() &&
chassis_detail.throttle_status__510().has_throttle_pedal_sts()) {
chassis_.set_throttle_percentage(static_cast<float>(
chassis_detail.throttle_status__510().throttle_pedal_sts()));
} else {
chassis_.set_throttle_percentage(0);
}
// 9 brake
if (chassis_detail.has_brake_status__511() &&
chassis_detail.brake_status__511().has_brake_pedal_sts()) {
chassis_.set_brake_percentage(static_cast<float>(
chassis_detail.brake_status__511().brake_pedal_sts()));
} else {
chassis_.set_brake_percentage(0);
}
// 10 gear
if (chassis_detail.has_gear_status_514() &&
chassis_detail.gear_status_514().has_gear_sts()) {
Chassis::GearPosition gear_pos = Chassis::GEAR_INVALID;
if (chassis_detail.gear_status_514().gear_sts() ==
Gear_status_514::GEAR_STS_NEUTRAL) {
gear_pos = Chassis::GEAR_NEUTRAL;
}
if (chassis_detail.gear_status_514().gear_sts() ==
Gear_status_514::GEAR_STS_REVERSE) {
gear_pos = Chassis::GEAR_REVERSE;
}
if (chassis_detail.gear_status_514().gear_sts() ==
Gear_status_514::GEAR_STS_DRIVE) {
gear_pos = Chassis::GEAR_DRIVE;
}
if (chassis_detail.gear_status_514().gear_sts() ==
Gear_status_514::GEAR_STS_PARK) {
gear_pos = Chassis::GEAR_PARKING;
}
chassis_.set_gear_location(gear_pos);
} else {
chassis_.set_gear_location(Chassis::GEAR_NONE);
}
// 11 steering
if (chassis_detail.has_steer_status__512() &&
chassis_detail.steer_status__512().has_steer_angle_sts()) {
chassis_.set_steering_percentage(static_cast<float>(
chassis_detail.steer_status__512().steer_angle_sts() * 100.0 /
vehicle_params_.max_steer_angle()));
} else {
chassis_.set_steering_percentage(0);
}
// 12 battery soc
if (chassis_detail.has_ecu_status_2_516() &&
chassis_detail.ecu_status_2_516().has_battery_soc()) {
chassis_.set_battery_soc_percentage(
chassis_detail.ecu_status_2_516().battery_soc());
}
// 13
// 14 give engage_advice based on error_code and battery low soc warn
if (!chassis_error_mask_ && chassis_.battery_soc_percentage() > 15.0) {
chassis_.mutable_engage_advice()->set_advice(
apollo::common::EngageAdvice::READY_TO_ENGAGE);
} else {
chassis_.mutable_engage_advice()->set_advice(
apollo::common::EngageAdvice::DISALLOW_ENGAGE);
if (chassis_.battery_soc_percentage() > 0) {
chassis_.mutable_engage_advice()->set_reason(
"Battery soc percentage is lower than 15%, please charge it "
"quickly!");
}
}
// 15 set vin
// vin set 17 bits, like LSBN1234567890123 is prased as
// vin17(L),vin16(S),vin15(B),.....,vin03(1)vin02(2),vin01(3)
std::string vin = "";
if (chassis_detail.has_vin_resp1_51b()) {
Vin_resp1_51b vin_51b = chassis_detail.vin_resp1_51b();
vin += vin_51b.vin01();
vin += vin_51b.vin02();
vin += vin_51b.vin03();
vin += vin_51b.vin04();
vin += vin_51b.vin05();
vin += vin_51b.vin06();
vin += vin_51b.vin07();
vin += vin_51b.vin08();
}
if (chassis_detail.has_vin_resp2_51c()) {
Vin_resp2_51c vin_51c = chassis_detail.vin_resp2_51c();
vin += vin_51c.vin09();
vin += vin_51c.vin10();
vin += vin_51c.vin11();
vin += vin_51c.vin12();
vin += vin_51c.vin13();
vin += vin_51c.vin14();
vin += vin_51c.vin15();
vin += vin_51c.vin16();
}
if (chassis_detail.has_vin_resp3_51d()) {
Vin_resp3_51d vin_51d = chassis_detail.vin_resp3_51d();
vin += vin_51d.vin17();
}
std::reverse(vin.begin(), vin.end());
chassis_.mutable_vehicle_id()->set_vin(vin);
// 16 front bumper event
if (chassis_detail.has_brake_status__511() &&
chassis_detail.brake_status__511().has_front_bump_env()) {
if (chassis_detail.brake_status__511().front_bump_env() ==
Brake_status__511::FRONT_BUMP_ENV_FRONT_BUMPER_ENV) {
chassis_.set_front_bumper_event(Chassis::BUMPER_PRESSED);
} else {
chassis_.set_front_bumper_event(Chassis::BUMPER_NORMAL);
}
} else {
chassis_.set_front_bumper_event(Chassis::BUMPER_INVALID);
}
// 17 back bumper event
if (chassis_detail.has_brake_status__511() &&
chassis_detail.brake_status__511().has_back_bump_env()) {
if (chassis_detail.brake_status__511().back_bump_env() ==
Brake_status__511::BACK_BUMP_ENV_BACK_BUMPER_ENV) {
chassis_.set_back_bumper_event(Chassis::BUMPER_PRESSED);
} else {
chassis_.set_back_bumper_event(Chassis::BUMPER_NORMAL);
}
} else {
chassis_.set_back_bumper_event(Chassis::BUMPER_INVALID);
}
// 18 add checkresponse signal
if (chassis_detail.has_brake_status__511() &&
chassis_detail.brake_status__511().has_brake_pedal_en_sts()) {
chassis_.mutable_check_response()->set_is_esp_online(
chassis_detail.brake_status__511().brake_pedal_en_sts() == 1);
}
if (chassis_detail.has_steer_status__512() &&
chassis_detail.steer_status__512().has_steer_angle_en_sts()) {
chassis_.mutable_check_response()->set_is_eps_online(
chassis_detail.steer_status__512().steer_angle_en_sts() == 1);
}
if (chassis_detail.has_throttle_status__510() &&
chassis_detail.throttle_status__510().has_throttle_pedal_en_sts()) {
chassis_.mutable_check_response()->set_is_vcu_online(
chassis_detail.throttle_status__510().throttle_pedal_en_sts() == 1);
}
return chassis_;
}
void ChController::Emergency() {
set_driving_mode(Chassis::EMERGENCY_MODE);
ResetProtocol();
}
ErrorCode ChController::EnableAutoMode() {
if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE) {
AINFO << "already in COMPLETE_AUTO_DRIVE mode";
return ErrorCode::OK;
}
brake_command_111_->set_brake_pedal_en_ctrl(
Brake_command_111::BRAKE_PEDAL_EN_CTRL_ENABLE);
throttle_command_110_->set_throttle_pedal_en_ctrl(
Throttle_command_110::THROTTLE_PEDAL_EN_CTRL_ENABLE);
steer_command_112_->set_steer_angle_en_ctrl(
Steer_command_112::STEER_ANGLE_EN_CTRL_ENABLE);
AINFO << "set enable";
can_sender_->Update();
const int32_t flag =
CHECK_RESPONSE_STEER_UNIT_FLAG | CHECK_RESPONSE_SPEED_UNIT_FLAG;
if (!CheckResponse(flag, true)) {
AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode. Please check the "
"emergency button or chassis.";
Emergency();
set_chassis_error_code(Chassis::CHASSIS_ERROR);
return ErrorCode::CANBUS_ERROR;
} else {
set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok.";
return ErrorCode::OK;
}
}
ErrorCode ChController::DisableAutoMode() {
ResetProtocol();
can_sender_->Update();
set_driving_mode(Chassis::COMPLETE_MANUAL);
set_chassis_error_code(Chassis::NO_ERROR);
AINFO << "Switch to COMPLETE_MANUAL OK!";
return ErrorCode::OK;
}
ErrorCode ChController::EnableSteeringOnlyMode() {
AFATAL << "SteeringOnlyMode Not supported!";
return ErrorCode::OK;
}
ErrorCode ChController::EnableSpeedOnlyMode() {
AFATAL << "SpeedOnlyMode Not supported!";
return ErrorCode::OK;
}
// NEUTRAL, REVERSE, DRIVE
void ChController::Gear(Chassis::GearPosition gear_position) {
if (!(driving_mode() == Chassis::COMPLETE_AUTO_DRIVE ||
driving_mode() == Chassis::AUTO_SPEED_ONLY)) {
AINFO << "this drive mode no need to set gear.";
return;
}
// ADD YOUR OWN CAR CHASSIS OPERATION
switch (gear_position) {
case Chassis::GEAR_NEUTRAL: {
gear_command_114_->set_gear_cmd(Gear_command_114::GEAR_CMD_NEUTRAL);
break;
}
case Chassis::GEAR_REVERSE: {
gear_command_114_->set_gear_cmd(Gear_command_114::GEAR_CMD_REVERSE);
break;
}
case Chassis::GEAR_DRIVE: {
gear_command_114_->set_gear_cmd(Gear_command_114::GEAR_CMD_DRIVE);
break;
}
case Chassis::GEAR_PARKING: {
gear_command_114_->set_gear_cmd(Gear_command_114::GEAR_CMD_PARK);
break;
}
case Chassis::GEAR_INVALID: {
// AERROR << "Gear command is invalid!";
gear_command_114_->set_gear_cmd(Gear_command_114::GEAR_CMD_NEUTRAL);
break;
}
default: {
gear_command_114_->set_gear_cmd(Gear_command_114::GEAR_CMD_NEUTRAL);
break;
}
}
}
// brake with new acceleration
// acceleration:0.00~99.99, unit:
// acceleration:0.0 ~ 7.0, unit:m/s^2
// acceleration_spd:60 ~ 100, suggest: 90
void ChController::Brake(double pedal) {
// Update brake value based on mode
if (!(driving_mode() == Chassis::COMPLETE_AUTO_DRIVE ||
driving_mode() == Chassis::AUTO_SPEED_ONLY)) {
AINFO << "The current drive mode does not need to set acceleration.";
return;
}
// ADD YOUR OWN CAR CHASSIS OPERATION
brake_command_111_->set_brake_pedal_cmd(static_cast<int>(pedal));
}
// drive with old acceleration
// gas:0.00~99.99 unit:
void ChController::Throttle(double pedal) {
if (!(driving_mode() == Chassis::COMPLETE_AUTO_DRIVE ||
driving_mode() == Chassis::AUTO_SPEED_ONLY)) {
AINFO << "The current drive mode does not need to set acceleration.";
return;
}
// ADD YOUR OWN CAR CHASSIS OPERATION
throttle_command_110_->set_throttle_pedal_cmd(static_cast<int>(pedal));
}
void ChController::Acceleration(double acc) {}
// ch default, 23 ~ -23, left:+, right:-
// need to be compatible with control module, so reverse
// steering with old angle speed
// angle:99.99~0.00~-99.99, unit:, left:+, right:-
void ChController::Steer(double angle) {
if (!(driving_mode() == Chassis::COMPLETE_AUTO_DRIVE ||
driving_mode() == Chassis::AUTO_STEER_ONLY)) {
AINFO << "The current driving mode does not need to set steer.";
return;
}
const double real_angle = vehicle_params_.max_steer_angle() * angle / 100.0;
// reverse sign
// ADD YOUR OWN CAR CHASSIS OPERATION
steer_command_112_->set_steer_angle_cmd(real_angle);
}
// steering with new angle speed
// angle:-99.99~0.00~99.99, unit:, left:-, right:+
// angle_spd:0.00~99.99, unit:deg/s
void ChController::Steer(double angle, double angle_spd) {
if (!(driving_mode() == Chassis::COMPLETE_AUTO_DRIVE ||
driving_mode() == Chassis::AUTO_STEER_ONLY)) {
AINFO << "The current driving mode does not need to set steer.";
return;
}
// ADD YOUR OWN CAR CHASSIS OPERATION
const double real_angle = vehicle_params_.max_steer_angle() * angle / 100.0;
steer_command_112_->set_steer_angle_cmd(real_angle);
}
void ChController::SetEpbBreak(const ControlCommand& command) {}
void ChController::SetBeam(const ControlCommand& command) {
// Set low beam
if (command.signal().low_beam()) {
turnsignal_command_113_->set_low_beam_cmd(
Turnsignal_command_113::LOW_BEAM_CMD_ON);
} else {
turnsignal_command_113_->set_low_beam_cmd(
Turnsignal_command_113::LOW_BEAM_CMD_OFF);
}
}
void ChController::SetHorn(const ControlCommand& command) {}
void ChController::SetTurningSignal(const ControlCommand& command) {
// Set Turn Signal
auto signal = command.signal().turn_signal();
if (signal == common::VehicleSignal::TURN_LEFT) {
turnsignal_command_113_->set_turn_signal_cmd(
Turnsignal_command_113::TURN_SIGNAL_CMD_LEFT);
} else if (signal == common::VehicleSignal::TURN_RIGHT) {
turnsignal_command_113_->set_turn_signal_cmd(
Turnsignal_command_113::TURN_SIGNAL_CMD_RIGHT);
} else if (signal == common::VehicleSignal::TURN_HAZARD_WARNING) {
turnsignal_command_113_->set_turn_signal_cmd(
Turnsignal_command_113::TURN_SIGNAL_CMD_HAZARD_WARNING_LAMPSTS);
} else {
turnsignal_command_113_->set_turn_signal_cmd(
Turnsignal_command_113::TURN_SIGNAL_CMD_NONE);
}
}
bool ChController::VerifyID() {
if (!CheckVin()) {
AERROR << "Failed to get the vin. Get vin again.";
GetVin();
return false;
} else {
ResetVin();
return true;
}
}
bool ChController::CheckVin() {
if (chassis_.vehicle_id().vin().size() >= 7) {
AINFO << "Vin check success! Vehicel vin is "
<< chassis_.vehicle_id().vin();
return true;
} else {
AINFO << "Vin check failed! Current vin size is "
<< chassis_.vehicle_id().vin().size();
return false;
}
}
void ChController::GetVin() {
vehicle_mode_command_116_->set_vin_req_cmd(
Vehicle_mode_command_116::VIN_REQ_CMD_VIN_REQ_ENABLE);
AINFO << "Get vin";
can_sender_->Update();
}
void ChController::ResetVin() {
vehicle_mode_command_116_->set_vin_req_cmd(
Vehicle_mode_command_116::VIN_REQ_CMD_VIN_REQ_DISABLE);
AINFO << "Reset vin";
can_sender_->Update();
}
void ChController::ResetProtocol() { message_manager_->ResetSendMessages(); }
bool ChController::CheckChassisError() {
Ch chassis_detail;
message_manager_->GetSensorData(&chassis_detail);
if (!chassis_detail.has_check_response()) {
AERROR_EVERY(100) << "ChassisDetail has NO ch vehicle info."
<< chassis_detail.DebugString();
return false;
}
// steer motor fault
if (chassis_detail.has_steer_status__512()) {
if (Steer_status__512::STEER_ERR_STEER_MOTOR_ERR ==
chassis_detail.steer_status__512().steer_err()) {
return true;
}
// cancel the sensor err check because of discarding the steer sensor
// if (Steer_status__512::SENSOR_ERR_STEER_SENSOR_ERR ==
// ch.steer_status__512().sensor_err()) {
// return false;
// }
}
// drive error
if (chassis_detail.has_throttle_status__510()) {
if (Throttle_status__510::DRIVE_MOTOR_ERR_DRV_MOTOR_ERR ==
chassis_detail.throttle_status__510().drive_motor_err()) {
return true;
}
// cancel the battery err check bacause of always causing this error block
// the vehicle use
// if (Throttle_status__510::BATTERY_BMS_ERR_BATTERY_ERR ==
// chassis_detail.throttle_status__510().battery_bms_err()) {
// return false;
// }
}
// brake error
if (chassis_detail.has_brake_status__511()) {
if (Brake_status__511::BRAKE_ERR_BRAKE_SYSTEM_ERR ==
chassis_detail.brake_status__511().brake_err()) {
return true;
}
}
return false;
}
void ChController::SecurityDogThreadFunc() {
int32_t vertical_ctrl_fail = 0;
int32_t horizontal_ctrl_fail = 0;
if (can_sender_ == nullptr) {
AERROR << "Fail to run SecurityDogThreadFunc() because can_sender_ is "
"nullptr.";
return;
}
while (!can_sender_->IsRunning()) {
std::this_thread::yield();
}
std::chrono::duration<double, std::micro> default_period{50000};
int64_t start = 0;
int64_t end = 0;
while (can_sender_->IsRunning()) {
start = ::apollo::cyber::Time::Now().ToMicrosecond();
const Chassis::DrivingMode mode = driving_mode();
bool emergency_mode = false;
// 1. horizontal control check
if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
mode == Chassis::AUTO_STEER_ONLY) &&
CheckResponse(CHECK_RESPONSE_STEER_UNIT_FLAG, false) == false) {
++horizontal_ctrl_fail;
if (horizontal_ctrl_fail >= kMaxFailAttempt) {
emergency_mode = true;
AINFO << "Driving_mode is into emergency by steer manual intervention";
set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
}
} else {
horizontal_ctrl_fail = 0;
}
// 2. vertical control check
if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
mode == Chassis::AUTO_SPEED_ONLY) &&
CheckResponse(CHECK_RESPONSE_SPEED_UNIT_FLAG, false) == false) {
++vertical_ctrl_fail;
if (vertical_ctrl_fail >= kMaxFailAttempt) {
emergency_mode = true;
AINFO << "Driving_mode is into emergency by speed manual intervention";
set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
}
} else {
vertical_ctrl_fail = 0;
}
if (CheckChassisError()) {
set_chassis_error_code(Chassis::CHASSIS_ERROR);
emergency_mode = true;
}
if (emergency_mode && mode != Chassis::EMERGENCY_MODE) {
set_driving_mode(Chassis::EMERGENCY_MODE);
message_manager_->ResetSendMessages();
can_sender_->Update();
}
end = ::apollo::cyber::Time::Now().ToMicrosecond();
std::chrono::duration<double, std::micro> elapsed{end - start};
if (elapsed < default_period) {
std::this_thread::sleep_for(default_period - elapsed);
} else {
AERROR << "Too much time consumption in ChController looping process:"
<< elapsed.count();
}
}
}
bool ChController::CheckResponse(const int32_t flags, bool need_wait) {
int32_t retry_num = 20;
Ch chassis_detail;
bool is_eps_online = false;
bool is_vcu_online = false;
bool is_esp_online = false;
do {
if (message_manager_->GetSensorData(&chassis_detail) != ErrorCode::OK) {
AERROR_EVERY(100) << "get chassis detail failed.";
return false;
}
bool check_ok = true;
if (flags & CHECK_RESPONSE_STEER_UNIT_FLAG) {
is_eps_online = chassis_detail.has_check_response() &&
chassis_detail.check_response().has_is_eps_online() &&
chassis_detail.check_response().is_eps_online();
check_ok = check_ok && is_eps_online;
}
if (flags & CHECK_RESPONSE_SPEED_UNIT_FLAG) {
is_vcu_online = chassis_detail.has_check_response() &&
chassis_detail.check_response().has_is_vcu_online() &&
chassis_detail.check_response().is_vcu_online();
is_esp_online = chassis_detail.has_check_response() &&
chassis_detail.check_response().has_is_esp_online() &&
chassis_detail.check_response().is_esp_online();
check_ok = check_ok && is_vcu_online && is_esp_online;
}
if (check_ok) {
return true;
} else {
AINFO << "Need to check response again.";
}
if (need_wait) {
--retry_num;
std::this_thread::sleep_for(
std::chrono::duration<double, std::milli>(20));
}
} while (need_wait && retry_num);
AINFO << "check_response fail: is_eps_online:" << is_eps_online
<< ", is_vcu_online:" << is_vcu_online
<< ", is_esp_online:" << is_esp_online;
return false;
}
void ChController::set_chassis_error_mask(const int32_t mask) {
std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
chassis_error_mask_ = mask;
}
int32_t ChController::chassis_error_mask() {
std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
return chassis_error_mask_;
}
Chassis::ErrorCode ChController::chassis_error_code() {
std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
return chassis_error_code_;
}
void ChController::set_chassis_error_code(
const Chassis::ErrorCode& error_code) {
std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
chassis_error_code_ = error_code;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/ch_controller_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/ch_controller.h"
#include "cyber/common/file.h"
#include "gtest/gtest.h"
#include "modules/canbus/proto/canbus_conf.pb.h"
#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/canbus_vehicle/ch/ch_message_manager.h"
#include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h"
#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
namespace apollo {
namespace canbus {
namespace ch {
using apollo::common::ErrorCode;
using apollo::common::VehicleSignal;
using apollo::control::ControlCommand;
class ChControllerTest : public ::testing::Test {
public:
virtual void SetUp() {
std::string canbus_conf_file =
"modules/canbus/testdata/conf/ch_canbus_conf_test.pb.txt";
cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_);
params_ = canbus_conf_.vehicle_parameter();
control_cmd_.set_throttle(20.0);
control_cmd_.set_brake(0.0);
control_cmd_.set_steering_rate(80.0);
control_cmd_.set_horn(false);
}
protected:
ChController controller_;
ControlCommand control_cmd_;
VehicleSignal vehicle_signal_;
CanSender<::apollo::canbus::Ch> sender_;
ChMessageManager msg_manager_;
CanbusConf canbus_conf_;
VehicleParameter params_;
};
TEST_F(ChControllerTest, Init) {
ErrorCode ret = controller_.Init(params_, &sender_, &msg_manager_);
EXPECT_EQ(ret, ErrorCode::OK);
}
TEST_F(ChControllerTest, SetDrivingMode) {
Chassis chassis;
chassis.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
controller_.Init(params_, &sender_, &msg_manager_);
controller_.set_driving_mode(chassis.driving_mode());
EXPECT_EQ(controller_.driving_mode(), chassis.driving_mode());
EXPECT_EQ(controller_.SetDrivingMode(chassis.driving_mode()), ErrorCode::OK);
}
TEST_F(ChControllerTest, Status) {
controller_.Init(params_, &sender_, &msg_manager_);
controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
EXPECT_EQ(controller_.Update(control_cmd_), ErrorCode::OK);
controller_.SetHorn(control_cmd_);
controller_.SetBeam(control_cmd_);
controller_.SetTurningSignal(control_cmd_);
EXPECT_FALSE(controller_.CheckChassisError());
}
TEST_F(ChControllerTest, UpdateDrivingMode) {
controller_.Init(params_, &sender_, &msg_manager_);
controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_MANUAL),
ErrorCode::OK);
EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_AUTO_DRIVE),
ErrorCode::CANBUS_ERROR);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools/install:install.bzl", "install", "install_files", "install_src_files")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
CANBUS_COPTS = ["-DMODULE_NAME=\\\"canbus\\\""]
cc_library(
name = "ch_vehicle_factory",
srcs = ["ch_vehicle_factory.cc"],
hdrs = ["ch_vehicle_factory.h"],
copts = CANBUS_COPTS,
alwayslink = True,
deps = [
":ch_controller",
":ch_message_manager",
"//modules/canbus/common:canbus_gflags",
"//modules/common/adapters:adapter_gflags",
"//modules/common/status",
"//modules/canbus/vehicle:abstract_vehicle_factory",
"//modules/drivers/canbus:sensor_canbus_lib",
],
)
cc_binary(
name = "libch_vehicle_factory_lib.so",
linkshared = True,
linkstatic = True,
deps = [":ch_vehicle_factory"],
)
cc_library(
name = "ch_message_manager",
srcs = ["ch_message_manager.cc"],
hdrs = ["ch_message_manager.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_library(
name = "ch_controller",
srcs = ["ch_controller.cc"],
hdrs = ["ch_controller.h"],
copts = CANBUS_COPTS,
deps = [
":ch_message_manager",
"//modules/canbus/proto:canbus_conf_cc_proto",
"//modules/common_msgs/chassis_msgs:chassis_cc_proto",
"//modules/canbus/proto:vehicle_parameter_cc_proto",
"//modules/canbus/vehicle:vehicle_controller_base",
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/common_msgs/control_msgs:control_cmd_cc_proto",
],
)
cc_test(
name = "ch_controller_test",
size = "small",
srcs = ["ch_controller_test.cc"],
data = ["//modules/canbus:test_data"],
deps = [
":ch_controller",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "ch_message_manager_test",
size = "small",
srcs = ["ch_message_manager_test.cc"],
deps = [
":ch_message_manager",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "ch_vehicle_factory_test",
size = "small",
srcs = ["ch_vehicle_factory_test.cc"],
data = ["//modules/canbus:test_data"],
linkstatic = True,
deps = [
":ch_vehicle_factory",
"@com_google_googletest//:gtest_main",
],
)
install(
name = "install",
library_dest = "canbus-vehicle-ch/lib",
data_dest = "canbus-vehicle-ch",
data = [
":runtime_data",
":cyberfile.xml",
":canbus-vehicle-ch.BUILD",
],
targets = [
":libch_vehicle_factory_lib.so",
],
deps = [
":pb_ch",
":pb_hdrs",
],
)
install(
name = "pb_hdrs",
data_dest = "canbus-vehicle-ch/include",
data = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
],
)
install_files(
name = "pb_ch",
dest = "canbus-vehicle-ch",
files = [
"//modules/canbus_vehicle/ch/proto:ch_py_pb2",
],
)
filegroup(
name = "runtime_data",
srcs = glob([
"testdata/**",
]),
)
install_src_files(
name = "install_src",
deps = [
":install_ch_src",
":install_ch_hdrs"
],
)
install_src_files(
name = "install_ch_src",
src_dir = ["."],
dest = "canbus-vehicle-ch/src",
filter = "*",
)
install_src_files(
name = "install_ch_hdrs",
src_dir = ["."],
dest = "canbus-vehicle-ch/include",
filter = "*.h",
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/ch_message_manager.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file ch_message_manager.h
* @brief the class of ChMessageManager
*/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::MessageManager;
class ChMessageManager
: public MessageManager<::apollo::canbus::Ch> {
public:
ChMessageManager();
virtual ~ChMessageManager();
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/ch_vehicle_factory.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/ch_vehicle_factory.h"
#include "cyber/common/log.h"
#include "modules/canbus/common/canbus_gflags.h"
#include "modules/canbus_vehicle/ch/ch_controller.h"
#include "modules/canbus_vehicle/ch/ch_message_manager.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/common/util/util.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
using apollo::common::ErrorCode;
using apollo::control::ControlCommand;
using apollo::drivers::canbus::CanClientFactory;
namespace apollo {
namespace canbus {
bool ChVehicleFactory::Init(const CanbusConf *canbus_conf) {
// Init can client
auto can_factory = CanClientFactory::Instance();
can_factory->RegisterCanClients();
can_client_ = can_factory->CreateCANClient(canbus_conf->can_card_parameter());
if (!can_client_) {
AERROR << "Failed to create can client.";
return false;
}
AINFO << "Can client is successfully created.";
message_manager_ = this->CreateMessageManager();
if (message_manager_ == nullptr) {
AERROR << "Failed to create message manager.";
return false;
}
AINFO << "Message manager is successfully created.";
if (can_receiver_.Init(can_client_.get(), message_manager_.get(),
canbus_conf->enable_receiver_log()) != ErrorCode::OK) {
AERROR << "Failed to init can receiver.";
return false;
}
AINFO << "The can receiver is successfully initialized.";
if (can_sender_.Init(can_client_.get(), message_manager_.get(),
canbus_conf->enable_sender_log()) != ErrorCode::OK) {
AERROR << "Failed to init can sender.";
return false;
}
AINFO << "The can sender is successfully initialized.";
vehicle_controller_ = CreateVehicleController();
if (vehicle_controller_ == nullptr) {
AERROR << "Failed to create vehicle controller.";
return false;
}
AINFO << "The vehicle controller is successfully created.";
if (vehicle_controller_->Init(canbus_conf->vehicle_parameter(), &can_sender_,
message_manager_.get()) != ErrorCode::OK) {
AERROR << "Failed to init vehicle controller.";
return false;
}
AINFO << "The vehicle controller is successfully"
<< " initialized with canbus conf as : "
<< canbus_conf->vehicle_parameter().ShortDebugString();
node_ = ::apollo::cyber::CreateNode("chassis_detail");
chassis_detail_writer_ =
node_->CreateWriter<::apollo::canbus::Ch>(FLAGS_chassis_detail_topic);
return true;
}
bool ChVehicleFactory::Start() {
// 1. init and start the can card hardware
if (can_client_->Start() != ErrorCode::OK) {
AERROR << "Failed to start can client";
return false;
}
AINFO << "Can client is started.";
// 2. start receive first then send
if (can_receiver_.Start() != ErrorCode::OK) {
AERROR << "Failed to start can receiver.";
return false;
}
AINFO << "Can receiver is started.";
// 3. start send
if (can_sender_.Start() != ErrorCode::OK) {
AERROR << "Failed to start can sender.";
return false;
}
// 4. start controller
if (!vehicle_controller_->Start()) {
AERROR << "Failed to start vehicle controller.";
return false;
}
return true;
}
void ChVehicleFactory::Stop() {
can_sender_.Stop();
can_receiver_.Stop();
can_client_->Stop();
vehicle_controller_->Stop();
AINFO << "Cleanup cansender, canreceiver, canclient, vehicle controller.";
}
void ChVehicleFactory::UpdateCommand(
const apollo::control::ControlCommand *control_command) {
if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) {
AERROR << "Failed to process callback function OnControlCommand because "
"vehicle_controller_->Update error.";
return;
}
can_sender_.Update();
}
Chassis ChVehicleFactory::publish_chassis() {
Chassis chassis = vehicle_controller_->chassis();
ADEBUG << chassis.ShortDebugString();
return chassis;
}
void ChVehicleFactory::PublishChassisDetail() {
Ch chassis_detail;
message_manager_->GetSensorData(&chassis_detail);
ADEBUG << chassis_detail.ShortDebugString();
chassis_detail_writer_->Write(chassis_detail);
}
std::unique_ptr<VehicleController<::apollo::canbus::Ch>>
ChVehicleFactory::CreateVehicleController() {
return std::unique_ptr<VehicleController<::apollo::canbus::Ch>>(
new ch::ChController());
}
std::unique_ptr<MessageManager<::apollo::canbus::Ch>>
ChVehicleFactory::CreateMessageManager() {
return std::unique_ptr<MessageManager<::apollo::canbus::Ch>>(
new ch::ChMessageManager());
}
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/testdata/ch_canbus_conf_test.pb.txt
|
vehicle_parameter {
brand: CH
max_enable_fail_attempt: 5
driving_mode: COMPLETE_AUTO_DRIVE
}
can_card_parameter {
brand: SOCKET_CAN_RAW
type: PCI_CARD
channel_id: CHANNEL_ID_ZERO
}
enable_debug_mode: true
enable_receiver_log: true
enable_sender_log: false
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/proto/ch.proto
|
syntax = "proto2";
package apollo.canbus;
// Coolhigh vehicle starts from here
message Throttle_command_110 {
// Control Message
enum Throttle_pedal_en_ctrlType {
THROTTLE_PEDAL_EN_CTRL_DISABLE = 0;
THROTTLE_PEDAL_EN_CTRL_ENABLE = 1;
}
// throttle pedal enable bit(Command) [] [0|1]
optional Throttle_pedal_en_ctrlType throttle_pedal_en_ctrl = 1;
// Percentage of throttle pedal(Command) [%] [0|100]
optional int32 throttle_pedal_cmd = 2;
}
message Brake_command_111 {
// Control Message
enum Brake_pedal_en_ctrlType {
BRAKE_PEDAL_EN_CTRL_DISABLE = 0;
BRAKE_PEDAL_EN_CTRL_ENABLE = 1;
}
// brake pedal enable bit(Command) [] [0|1]
optional Brake_pedal_en_ctrlType brake_pedal_en_ctrl = 1;
// Percentage of brake pedal(Command) [%] [0|100]
optional int32 brake_pedal_cmd = 2;
}
message Steer_command_112 {
// Control Message
enum Steer_angle_en_ctrlType {
STEER_ANGLE_EN_CTRL_DISABLE = 0;
STEER_ANGLE_EN_CTRL_ENABLE = 1;
}
// steering angle enable bit(Command) [] [0|1]
optional Steer_angle_en_ctrlType steer_angle_en_ctrl = 1;
// Current steering angle(Command) [radian] [-0.524|0.524]
optional double steer_angle_cmd = 2;
}
message Turnsignal_command_113 {
// Control Message
enum Low_beam_cmdType {
LOW_BEAM_CMD_OFF = 0;
LOW_BEAM_CMD_ON = 1;
}
enum Turn_signal_cmdType {
TURN_SIGNAL_CMD_NONE = 0;
TURN_SIGNAL_CMD_LEFT = 1;
TURN_SIGNAL_CMD_RIGHT = 2;
TURN_SIGNAL_CMD_HAZARD_WARNING_LAMPSTS = 3;
}
// Lighting control(Command) [] [0|3]
optional Turn_signal_cmdType turn_signal_cmd = 1;
// Lighting control(Command) [] [0|1]
optional Low_beam_cmdType low_beam_cmd = 2;
}
message Gear_command_114 {
// Control Message
enum Gear_cmdType {
GEAR_CMD_PARK = 1;
GEAR_CMD_REVERSE = 2;
GEAR_CMD_NEUTRAL = 3;
GEAR_CMD_DRIVE = 4;
}
// PRND control(Command) [] [1|4]
optional Gear_cmdType gear_cmd = 1;
}
message Control_command_115 {
// Control Message
enum Ctrl_cmdType {
CTRL_CMD_OUT_OF_CONTROL = 0;
CTRL_CMD_UNDER_CONTROL = 1;
}
// Take control(Command) [] [0|1]
optional Ctrl_cmdType ctrl_cmd = 1;
}
message Vehicle_mode_command_116 {
// Control Message
enum Vin_req_cmdType {
VIN_REQ_CMD_VIN_REQ_DISABLE = 0;
VIN_REQ_CMD_VIN_REQ_ENABLE = 1;
}
// Request VIN(Command) [] [0|1]
optional Vin_req_cmdType vin_req_cmd = 1;
}
message Throttle_status__510 {
// Report Message
enum Throttle_pedal_en_stsType {
THROTTLE_PEDAL_EN_STS_DISABLE = 0;
THROTTLE_PEDAL_EN_STS_ENABLE = 1;
THROTTLE_PEDAL_EN_STS_TAKEOVER = 2;
}
enum Drive_motor_errType {
DRIVE_MOTOR_ERR_NOERR = 0;
DRIVE_MOTOR_ERR_DRV_MOTOR_ERR = 1;
}
enum Battery_bms_errType {
BATTERY_BMS_ERR_NOERR = 0;
BATTERY_BMS_ERR_BATTERY_ERR = 1;
}
// throttle pedal enable bit(Status) [] [0|2]
optional Throttle_pedal_en_stsType throttle_pedal_en_sts = 1;
// Percentage of throttle pedal(Status) [%] [0|100]
optional int32 throttle_pedal_sts = 2;
// [] [0|1]
optional Drive_motor_errType drive_motor_err = 3;
// [] [0|1]
optional Battery_bms_errType battery_bms_err = 4;
}
message Brake_status__511 {
// Report Message
enum Overspd_envType {
OVERSPD_ENV_NOENV = 0;
OVERSPD_ENV_OVERSPEED_ENV = 1;
}
enum Brake_pedal_en_stsType {
BRAKE_PEDAL_EN_STS_DISABLE = 0;
BRAKE_PEDAL_EN_STS_ENABLE = 1;
BRAKE_PEDAL_EN_STS_TAKEOVER = 2;
}
enum Brake_errType {
BRAKE_ERR_NOERR = 0;
BRAKE_ERR_BRAKE_SYSTEM_ERR = 1;
}
enum Emergency_btn_envType {
EMERGENCY_BTN_ENV_NOENV = 0;
EMERGENCY_BTN_ENV_EMERGENCY_BUTTON_ENV = 1;
}
enum Front_bump_envType {
FRONT_BUMP_ENV_NOENV = 0;
FRONT_BUMP_ENV_FRONT_BUMPER_ENV = 1;
}
enum Back_bump_envType {
BACK_BUMP_ENV_NOENV = 0;
BACK_BUMP_ENV_BACK_BUMPER_ENV = 1;
}
enum Brake_light_actualType {
BRAKE_LIGHT_ACTUAL_BRAKELIGHT_OFF = 0;
BRAKE_LIGHT_ACTUAL_BRAKELIGHT_ON = 1;
}
// brake pedal enable bit(Status) [] [0|2]
optional Brake_pedal_en_stsType brake_pedal_en_sts = 1;
// Percentage of brake pedal(Status) [%] [0|100]
optional int32 brake_pedal_sts = 2;
// [] [0|1]
optional Brake_errType brake_err = 3;
// [] [0|1]
optional Emergency_btn_envType emergency_btn_env = 4;
// [] [0|1]
optional Front_bump_envType front_bump_env = 5;
// [] [0|1]
optional Back_bump_envType back_bump_env = 6;
// [] [0|1]
optional Overspd_envType overspd_env = 7;
// [] [0|1]
optional Brake_light_actualType brake_light_actual = 8;
}
message Steer_status__512 {
// Report Message
enum Steer_angle_en_stsType {
STEER_ANGLE_EN_STS_DISABLE = 0;
STEER_ANGLE_EN_STS_ENABLE = 1;
STEER_ANGLE_EN_STS_TAKEOVER = 2;
}
enum Steer_errType {
STEER_ERR_NOERR = 0;
STEER_ERR_STEER_MOTOR_ERR = 1;
}
enum Sensor_errType {
SENSOR_ERR_NOERR = 0;
SENSOR_ERR_STEER_SENSOR_ERR = 1;
}
// steering angle enable bit(Status) [] [0|2]
optional Steer_angle_en_stsType steer_angle_en_sts = 1;
// Current steering angle(Status) [radian] [-0.524|0.524]
optional double steer_angle_sts = 2;
// [] [0|1]
optional Steer_errType steer_err = 3;
// [] [0|1]
optional Sensor_errType sensor_err = 4;
}
message Turnsignal_status__513 {
// Report Message
enum Low_beam_stsType {
LOW_BEAM_STS_ON = 0;
LOW_BEAM_STS_OFF = 1;
}
enum Turn_signal_stsType {
TURN_SIGNAL_STS_NONE = 0;
TURN_SIGNAL_STS_LEFT = 1;
TURN_SIGNAL_STS_RIGHT = 2;
TURN_SIGNAL_STS_HAZARD_WARNING_LAMPSTS_ON = 3;
}
// Lighting control(Status) [] [0|3]
optional Turn_signal_stsType turn_signal_sts = 1;
// Lighting control(Status) [] [0|1]
optional Low_beam_stsType low_beam_sts = 2;
}
message Gear_status_514 {
// Report Message
enum Gear_stsType {
GEAR_STS_PARK = 1;
GEAR_STS_REVERSE = 2;
GEAR_STS_NEUTRAL = 3;
GEAR_STS_DRIVE = 4;
}
// PRND control(Status) [] [1|4]
optional Gear_stsType gear_sts = 1;
}
message Ecu_status_1_515 {
// Report Message
enum Ctrl_stsType {
CTRL_STS_OUT_OF_CONTROL = 0;
CTRL_STS_UNDER_CONTROL = 1;
}
enum Chassis_mcu_errType {
CHASSIS_MCU_ERR_NORMAL = 0;
CHASSIS_MCU_ERR_ERROR = 1;
}
enum Chassis_mcu_canType {
CHASSIS_MCU_CAN_NORMAL = 0;
CHASSIS_MCU_CAN_ERROR = 1;
}
enum Chassis_hw_lostType {
CHASSIS_HW_LOST_NORMAL = 0;
CHASSIS_HW_LOST_ERROR = 1;
}
enum Chassis_eps_errType {
CHASSIS_EPS_ERR_NORMAL = 0;
CHASSIS_EPS_ERR_ERROR = 1;
}
enum Chassis_eps_canType {
CHASSIS_EPS_CAN_NORMAL = 0;
CHASSIS_EPS_CAN_ERROR = 1;
}
enum Chassis_ehb_errType {
CHASSIS_EHB_ERR_NORMAL = 0;
CHASSIS_EHB_ERR_ERROR = 1;
}
enum Chassis_ehb_canType {
CHASSIS_EHB_CAN_NORMAL = 0;
CHASSIS_EHB_CAN_ERROR = 1;
}
enum Chassis_bms_canType {
CHASSIS_BMS_CAN_NORMAL = 0;
CHASSIS_BMS_CAN_ERROR = 1;
}
enum Chassis_ads_errType {
CHASSIS_ADS_ERR_NORMAL = 0;
CHASSIS_ADS_ERR_ADS_CAN_LOST = 1;
CHASSIS_ADS_ERR_ADS_CAN_RECOVERY = 2;
}
// Current speed (Steering status) [m/s] [-327.68|327.67]
optional double speed = 1;
// Current acceleration (Steering status) [m/s^2] [0|0]
optional double acc_speed = 2;
// Current Auto-mode state (Chassis status) [] [0|1]
optional Ctrl_stsType ctrl_sts = 3;
// Current chassis state (Chassis status) [] [0|255]
optional int32 chassis_sts = 4;
// Chassis error code (Chassis status) [] [0|65535]
optional int32 chassis_err = 5;
// [] [0|1]
optional Chassis_mcu_errType chassis_mcu_err = 6;
// [] [0|1]
optional Chassis_mcu_canType chassis_mcu_can = 7;
// [] [0|1]
optional Chassis_hw_lostType chassis_hw_lost = 8;
// [] [0|1]
optional Chassis_eps_errType chassis_eps_err = 9;
// [] [0|1]
optional Chassis_eps_canType chassis_eps_can = 10;
// [] [0|1]
optional Chassis_ehb_errType chassis_ehb_err = 11;
// [] [0|1]
optional Chassis_ehb_canType chassis_ehb_can = 12;
// [] [0|1]
optional Chassis_bms_canType chassis_bms_can = 13;
// Chassis error code (Chassis status) [] [0|2]
optional Chassis_ads_errType chassis_ads_err = 14;
}
message Ecu_status_2_516 {
// Report Message
// Percentage of battery remaining (BMS status) [%] [0|100]
optional int32 battery_soc = 1;
// Battery full capacity (BMS status) [Ah] [0|100]
optional int32 battery_capacity = 2;
// Current battery voltage (BMS status) [V] [0|80]
optional double battery_voltage = 3;
// Current battery current (BMS status) [A] [-60|60]
optional double battery_current = 4;
// Current battery temperature (BMS status) [℃] [-40|110]
optional int32 battery_temperature = 5;
// Battery Low Soc Warn [] [0|1]
optional bool is_battery_soc_low = 6;
}
message Ecu_status_3_517 {
// Report Message
// Ultrasonic detection distance 1 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_1 = 1;
// Ultrasonic detection distance 2 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_2 = 2;
// Ultrasonic detection distance 3 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_3 = 3;
// Ultrasonic detection distance 4 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_4 = 4;
// Ultrasonic detection distance 5 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_5 = 5;
// Ultrasonic detection distance 6 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_6 = 6;
// Ultrasonic detection distance 7 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_7 = 7;
// Ultrasonic detection distance 8 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_8 = 8;
}
message Ecu_status_4_518 {
// Report Message
// Ultrasonic detection distance 9 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_9 = 1;
// Ultrasonic detection distance 10 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_10 = 2;
// Ultrasonic detection distance 11 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_11 = 3;
// Ultrasonic detection distance 12 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_12 = 4;
// Ultrasonic detection distance 13 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_13 = 5;
// Ultrasonic detection distance 14 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_14 = 6;
// Ultrasonic detection distance 15 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_15 = 7;
// Ultrasonic detection distance 16 (Ultrasound status) [cm] [0|500]
optional double ultrasound_dist_16 = 8;
}
message Vin_resp1_51b {
// Report Message
// VIN Response [] [0|255] to char
optional string vin08 = 1;
// VIN Response [] [0|255] to char
optional string vin07 = 2;
// VIN Response [] [0|255] to char
optional string vin06 = 3;
// VIN Response [] [0|255] to char
optional string vin05 = 4;
// VIN Response [] [0|255] to char
optional string vin04 = 5;
// VIN Response [] [0|255] to char
optional string vin03 = 6;
// VIN Response [] [0|255] to char
optional string vin02 = 7;
// VIN Response [] [0|255] to char
optional string vin01 = 8;
}
message Vin_resp2_51c {
// Report Message
// VIN Response [] [0|0] to char
optional string vin16 = 1;
// VIN Response [] [0|0] to char
optional string vin15 = 2;
// VIN Response [] [0|0] to char
optional string vin14 = 3;
// VIN Response [] [0|0] to char
optional string vin13 = 4;
// VIN Response [] [0|0] to char
optional string vin12 = 5;
// VIN Response [] [0|0] to char
optional string vin11 = 6;
// VIN Response [] [0|0] to char
optional string vin10 = 7;
// VIN Response [] [0|0] to char
optional string vin09 = 8;
}
message Vin_resp3_51d {
// Report Message
// VIN Response [] [0|0] to char
optional string vin17 = 1;
}
message Wheelspeed_report_51e {
// Report Message
// wheel speed rear right [m/s] [-327.68|327.67]
optional double rr = 1;
// wheel speed rear left [m/s] [-327.68|327.67]
optional double rl = 2;
// wheel speed front right [m/s] [-327.68|327.67]
optional double fr = 3;
// wheel speed front left [m/s] [-327.68|327.67]
optional double fl = 4;
}
// CheckResponseSignal
message CheckResponseSignal {
optional bool is_eps_online = 1 [default = false];
optional bool is_epb_online = 2 [default = false];
optional bool is_esp_online = 3 [default = false];
optional bool is_vtog_online = 4 [default = false];
optional bool is_scu_online = 5 [default = false];
optional bool is_switch_online = 6 [default = false];
optional bool is_vcu_online = 7 [default = false];
}
message Ch {
optional Throttle_command_110 throttle_command_110 = 1; // control message
optional Brake_command_111 brake_command_111 = 2; // control message
optional Steer_command_112 steer_command_112 = 3; // control message
optional Turnsignal_command_113 turnsignal_command_113 = 4; // control message
optional Gear_command_114 gear_command_114 = 5; // control message
optional Control_command_115 control_command_115 = 6 [deprecated = true]; // control message
optional Throttle_status__510 throttle_status__510 = 7; // report message
optional Brake_status__511 brake_status__511 = 8; // report message
optional Steer_status__512 steer_status__512 = 9; // report message
optional Turnsignal_status__513 turnsignal_status__513 = 10; // report message
optional Gear_status_514 gear_status_514 = 11; // report message
optional Ecu_status_1_515 ecu_status_1_515 = 12; // report message
optional Ecu_status_2_516 ecu_status_2_516 = 13; // report message
optional Ecu_status_3_517 ecu_status_3_517 = 14; // report message
optional Ecu_status_4_518 ecu_status_4_518 = 15; // report message
optional Vehicle_mode_command_116 vehicle_mode_command_116 = 16; // control message
optional Vin_resp1_51b vin_resp1_51b = 17; // report message
optional Vin_resp2_51c vin_resp2_51c = 18; // report message
optional Vin_resp3_51d vin_resp3_51d = 19; // report message
optional Wheelspeed_report_51e wheelspeed_report_51e = 20; // report message
optional CheckResponseSignal check_response = 100;
}
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/proto/BUILD
|
## Auto generated by `proto_build_generator.py`
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("//tools:python_rules.bzl", "py_proto_library")
package(default_visibility = ["//visibility:public"])
cc_proto_library(
name = "ch_cc_proto",
deps = [
":ch_proto",
],
)
proto_library(
name = "ch_proto",
srcs = ["ch.proto"],
)
py_proto_library(
name = "ch_py_pb2",
deps = [
":ch_proto",
],
)
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/steer_status__512.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/steer_status__512.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Steerstatus512::Steerstatus512() {}
const int32_t Steerstatus512::ID = 0x512;
void Steerstatus512::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_steer_status__512()->set_steer_angle_en_sts(
steer_angle_en_sts(bytes, length));
chassis->mutable_steer_status__512()->set_steer_angle_sts(
steer_angle_sts(bytes, length));
chassis->mutable_steer_status__512()->set_steer_err(
steer_err(bytes, length));
chassis->mutable_steer_status__512()->set_sensor_err(
sensor_err(bytes, length));
chassis->mutable_check_response()->set_is_eps_online(
steer_angle_en_sts(bytes, length) == 1);
}
// config detail: {'bit': 0, 'description': 'steering angle enable bit(Status)',
// 'enum': {0: 'STEER_ANGLE_EN_STS_DISABLE', 1: 'STEER_ANGLE_EN_STS_ENABLE', 2:
// 'STEER_ANGLE_EN_STS_TAKEOVER'}, 'is_signed_var': False, 'len': 8, 'name':
// 'steer_angle_en_sts', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Steer_status__512::Steer_angle_en_stsType Steerstatus512::steer_angle_en_sts(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
Steer_status__512::Steer_angle_en_stsType ret =
static_cast<Steer_status__512::Steer_angle_en_stsType>(x);
return ret;
}
// config detail: {'bit': 8, 'description': 'Current steering angle(Status)',
// 'is_signed_var': True, 'len': 16, 'name': 'steer_angle_sts', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[-0.524|0.524]', 'physical_unit':
// 'radian', 'precision': 0.001, 'type': 'double'}
double Steerstatus512::steer_angle_sts(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 1);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.001000;
return ret;
}
// config detail: {'bit': 24, 'enum': {0: 'STEER_ERR_NOERR', 1:
// 'STEER_ERR_STEER_MOTOR_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'steer_err', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Steer_status__512::Steer_errType Steerstatus512::steer_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
Steer_status__512::Steer_errType ret =
static_cast<Steer_status__512::Steer_errType>(x);
return ret;
}
// config detail: {'bit': 32, 'enum': {0: 'SENSOR_ERR_NOERR', 1:
// 'SENSOR_ERR_STEER_SENSOR_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'sensor_err', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Steer_status__512::Sensor_errType Steerstatus512::sensor_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
Steer_status__512::Sensor_errType ret =
static_cast<Steer_status__512::Sensor_errType>(x);
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/turnsignal_status__513_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/turnsignal_status__513.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Turnsignalstatus513Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Turnsignalstatus513Test, General) {
uint8_t data[8] = {0x01, 0x01, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14};
int32_t length = 8;
Ch cd;
Turnsignalstatus513 turnsignalstatus;
turnsignalstatus.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000001);
EXPECT_EQ(data[2], 0b00000011);
EXPECT_EQ(data[3], 0b00000100);
EXPECT_EQ(data[4], 0b00010001);
EXPECT_EQ(data[5], 0b00010010);
EXPECT_EQ(data[6], 0b00010011);
EXPECT_EQ(data[7], 0b00010100);
EXPECT_EQ(cd.turnsignal_status__513().turn_signal_sts(), 1);
EXPECT_EQ(cd.turnsignal_status__513().low_beam_sts(), 1);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/control_command_115_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/control_command_115.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Controlcommand115Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Controlcommand115Test, simple) {
Controlcommand115 controlcommand;
EXPECT_EQ(controlcommand.GetPeriod(), 20 * 1000);
uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68};
controlcommand.UpdateData(data);
EXPECT_EQ(data[0], 0b00000000);
EXPECT_EQ(data[1], 0b01100010);
EXPECT_EQ(data[2], 0b01100011);
EXPECT_EQ(data[3], 0b01100100);
EXPECT_EQ(data[4], 0b01100101);
EXPECT_EQ(data[5], 0b01100110);
EXPECT_EQ(data[6], 0b01100111);
EXPECT_EQ(data[7], 0b01101000);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vin_resp1_51b.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/vin_resp1_51b.h"
#include <string>
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Vinresp151b::Vinresp151b() {}
const int32_t Vinresp151b::ID = 0x51B;
void Vinresp151b::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_vin_resp1_51b()->set_vin08(
vin08(bytes, length));
chassis->mutable_vin_resp1_51b()->set_vin07(
vin07(bytes, length));
chassis->mutable_vin_resp1_51b()->set_vin06(
vin06(bytes, length));
chassis->mutable_vin_resp1_51b()->set_vin05(
vin05(bytes, length));
chassis->mutable_vin_resp1_51b()->set_vin04(
vin04(bytes, length));
chassis->mutable_vin_resp1_51b()->set_vin03(
vin03(bytes, length));
chassis->mutable_vin_resp1_51b()->set_vin02(
vin02(bytes, length));
chassis->mutable_vin_resp1_51b()->set_vin01(
vin01(bytes, length));
}
// config detail: {'bit': 56, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin08', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin08(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 48, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin07', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin07(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 40, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin06', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin06(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 32, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin05', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin05(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 24, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin04', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin04(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 16, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin03', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin03(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 8, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin02', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin02(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 0, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin01', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp151b::vin01(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/turnsignal_status__513.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Turnsignalstatus513 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Turnsignalstatus513();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'Lighting control(Status)',
// 'enum': {0: 'TURN_SIGNAL_STS_NONE', 1: 'TURN_SIGNAL_STS_LEFT', 2:
// 'TURN_SIGNAL_STS_RIGHT', 3: 'TURN_SIGNAL_STS_HAZARD_WARNING_LAMPSTS_ON'},
// 'is_signed_var': False, 'len': 8, 'name': 'TURN_SIGNAL_STS', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
Turnsignal_status__513::Turn_signal_stsType turn_signal_sts(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 8, 'description': 'Lighting control(Status)',
// 'enum': {0: 'LOW_BEAM_STS_ON', 1: 'LOW_BEAM_STS_OFF'}, 'is_signed_var':
// False, 'len': 2, 'name': 'LOW_BEAM_STS', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Turnsignal_status__513::Low_beam_stsType low_beam_sts(
const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/gear_command_114.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/gear_command_114.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
const int32_t Gearcommand114::ID = 0x114;
// public
Gearcommand114::Gearcommand114() { Reset(); }
uint32_t Gearcommand114::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
void Gearcommand114::UpdateData(uint8_t* data) {
set_p_gear_cmd(data, gear_cmd_);
}
void Gearcommand114::Reset() {
// TODO(All) : you should check this manually
gear_cmd_ = Gear_command_114::GEAR_CMD_NEUTRAL;
}
Gearcommand114* Gearcommand114::set_gear_cmd(
Gear_command_114::Gear_cmdType gear_cmd) {
gear_cmd_ = gear_cmd;
return this;
}
// config detail: {'bit': 0, 'description': 'PRND control(Command)', 'enum': {1:
// 'GEAR_CMD_PARK', 2: 'GEAR_CMD_REVERSE', 3: 'GEAR_CMD_NEUTRAL', 4:
// 'GEAR_CMD_DRIVE'}, 'is_signed_var': False, 'len': 8, 'name': 'GEAR_CMD',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[1|4]', 'physical_unit':
// '', 'precision': 1.0, 'type': 'enum'}
void Gearcommand114::set_p_gear_cmd(uint8_t* data,
Gear_command_114::Gear_cmdType gear_cmd) {
int x = gear_cmd;
Byte to_set(data + 0);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_3_517.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/ecu_status_3_517.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Ecustatus3517::Ecustatus3517() {}
const int32_t Ecustatus3517::ID = 0x517;
void Ecustatus3517::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_1(
ultrasound_dist_1(bytes, length));
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_2(
ultrasound_dist_2(bytes, length));
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_3(
ultrasound_dist_3(bytes, length));
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_4(
ultrasound_dist_4(bytes, length));
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_5(
ultrasound_dist_5(bytes, length));
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_6(
ultrasound_dist_6(bytes, length));
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_7(
ultrasound_dist_7(bytes, length));
chassis->mutable_ecu_status_3_517()->set_ultrasound_dist_8(
ultrasound_dist_8(bytes, length));
}
// config detail: {'bit': 0, 'description': 'Ultrasonic detection distance 1
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_1', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_1(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 8, 'description': 'Ultrasonic detection distance 2
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_2', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_2(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 16, 'description': 'Ultrasonic detection distance 3
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_3', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_3(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 24, 'description': 'Ultrasonic detection distance 4
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_4', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_4(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 32, 'description': 'Ultrasonic detection distance 5
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_5', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_5(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 40, 'description': 'Ultrasonic detection distance 6
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_6', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_6(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'bit': 48, 'description': 'Ultrasonic detection distance 7
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_7', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_7(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 56, 'description': 'Ultrasonic detection distance 8
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_8', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus3517::ultrasound_dist_8(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/throttle_status__510_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/throttle_status__510.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Throttlestatus510Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Throttlestatus510Test, General) {
uint8_t data[8] = {0x01, 0x02, 0x01, 0x00, 0x11, 0x12, 0x13, 0x14};
int32_t length = 8;
Ch cd;
Throttlestatus510 throttlestatus;
throttlestatus.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000010);
EXPECT_EQ(data[2], 0b00000001);
EXPECT_EQ(data[3], 0b00000000);
EXPECT_EQ(data[4], 0b00010001);
EXPECT_EQ(data[5], 0b00010010);
EXPECT_EQ(data[6], 0b00010011);
EXPECT_EQ(data[7], 0b00010100);
EXPECT_EQ(cd.throttle_status__510().throttle_pedal_en_sts(), 1);
EXPECT_EQ(cd.throttle_status__510().throttle_pedal_sts(), 2);
EXPECT_EQ(cd.throttle_status__510().drive_motor_err(), 1);
EXPECT_EQ(cd.throttle_status__510().battery_bms_err(), 0);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/brake_status__511.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/brake_status__511.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Brakestatus511::Brakestatus511() {}
const int32_t Brakestatus511::ID = 0x511;
void Brakestatus511::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_brake_status__511()->set_overspd_env(
overspd_env(bytes, length));
chassis->mutable_brake_status__511()->set_brake_pedal_en_sts(
brake_pedal_en_sts(bytes, length));
chassis->mutable_brake_status__511()->set_brake_pedal_sts(
brake_pedal_sts(bytes, length));
chassis->mutable_brake_status__511()->set_brake_err(
brake_err(bytes, length));
chassis->mutable_brake_status__511()->set_emergency_btn_env(
emergency_btn_env(bytes, length));
chassis->mutable_brake_status__511()->set_front_bump_env(
front_bump_env(bytes, length));
chassis->mutable_brake_status__511()->set_back_bump_env(
back_bump_env(bytes, length));
chassis->mutable_brake_status__511()->set_brake_light_actual(
brake_light_actual(bytes, length));
chassis->mutable_check_response()->set_is_esp_online(
brake_pedal_en_sts(bytes, length) == 1);
}
// config detail: {'bit': 48, 'enum': {0: 'OVERSPD_ENV_NOENV', 1:
// 'OVERSPD_ENV_OVERSPEED_ENV'}, 'is_signed_var': False, 'len': 8, 'name':
// 'overspd_env', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Overspd_envType Brakestatus511::overspd_env(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 8);
Brake_status__511::Overspd_envType ret =
static_cast<Brake_status__511::Overspd_envType>(x);
return ret;
}
// config detail: {'bit': 0, 'description': 'brake pedal enable bit(Status)',
// 'enum': {0: 'BRAKE_PEDAL_EN_STS_DISABLE', 1: 'BRAKE_PEDAL_EN_STS_ENABLE', 2:
// 'BRAKE_PEDAL_EN_STS_TAKEOVER'}, 'is_signed_var': False, 'len': 8, 'name':
// 'brake_pedal_en_sts', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Brake_pedal_en_stsType Brakestatus511::brake_pedal_en_sts(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
Brake_status__511::Brake_pedal_en_stsType ret =
static_cast<Brake_status__511::Brake_pedal_en_stsType>(x);
return ret;
}
// config detail: {'bit': 8, 'description': 'Percentage of brake pedal(Status)',
// 'is_signed_var': False, 'len': 8, 'name': 'brake_pedal_sts', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|100]', 'physical_unit': '%',
// 'precision': 1.0, 'type': 'int'}
int Brakestatus511::brake_pedal_sts(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'bit': 16, 'enum': {0: 'BRAKE_ERR_NOERR', 1:
// 'BRAKE_ERR_BRAKE_SYSTEM_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'brake_err', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Brake_errType Brakestatus511::brake_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
Brake_status__511::Brake_errType ret =
static_cast<Brake_status__511::Brake_errType>(x);
return ret;
}
// config detail: {'bit': 24, 'enum': {0: 'EMERGENCY_BTN_ENV_NOENV', 1:
// 'EMERGENCY_BTN_ENV_EMERGENCY_BUTTON_ENV'}, 'is_signed_var': False, 'len': 8,
// 'name': 'emergency_btn_env', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Brake_status__511::Emergency_btn_envType Brakestatus511::emergency_btn_env(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
Brake_status__511::Emergency_btn_envType ret =
static_cast<Brake_status__511::Emergency_btn_envType>(x);
return ret;
}
// config detail: {'bit': 32, 'enum': {0: 'FRONT_BUMP_ENV_NOENV', 1:
// 'FRONT_BUMP_ENV_FRONT_BUMPER_ENV'}, 'is_signed_var': False, 'len': 8, 'name':
// 'front_bump_env', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Front_bump_envType Brakestatus511::front_bump_env(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
Brake_status__511::Front_bump_envType ret =
static_cast<Brake_status__511::Front_bump_envType>(x);
return ret;
}
// config detail: {'bit': 40, 'enum': {0: 'BACK_BUMP_ENV_NOENV', 1:
// 'BACK_BUMP_ENV_BACK_BUMPER_ENV'}, 'is_signed_var': False, 'len': 8, 'name':
// 'back_bump_env', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Back_bump_envType Brakestatus511::back_bump_env(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
Brake_status__511::Back_bump_envType ret =
static_cast<Brake_status__511::Back_bump_envType>(x);
return ret;
}
// config detail: {'bit': 56, 'enum': {0: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_OFF',
// 1: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_ON'}, 'is_signed_var': False, 'len': 1,
// 'name': 'brake_light_actual', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Brake_status__511::Brake_light_actualType Brakestatus511::brake_light_actual(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 1);
Brake_status__511::Brake_light_actualType ret =
static_cast<Brake_status__511::Brake_light_actualType>(x);
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/wheelspeed_report_51e.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Wheelspeedreport51e : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Wheelspeedreport51e();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 48, 'description': 'wheel speed rear right',
// 'is_signed_var': True, 'len': 16, 'name': 'RR', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double rr(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 32, 'description': 'wheel speed rear left',
// 'is_signed_var': True, 'len': 16, 'name': 'RL', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double rl(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 16, 'description': 'wheel speed front right',
// 'is_signed_var': True, 'len': 16, 'name': 'FR', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double fr(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 0, 'description': 'wheel speed front left',
// 'is_signed_var': True, 'len': 16, 'name': 'FL', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double fl(const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/throttle_command_110.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/throttle_command_110.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
const int32_t Throttlecommand110::ID = 0x110;
// public
Throttlecommand110::Throttlecommand110() { Reset(); }
uint32_t Throttlecommand110::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
void Throttlecommand110::UpdateData(uint8_t* data) {
set_p_throttle_pedal_en_ctrl(data, throttle_pedal_en_ctrl_);
set_p_throttle_pedal_cmd(data, throttle_pedal_cmd_);
}
void Throttlecommand110::Reset() {
// TODO(All) : you should check this manually
throttle_pedal_en_ctrl_ =
Throttle_command_110::THROTTLE_PEDAL_EN_CTRL_DISABLE;
throttle_pedal_cmd_ = 0;
}
Throttlecommand110* Throttlecommand110::set_throttle_pedal_en_ctrl(
Throttle_command_110::Throttle_pedal_en_ctrlType throttle_pedal_en_ctrl) {
throttle_pedal_en_ctrl_ = throttle_pedal_en_ctrl;
return this;
}
// config detail: {'bit': 0, 'description': 'throttle pedal enable
// bit(Command)', 'enum': {0: 'THROTTLE_PEDAL_EN_CTRL_DISABLE', 1:
// 'THROTTLE_PEDAL_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'THROTTLE_PEDAL_EN_CTRL', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
void Throttlecommand110::set_p_throttle_pedal_en_ctrl(
uint8_t* data,
Throttle_command_110::Throttle_pedal_en_ctrlType throttle_pedal_en_ctrl) {
int x = throttle_pedal_en_ctrl;
Byte to_set(data + 0);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
Throttlecommand110* Throttlecommand110::set_throttle_pedal_cmd(
int throttle_pedal_cmd) {
throttle_pedal_cmd_ = throttle_pedal_cmd;
return this;
}
// config detail: {'bit': 8, 'description': 'Percentage of throttle
// pedal(Command)', 'is_signed_var': False, 'len': 8, 'name':
// 'THROTTLE_PEDAL_CMD', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
void Throttlecommand110::set_p_throttle_pedal_cmd(uint8_t* data,
int throttle_pedal_cmd) {
throttle_pedal_cmd = ProtocolData::BoundedValue(0, 100, throttle_pedal_cmd);
int x = throttle_pedal_cmd;
Byte to_set(data + 1);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/turnsignal_command_113_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/turnsignal_command_113.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Turnsignalcommand113Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Turnsignalcommand113Test, simple) {
Turnsignalcommand113 turnsignalcommand;
EXPECT_EQ(turnsignalcommand.GetPeriod(), 20 * 1000);
uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68};
turnsignalcommand.UpdateData(data);
EXPECT_EQ(data[0], 0b00000000);
EXPECT_EQ(data[1], 0b01100000);
EXPECT_EQ(data[2], 0b01100011);
EXPECT_EQ(data[3], 0b01100100);
EXPECT_EQ(data[4], 0b01100101);
EXPECT_EQ(data[5], 0b01100110);
EXPECT_EQ(data[6], 0b01100111);
EXPECT_EQ(data[7], 0b01101000);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_3_517_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/ecu_status_3_517.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Ecustatus3517Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Ecustatus3517Test, General) {
uint8_t data[8] = {0x01, 0x02, 0x03, 0x04, 0x01, 0x12, 0x13, 0x14};
int32_t length = 8;
Ch cd;
Ecustatus3517 ecustatus;
ecustatus.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000010);
EXPECT_EQ(data[2], 0b00000011);
EXPECT_EQ(data[3], 0b00000100);
EXPECT_EQ(data[4], 0b00000001);
EXPECT_EQ(data[5], 0b00010010);
EXPECT_EQ(data[6], 0b00010011);
EXPECT_EQ(data[7], 0b00010100);
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_1(), 2);
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_2(), 4);
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_3(), 6);
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_4(), 8);
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_5(), 2);
// todo:// check expect 36 or 18 ?
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_6(), 18);
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_7(), 38);
EXPECT_EQ(cd.ecu_status_3_517().ultrasound_dist_8(), 40);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/throttle_command_110_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/throttle_command_110.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Throttlecommand110Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Throttlecommand110Test, simple) {
Throttlecommand110 throttlecommand;
EXPECT_EQ(throttlecommand.GetPeriod(), 20 * 1000);
uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68};
throttlecommand.UpdateData(data);
EXPECT_EQ(data[0], 0b00000000);
EXPECT_EQ(data[1], 0b00000000);
EXPECT_EQ(data[2], 0b01100011);
EXPECT_EQ(data[3], 0b01100100);
EXPECT_EQ(data[4], 0b01100101);
EXPECT_EQ(data[5], 0b01100110);
EXPECT_EQ(data[6], 0b01100111);
EXPECT_EQ(data[7], 0b01101000);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vin_resp1_51b.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <string>
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Vinresp151b : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Vinresp151b();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 56, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN08', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin08(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 48, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN07', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin07(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 40, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN06', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin06(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 32, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN05', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin05(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 24, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN04', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin04(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 16, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN03', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin03(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 8, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN02', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin02(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 0, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN01', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|255]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin01(const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/control_command_115.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Controlcommand115 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Controlcommand115();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'description': 'Take control(Command)', 'enum': {0:
// 'CTRL_CMD_OUT_OF_CONTROL', 1: 'CTRL_CMD_UNDER_CONTROL'}, 'precision': 1.0,
// 'len': 8, 'name': 'CTRL_CMD', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Controlcommand115* set_ctrl_cmd(Control_command_115::Ctrl_cmdType ctrl_cmd);
private:
// config detail: {'description': 'Take control(Command)', 'enum': {0:
// 'CTRL_CMD_OUT_OF_CONTROL', 1: 'CTRL_CMD_UNDER_CONTROL'}, 'precision': 1.0,
// 'len': 8, 'name': 'CTRL_CMD', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
void set_p_ctrl_cmd(uint8_t* data,
Control_command_115::Ctrl_cmdType ctrl_cmd);
private:
Control_command_115::Ctrl_cmdType ctrl_cmd_;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_3_517.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Ecustatus3517 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Ecustatus3517();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'Ultrasonic detection distance 1
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_1', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_1(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 8, 'description': 'Ultrasonic detection distance 2
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_2', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_2(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 16, 'description': 'Ultrasonic detection distance 3
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_3', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_3(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 24, 'description': 'Ultrasonic detection distance 4
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_4', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_4(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 32, 'description': 'Ultrasonic detection distance 5
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_5', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_5(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 40, 'description': 'Ultrasonic detection distance 6
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_6', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_6(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 48, 'description': 'Ultrasonic detection distance 7
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_7', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_7(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 56, 'description': 'Ultrasonic detection distance 8
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_8', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_8(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/gear_status_514.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/gear_status_514.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Gearstatus514::Gearstatus514() {}
const int32_t Gearstatus514::ID = 0x514;
void Gearstatus514::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_gear_status_514()->set_gear_sts(
gear_sts(bytes, length));
}
// config detail: {'bit': 0, 'description': 'PRND control(Status)', 'enum': {1:
// 'GEAR_STS_PARK', 2: 'GEAR_STS_REVERSE', 3: 'GEAR_STS_NEUTRAL', 4:
// 'GEAR_STS_DRIVE'}, 'is_signed_var': False, 'len': 8, 'name': 'gear_sts',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[1|4]', 'physical_unit':
// '', 'precision': 1.0, 'type': 'enum'}
Gear_status_514::Gear_stsType Gearstatus514::gear_sts(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
Gear_status_514::Gear_stsType ret =
static_cast<Gear_status_514::Gear_stsType>(x);
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/brake_status__511.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Brakestatus511 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Brakestatus511();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 48, 'enum': {0: 'OVERSPD_ENV_NOENV', 1:
// 'OVERSPD_ENV_OVERSPEED_ENV'}, 'is_signed_var': False, 'len': 8, 'name':
// 'OVERSPD_ENV', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Overspd_envType overspd_env(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 0, 'description': 'brake pedal enable bit(Status)',
// 'enum': {0: 'BRAKE_PEDAL_EN_STS_DISABLE', 1: 'BRAKE_PEDAL_EN_STS_ENABLE',
// 2: 'BRAKE_PEDAL_EN_STS_TAKEOVER'}, 'is_signed_var': False, 'len': 8,
// 'name': 'BRAKE_PEDAL_EN_STS', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Brake_status__511::Brake_pedal_en_stsType brake_pedal_en_sts(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 8, 'description': 'Percentage of brake
// pedal(Status)', 'is_signed_var': False, 'len': 8, 'name':
// 'BRAKE_PEDAL_STS', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
int brake_pedal_sts(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 16, 'enum': {0: 'BRAKE_ERR_NOERR', 1:
// 'BRAKE_ERR_BRAKE_SYSTEM_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'BRAKE_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Brake_errType brake_err(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 24, 'enum': {0: 'EMERGENCY_BTN_ENV_NOENV', 1:
// 'EMERGENCY_BTN_ENV_EMERGENCY_BUTTON_ENV'}, 'is_signed_var': False, 'len':
// 8, 'name': 'EMERGENCY_BTN_ENV', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Brake_status__511::Emergency_btn_envType emergency_btn_env(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 32, 'enum': {0: 'FRONT_BUMP_ENV_NOENV', 1:
// 'FRONT_BUMP_ENV_FRONT_BUMPER_ENV'}, 'is_signed_var': False, 'len': 8,
// 'name': 'FRONT_BUMP_ENV', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Brake_status__511::Front_bump_envType front_bump_env(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 40, 'enum': {0: 'BACK_BUMP_ENV_NOENV', 1:
// 'BACK_BUMP_ENV_BACK_BUMPER_ENV'}, 'is_signed_var': False, 'len': 8, 'name':
// 'BACK_BUMP_ENV', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brake_status__511::Back_bump_envType back_bump_env(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 56, 'enum': {0: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_OFF',
// 1: 'BRAKE_LIGHT_ACTUAL_BRAKELIGHT_ON'}, 'is_signed_var': False, 'len': 1,
// 'name': 'Brake_Light_Actual', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Brake_status__511::Brake_light_actualType brake_light_actual(
const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/turnsignal_command_113.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/turnsignal_command_113.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
const int32_t Turnsignalcommand113::ID = 0x113;
// public
Turnsignalcommand113::Turnsignalcommand113() { Reset(); }
uint32_t Turnsignalcommand113::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
void Turnsignalcommand113::UpdateData(uint8_t* data) {
set_p_turn_signal_cmd(data, turn_signal_cmd_);
set_p_low_beam_cmd(data, low_beam_cmd_);
}
void Turnsignalcommand113::Reset() {
// TODO(All) : you should check this manually
turn_signal_cmd_ = Turnsignal_command_113::TURN_SIGNAL_CMD_NONE;
low_beam_cmd_ = Turnsignal_command_113::LOW_BEAM_CMD_OFF;
}
Turnsignalcommand113* Turnsignalcommand113::set_turn_signal_cmd(
Turnsignal_command_113::Turn_signal_cmdType turn_signal_cmd) {
turn_signal_cmd_ = turn_signal_cmd;
return this;
}
// config detail: {'bit': 0, 'description': 'Lighting control(Command)', 'enum':
// {0: 'TURN_SIGNAL_CMD_NONE', 1: 'TURN_SIGNAL_CMD_LEFT', 2:
// 'TURN_SIGNAL_CMD_RIGHT', 3: 'TURN_SIGNAL_CMD_HAZARD_WARNING_LAMPSTS'},
// 'is_signed_var': False, 'len': 8, 'name': 'TURN_SIGNAL_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
void Turnsignalcommand113::set_p_turn_signal_cmd(
uint8_t* data,
Turnsignal_command_113::Turn_signal_cmdType turn_signal_cmd) {
int x = turn_signal_cmd;
Byte to_set(data + 0);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
Turnsignalcommand113* Turnsignalcommand113::set_low_beam_cmd(
Turnsignal_command_113::Low_beam_cmdType low_beam_cmd) {
low_beam_cmd_ = low_beam_cmd;
return this;
}
// config detail: {'bit': 8, 'description': 'Lighting control(Command)', 'enum':
// {0: 'LOW_BEAM_CMD_OFF', 1: 'LOW_BEAM_CMD_ON'}, 'is_signed_var': False, 'len':
// 2, 'name': 'LOW_BEAM_CMD', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
void Turnsignalcommand113::set_p_low_beam_cmd(
uint8_t* data, Turnsignal_command_113::Low_beam_cmdType low_beam_cmd) {
int x = low_beam_cmd;
Byte to_set(data + 1);
to_set.set_value(static_cast<uint8_t>(x), 0, 2);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/wheelspeed_report_51e.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/wheelspeed_report_51e.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Wheelspeedreport51e::Wheelspeedreport51e() {}
const int32_t Wheelspeedreport51e::ID = 0x51E;
void Wheelspeedreport51e::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_wheelspeed_report_51e()->set_rr(
rr(bytes, length));
chassis->mutable_wheelspeed_report_51e()->set_rl(
rl(bytes, length));
chassis->mutable_wheelspeed_report_51e()->set_fr(
fr(bytes, length));
chassis->mutable_wheelspeed_report_51e()->set_fl(
fl(bytes, length));
}
// config detail: {'bit': 48, 'description': 'wheel speed rear right',
// 'is_signed_var': True, 'len': 16, 'name': 'rr', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double Wheelspeedreport51e::rr(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 6);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.010000;
return ret;
}
// config detail: {'bit': 32, 'description': 'wheel speed rear left',
// 'is_signed_var': True, 'len': 16, 'name': 'rl', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double Wheelspeedreport51e::rl(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 4);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.010000;
return ret;
}
// config detail: {'bit': 16, 'description': 'wheel speed front right',
// 'is_signed_var': True, 'len': 16, 'name': 'fr', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double Wheelspeedreport51e::fr(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.010000;
return ret;
}
// config detail: {'bit': 0, 'description': 'wheel speed front left',
// 'is_signed_var': True, 'len': 16, 'name': 'fl', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double Wheelspeedreport51e::fl(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 0);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.010000;
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/steer_status__512.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Steerstatus512 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Steerstatus512();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'steering angle enable
// bit(Status)', 'enum': {0: 'STEER_ANGLE_EN_STS_DISABLE', 1:
// 'STEER_ANGLE_EN_STS_ENABLE', 2: 'STEER_ANGLE_EN_STS_TAKEOVER'},
// 'is_signed_var': False, 'len': 8, 'name': 'STEER_ANGLE_EN_STS', 'offset':
// 0.0, 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
Steer_status__512::Steer_angle_en_stsType steer_angle_en_sts(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 8, 'description': 'Current steering angle(Status)',
// 'is_signed_var': True, 'len': 16, 'name': 'STEER_ANGLE_STS', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[-0.524|0.524]', 'physical_unit':
// 'radian', 'precision': 0.001, 'type': 'double'}
double steer_angle_sts(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 24, 'enum': {0: 'STEER_ERR_NOERR', 1:
// 'STEER_ERR_STEER_MOTOR_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'STEER_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Steer_status__512::Steer_errType steer_err(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 32, 'enum': {0: 'SENSOR_ERR_NOERR', 1:
// 'SENSOR_ERR_STEER_SENSOR_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'SENSOR_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Steer_status__512::Sensor_errType sensor_err(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/throttle_command_110.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Throttlecommand110 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Throttlecommand110();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'bit': 0, 'description': 'throttle pedal enable
// bit(Command)', 'enum': {0: 'THROTTLE_PEDAL_EN_CTRL_DISABLE', 1:
// 'THROTTLE_PEDAL_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'THROTTLE_PEDAL_EN_CTRL', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Throttlecommand110* set_throttle_pedal_en_ctrl(
Throttle_command_110::Throttle_pedal_en_ctrlType throttle_pedal_en_ctrl);
// config detail: {'bit': 8, 'description': 'Percentage of throttle
// pedal(Command)', 'is_signed_var': False, 'len': 8, 'name':
// 'THROTTLE_PEDAL_CMD', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
Throttlecommand110* set_throttle_pedal_cmd(int throttle_pedal_cmd);
private:
// config detail: {'bit': 0, 'description': 'throttle pedal enable
// bit(Command)', 'enum': {0: 'THROTTLE_PEDAL_EN_CTRL_DISABLE', 1:
// 'THROTTLE_PEDAL_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'THROTTLE_PEDAL_EN_CTRL', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
void set_p_throttle_pedal_en_ctrl(
uint8_t* data,
Throttle_command_110::Throttle_pedal_en_ctrlType throttle_pedal_en_ctrl);
// config detail: {'bit': 8, 'description': 'Percentage of throttle
// pedal(Command)', 'is_signed_var': False, 'len': 8, 'name':
// 'THROTTLE_PEDAL_CMD', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
void set_p_throttle_pedal_cmd(uint8_t* data, int throttle_pedal_cmd);
private:
Throttle_command_110::Throttle_pedal_en_ctrlType throttle_pedal_en_ctrl_;
int throttle_pedal_cmd_;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/control_command_115.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/control_command_115.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
const int32_t Controlcommand115::ID = 0x115;
// public
Controlcommand115::Controlcommand115() { Reset(); }
uint32_t Controlcommand115::GetPeriod() const {
// modify every protocol's period manually
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
void Controlcommand115::UpdateData(uint8_t* data) {
set_p_ctrl_cmd(data, ctrl_cmd_);
}
void Controlcommand115::Reset() {
// you should check this manually
ctrl_cmd_ = Control_command_115::CTRL_CMD_OUT_OF_CONTROL;
}
Controlcommand115* Controlcommand115::set_ctrl_cmd(
Control_command_115::Ctrl_cmdType ctrl_cmd) {
ctrl_cmd_ = ctrl_cmd;
return this;
}
// config detail: {'description': 'Take control(Command)', 'enum': {0:
// 'CTRL_CMD_OUT_OF_CONTROL', 1: 'CTRL_CMD_UNDER_CONTROL'}, 'precision': 1.0,
// 'len': 8, 'name': 'CTRL_CMD', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
void Controlcommand115::set_p_ctrl_cmd(
uint8_t* data, Control_command_115::Ctrl_cmdType ctrl_cmd) {
int x = ctrl_cmd;
Byte to_set(data + 0);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/gear_command_114_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/gear_command_114.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Gearcommand114Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Gearcommand114Test, simple) {
Gearcommand114 gearcommand;
EXPECT_EQ(gearcommand.GetPeriod(), 20 * 1000);
uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68};
gearcommand.UpdateData(data);
EXPECT_EQ(data[0], 0b00000011);
EXPECT_EQ(data[1], 0b01100010);
EXPECT_EQ(data[2], 0b01100011);
EXPECT_EQ(data[3], 0b01100100);
EXPECT_EQ(data[4], 0b01100101);
EXPECT_EQ(data[5], 0b01100110);
EXPECT_EQ(data[6], 0b01100111);
EXPECT_EQ(data[7], 0b01101000);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/throttle_status__510.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/throttle_status__510.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Throttlestatus510::Throttlestatus510() {}
const int32_t Throttlestatus510::ID = 0x510;
void Throttlestatus510::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis
->mutable_throttle_status__510()
->set_throttle_pedal_en_sts(throttle_pedal_en_sts(bytes, length));
chassis->mutable_throttle_status__510()->set_throttle_pedal_sts(
throttle_pedal_sts(bytes, length));
chassis->mutable_throttle_status__510()->set_drive_motor_err(
drive_motor_err(bytes, length));
chassis->mutable_throttle_status__510()->set_battery_bms_err(
battery_bms_err(bytes, length));
chassis->mutable_check_response()->set_is_vcu_online(
throttle_pedal_en_sts(bytes, length) == 1);
}
// config detail: {'description': 'throttle pedal enable bit(Status)', 'enum':
// {0: 'THROTTLE_PEDAL_EN_STS_DISABLE', 1: 'THROTTLE_PEDAL_EN_STS_ENABLE', 2:
// 'THROTTLE_PEDAL_EN_STS_TAKEOVER'}, 'precision': 1.0, 'len': 8, 'name':
// 'throttle_pedal_en_sts', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|1]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Throttle_status__510::Throttle_pedal_en_stsType
Throttlestatus510::throttle_pedal_en_sts(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
Throttle_status__510::Throttle_pedal_en_stsType ret =
static_cast<Throttle_status__510::Throttle_pedal_en_stsType>(x);
return ret;
}
// config detail: {'bit': 8, 'description': 'Percentage of throttle
// pedal(Status)', 'is_signed_var': False, 'len': 8, 'name':
// 'throttle_pedal_sts', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
int Throttlestatus510::throttle_pedal_sts(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'bit': 16, 'enum': {0: 'DRIVE_MOTOR_ERR_NOERR', 1:
// 'DRIVE_MOTOR_ERR_DRV_MOTOR_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'drive_motor_err', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Throttle_status__510::Drive_motor_errType Throttlestatus510::drive_motor_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
Throttle_status__510::Drive_motor_errType ret =
static_cast<Throttle_status__510::Drive_motor_errType>(x);
return ret;
}
// config detail: {'bit': 24, 'enum': {0: 'BATTERY_BMS_ERR_NOERR', 1:
// 'BATTERY_BMS_ERR_BATTERY_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'battery_bms_err', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Throttle_status__510::Battery_bms_errType Throttlestatus510::battery_bms_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
Throttle_status__510::Battery_bms_errType ret =
static_cast<Throttle_status__510::Battery_bms_errType>(x);
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/gear_status_514.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Gearstatus514 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Gearstatus514();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'PRND control(Status)', 'enum':
// {1: 'GEAR_STS_PARK', 2: 'GEAR_STS_REVERSE', 3: 'GEAR_STS_NEUTRAL', 4:
// 'GEAR_STS_DRIVE'}, 'is_signed_var': False, 'len': 8, 'name': 'GEAR_STS',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[1|4]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Gear_status_514::Gear_stsType gear_sts(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vin_resp2_51c.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/vin_resp2_51c.h"
#include <string>
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Vinresp251c::Vinresp251c() {}
const int32_t Vinresp251c::ID = 0x51C;
void Vinresp251c::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_vin_resp2_51c()->set_vin16(
vin16(bytes, length));
chassis->mutable_vin_resp2_51c()->set_vin15(
vin15(bytes, length));
chassis->mutable_vin_resp2_51c()->set_vin14(
vin14(bytes, length));
chassis->mutable_vin_resp2_51c()->set_vin13(
vin13(bytes, length));
chassis->mutable_vin_resp2_51c()->set_vin12(
vin12(bytes, length));
chassis->mutable_vin_resp2_51c()->set_vin11(
vin11(bytes, length));
chassis->mutable_vin_resp2_51c()->set_vin10(
vin10(bytes, length));
chassis->mutable_vin_resp2_51c()->set_vin09(
vin09(bytes, length));
}
// config detail: {'bit': 56, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin16', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin16(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 48, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin15', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin15(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 40, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin14', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin14(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 32, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin13', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin13(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 24, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin12', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin12(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 16, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin11', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin11(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 8, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin10', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin10(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
// config detail: {'bit': 0, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin09', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp251c::vin09(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_1_515_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/ecu_status_1_515.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Ecustatus1515Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Ecustatus1515Test, General) {
uint8_t data[8] = {0x01, 0x02, 0x03, 0x04, 0x01, 0x12, 0x12, 0x14};
int32_t length = 8;
Ch cd;
Ecustatus1515 ecustatus;
ecustatus.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000010);
EXPECT_EQ(data[2], 0b00000011);
EXPECT_EQ(data[3], 0b00000100);
EXPECT_EQ(data[4], 0b00000001);
EXPECT_EQ(data[5], 0b00010010);
EXPECT_EQ(data[6], 0b00010010);
EXPECT_EQ(data[7], 0b00010100);
EXPECT_DOUBLE_EQ(cd.ecu_status_1_515().speed(), 5.1299999999999999);
EXPECT_DOUBLE_EQ(cd.ecu_status_1_515().acc_speed(), 1.0269999999999999);
EXPECT_EQ(cd.ecu_status_1_515().ctrl_sts(), 1);
EXPECT_EQ(cd.ecu_status_1_515().chassis_sts(), 18);
EXPECT_EQ(cd.ecu_status_1_515().chassis_err(), 5138);
EXPECT_EQ(cd.ecu_status_1_515().chassis_mcu_err(), 0);
EXPECT_EQ(cd.ecu_status_1_515().chassis_mcu_can(), 0);
EXPECT_EQ(cd.ecu_status_1_515().chassis_hw_lost(), 0);
EXPECT_EQ(cd.ecu_status_1_515().chassis_eps_err(), 0);
EXPECT_EQ(cd.ecu_status_1_515().chassis_eps_can(), 0);
EXPECT_EQ(cd.ecu_status_1_515().chassis_ehb_err(), 1);
EXPECT_EQ(cd.ecu_status_1_515().chassis_ehb_can(), 0);
EXPECT_EQ(cd.ecu_status_1_515().chassis_bms_can(), 0);
EXPECT_EQ(cd.ecu_status_1_515().chassis_ads_err(), 2);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/turnsignal_command_113.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Turnsignalcommand113 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Turnsignalcommand113();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'bit': 8, 'description': 'Lighting control(Command)',
// 'enum': {0: 'LOW_BEAM_CMD_OFF', 1: 'LOW_BEAM_CMD_ON'}, 'is_signed_var':
// False, 'len': 2, 'name': 'LOW_BEAM_CMD', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
Turnsignalcommand113* set_low_beam_cmd(
Turnsignal_command_113::Low_beam_cmdType low_beam_cmd);
// config detail: {'bit': 0, 'description': 'Lighting control(Command)',
// 'enum': {0: 'TURN_SIGNAL_CMD_NONE', 1: 'TURN_SIGNAL_CMD_LEFT', 2:
// 'TURN_SIGNAL_CMD_RIGHT', 3: 'TURN_SIGNAL_CMD_HAZARD_WARNING_LAMPSTS'},
// 'is_signed_var': False, 'len': 8, 'name': 'TURN_SIGNAL_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
Turnsignalcommand113* set_turn_signal_cmd(
Turnsignal_command_113::Turn_signal_cmdType turn_signal_cmd);
private:
// config detail: {'bit': 8, 'description': 'Lighting control(Command)',
// 'enum': {0: 'LOW_BEAM_CMD_OFF', 1: 'LOW_BEAM_CMD_ON'}, 'is_signed_var':
// False, 'len': 2, 'name': 'LOW_BEAM_CMD', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'enum'}
void set_p_low_beam_cmd(
uint8_t* data, Turnsignal_command_113::Low_beam_cmdType low_beam_cmd);
// config detail: {'bit': 0, 'description': 'Lighting control(Command)',
// 'enum': {0: 'TURN_SIGNAL_CMD_NONE', 1: 'TURN_SIGNAL_CMD_LEFT', 2:
// 'TURN_SIGNAL_CMD_RIGHT', 3: 'TURN_SIGNAL_CMD_HAZARD_WARNING_LAMPSTS'},
// 'is_signed_var': False, 'len': 8, 'name': 'TURN_SIGNAL_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
void set_p_turn_signal_cmd(
uint8_t* data,
Turnsignal_command_113::Turn_signal_cmdType turn_signal_cmd);
private:
Turnsignal_command_113::Turn_signal_cmdType turn_signal_cmd_;
Turnsignal_command_113::Low_beam_cmdType low_beam_cmd_;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/gear_status_514_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/gear_status_514.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Gearstatus514Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Gearstatus514Test, General) {
uint8_t data[8] = {0x01, 0x02, 0x03, 0x04, 0x11, 0x12, 0x13, 0x14};
int32_t length = 8;
Ch cd;
Gearstatus514 gearstatus;
gearstatus.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000010);
EXPECT_EQ(data[2], 0b00000011);
EXPECT_EQ(data[3], 0b00000100);
EXPECT_EQ(data[4], 0b00010001);
EXPECT_EQ(data[5], 0b00010010);
EXPECT_EQ(data[6], 0b00010011);
EXPECT_EQ(data[7], 0b00010100);
EXPECT_EQ(cd.gear_status_514().gear_sts(), 1);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vehicle_mode_command_116.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/vehicle_mode_command_116.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
const int32_t Vehiclemodecommand116::ID = 0x116;
// public
Vehiclemodecommand116::Vehiclemodecommand116() { Reset(); }
uint32_t Vehiclemodecommand116::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 500 * 1000;
return PERIOD;
}
void Vehiclemodecommand116::UpdateData(uint8_t* data) {
set_p_vin_req_cmd(data, vin_req_cmd_);
}
void Vehiclemodecommand116::Reset() {
// TODO(All) : you should check this manually
vin_req_cmd_ = Vehicle_mode_command_116::VIN_REQ_CMD_VIN_REQ_DISABLE;
}
Vehiclemodecommand116* Vehiclemodecommand116::set_vin_req_cmd(
Vehicle_mode_command_116::Vin_req_cmdType vin_req_cmd) {
vin_req_cmd_ = vin_req_cmd;
return this;
}
// config detail: {'bit': 0, 'description': 'Request VIN(Command)', 'enum': {0:
// 'VIN_REQ_CMD_VIN_REQ_DISABLE', 1: 'VIN_REQ_CMD_VIN_REQ_ENABLE'},
// 'is_signed_var': False, 'len': 1, 'name': 'VIN_REQ_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|1]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
void Vehiclemodecommand116::set_p_vin_req_cmd(
uint8_t* data, Vehicle_mode_command_116::Vin_req_cmdType vin_req_cmd) {
int x = vin_req_cmd;
Byte to_set(data + 0);
to_set.set_value(static_cast<uint8_t>(x), 0, 1);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/steer_command_112.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/steer_command_112.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
const int32_t Steercommand112::ID = 0x112;
// public
Steercommand112::Steercommand112() { Reset(); }
uint32_t Steercommand112::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
void Steercommand112::UpdateData(uint8_t* data) {
set_p_steer_angle_en_ctrl(data, steer_angle_en_ctrl_);
set_p_steer_angle_cmd(data, steer_angle_cmd_);
}
void Steercommand112::Reset() {
// TODO(All) : you should check this manually
steer_angle_en_ctrl_ = Steer_command_112::STEER_ANGLE_EN_CTRL_DISABLE;
steer_angle_cmd_ = 0.0;
}
Steercommand112* Steercommand112::set_steer_angle_en_ctrl(
Steer_command_112::Steer_angle_en_ctrlType steer_angle_en_ctrl) {
steer_angle_en_ctrl_ = steer_angle_en_ctrl;
return this;
}
// config detail: {'bit': 0, 'description': 'steering angle enable
// bit(Command)', 'enum': {0: 'STEER_ANGLE_EN_CTRL_DISABLE', 1:
// 'STEER_ANGLE_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'STEER_ANGLE_EN_CTRL', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
void Steercommand112::set_p_steer_angle_en_ctrl(
uint8_t* data,
Steer_command_112::Steer_angle_en_ctrlType steer_angle_en_ctrl) {
int x = steer_angle_en_ctrl;
Byte to_set(data + 0);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
Steercommand112* Steercommand112::set_steer_angle_cmd(double steer_angle_cmd) {
steer_angle_cmd_ = steer_angle_cmd;
return this;
}
// config detail: {'bit': 8, 'description': 'Current steering angle(Command)',
// 'is_signed_var': True, 'len': 16, 'name': 'STEER_ANGLE_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[-0.524|0.524]', 'physical_unit':
// 'radian', 'precision': 0.001, 'type': 'double'}
void Steercommand112::set_p_steer_angle_cmd(uint8_t* data,
double steer_angle_cmd) {
steer_angle_cmd = ProtocolData::BoundedValue(-0.524, 0.524, steer_angle_cmd);
int x = static_cast<int>(steer_angle_cmd / 0.001000);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set0(data + 1);
to_set0.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set1(data + 2);
to_set1.set_value(t, 0, 8);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_4_518.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/ecu_status_4_518.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Ecustatus4518::Ecustatus4518() {}
const int32_t Ecustatus4518::ID = 0x518;
void Ecustatus4518::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_9(
ultrasound_dist_9(bytes, length));
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_10(
ultrasound_dist_10(bytes, length));
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_11(
ultrasound_dist_11(bytes, length));
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_12(
ultrasound_dist_12(bytes, length));
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_13(
ultrasound_dist_13(bytes, length));
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_14(
ultrasound_dist_14(bytes, length));
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_15(
ultrasound_dist_15(bytes, length));
chassis->mutable_ecu_status_4_518()->set_ultrasound_dist_16(
ultrasound_dist_16(bytes, length));
}
// config detail: {'bit': 0, 'description': 'Ultrasonic detection distance 9
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_9', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_9(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 8, 'description': 'Ultrasonic detection distance 10
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_10', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_10(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 16, 'description': 'Ultrasonic detection distance 11
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_11', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_11(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 24, 'description': 'Ultrasonic detection distance 12
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_12', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_12(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 32, 'description': 'Ultrasonic detection distance 13
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_13', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_13(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 40, 'description': 'Ultrasonic detection distance 14
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_14', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_14(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 48, 'description': 'Ultrasonic detection distance 15
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_15', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_15(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
// config detail: {'bit': 56, 'description': 'Ultrasonic detection distance 16
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ultrasound_dist_16', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double Ecustatus4518::ultrasound_dist_16(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
double ret = x * 2.000000;
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/brake_command_111.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/brake_command_111.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
const int32_t Brakecommand111::ID = 0x111;
// public
Brakecommand111::Brakecommand111() { Reset(); }
uint32_t Brakecommand111::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
void Brakecommand111::UpdateData(uint8_t* data) {
set_p_brake_pedal_en_ctrl(data, brake_pedal_en_ctrl_);
set_p_brake_pedal_cmd(data, brake_pedal_cmd_);
}
void Brakecommand111::Reset() {
// TODO(All) : you should check this manually
brake_pedal_en_ctrl_ = Brake_command_111::BRAKE_PEDAL_EN_CTRL_DISABLE;
brake_pedal_cmd_ = 0;
}
Brakecommand111* Brakecommand111::set_brake_pedal_en_ctrl(
Brake_command_111::Brake_pedal_en_ctrlType brake_pedal_en_ctrl) {
brake_pedal_en_ctrl_ = brake_pedal_en_ctrl;
return this;
}
// config detail: {'bit': 0, 'description': 'brake pedal enable bit(Command)',
// 'enum': {0: 'BRAKE_PEDAL_EN_CTRL_DISABLE', 1: 'BRAKE_PEDAL_EN_CTRL_ENABLE'},
// 'is_signed_var': False, 'len': 8, 'name': 'BRAKE_PEDAL_EN_CTRL', 'offset':
// 0.0, 'order': 'intel', 'physical_range': '[0|1]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
void Brakecommand111::set_p_brake_pedal_en_ctrl(
uint8_t* data,
Brake_command_111::Brake_pedal_en_ctrlType brake_pedal_en_ctrl) {
int x = brake_pedal_en_ctrl;
Byte to_set(data + 0);
to_set.set_value(x, 0, 8);
}
Brakecommand111* Brakecommand111::set_brake_pedal_cmd(int brake_pedal_cmd) {
brake_pedal_cmd_ = brake_pedal_cmd;
return this;
}
// config detail: {'bit': 8, 'description': 'Percentage of brake
// pedal(Command)', 'is_signed_var': False, 'len': 8, 'name': 'BRAKE_PEDAL_CMD',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|100]',
// 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
void Brakecommand111::set_p_brake_pedal_cmd(uint8_t* data,
int brake_pedal_cmd) {
brake_pedal_cmd = ProtocolData::BoundedValue(0, 100, brake_pedal_cmd);
int x = brake_pedal_cmd;
Byte to_set(data + 1);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_2_516.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/ecu_status_2_516.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Ecustatus2516::Ecustatus2516() {}
const int32_t Ecustatus2516::ID = 0x516;
void Ecustatus2516::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_ecu_status_2_516()->set_battery_soc(
battery_soc(bytes, length));
chassis->mutable_ecu_status_2_516()->set_battery_capacity(
battery_capacity(bytes, length));
chassis->mutable_ecu_status_2_516()->set_battery_voltage(
battery_voltage(bytes, length));
chassis->mutable_ecu_status_2_516()->set_battery_current(
battery_current(bytes, length));
chassis->mutable_ecu_status_2_516()->set_battery_temperature(
battery_temperature(bytes, length));
chassis->mutable_ecu_status_2_516()->set_is_battery_soc_low(
battery_soc(bytes, length) <= 15);
}
// config detail: {'bit': 0, 'description': 'Percentage of battery remaining
// (BMS status)', 'is_signed_var': False, 'len': 8, 'name': 'battery_soc',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|100]',
// 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
int Ecustatus2516::battery_soc(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'bit': 8, 'description': 'Battery full capacity (BMS
// status)', 'is_signed_var': False, 'len': 8, 'name': 'battery_capacity',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|100]',
// 'physical_unit': 'Ah', 'precision': 1.0, 'type': 'int'}
int Ecustatus2516::battery_capacity(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'bit': 16, 'description': 'Current battery voltage (BMS
// status)', 'is_signed_var': False, 'len': 16, 'name': 'battery_voltage',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|80]', 'physical_unit':
// 'V', 'precision': 0.1, 'type': 'double'}
double Ecustatus2516::battery_voltage(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
double ret = x * 0.100000;
return ret;
}
// config detail: {'bit': 32, 'description': 'Current battery current (BMS
// status)', 'is_signed_var': True, 'len': 16, 'name': 'battery_current',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[-60|60]',
// 'physical_unit': 'A', 'precision': 0.1, 'type': 'double'}
double Ecustatus2516::battery_current(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 4);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.100000;
return ret;
}
// config detail: {'bit': 48, 'description': 'Current battery temperature (BMS
// status)', 'is_signed_var': True, 'len': 16, 'name': 'battery_temperature',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[-40|110]',
// 'physical_unit': '℃', 'precision': 1.0, 'type': 'int'}
int Ecustatus2516::battery_temperature(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 6);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
int ret = x;
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_2_516_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/ecu_status_2_516.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Ecustatus2516Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Ecustatus2516Test, General) {
uint8_t data[8] = {0x01, 0x02, 0x03, 0x04, 0x01, 0x12, 0x13, 0x14};
int32_t length = 8;
Ch cd;
Ecustatus2516 ecustatus;
ecustatus.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000010);
EXPECT_EQ(data[2], 0b00000011);
EXPECT_EQ(data[3], 0b00000100);
EXPECT_EQ(data[4], 0b00000001);
EXPECT_EQ(data[5], 0b00010010);
EXPECT_EQ(data[6], 0b00010011);
EXPECT_EQ(data[7], 0b00010100);
EXPECT_EQ(cd.ecu_status_2_516().battery_soc(), 1);
EXPECT_EQ(cd.ecu_status_2_516().battery_capacity(), 2);
EXPECT_DOUBLE_EQ(cd.ecu_status_2_516().battery_voltage(), 102.7);
EXPECT_DOUBLE_EQ(cd.ecu_status_2_516().battery_current(),
460.90000000000003);
EXPECT_EQ(cd.ecu_status_2_516().battery_temperature(), 5139);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vin_resp2_51c.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <string>
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Vinresp251c : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Vinresp251c();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 56, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN16', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin16(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 48, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN15', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin15(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 40, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN14', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin14(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 32, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN13', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin13(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 24, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN12', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin12(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 16, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN11', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin11(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 8, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN10', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin10(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 0, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN09', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin09(const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vin_resp3_51d.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <string>
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Vinresp351d : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Vinresp351d();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'VIN17', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string vin17(const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_2_516.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Ecustatus2516 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Ecustatus2516();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'Percentage of battery remaining
// (BMS status)', 'is_signed_var': False, 'len': 8, 'name': 'BATTERY_SOC',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|100]',
// 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
int battery_soc(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 8, 'description': 'Battery full capacity (BMS
// status)', 'is_signed_var': False, 'len': 8, 'name': 'BATTERY_CAPACITY',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|100]',
// 'physical_unit': 'Ah', 'precision': 1.0, 'type': 'int'}
int battery_capacity(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 16, 'description': 'Current battery voltage (BMS
// status)', 'is_signed_var': False, 'len': 16, 'name': 'BATTERY_VOLTAGE',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|80]',
// 'physical_unit': 'V', 'precision': 0.1, 'type': 'double'}
double battery_voltage(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 32, 'description': 'Current battery current (BMS
// status)', 'is_signed_var': True, 'len': 16, 'name': 'BATTERY_CURRENT',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[-60|60]',
// 'physical_unit': 'A', 'precision': 0.1, 'type': 'double'}
double battery_current(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 48, 'description': 'Current battery temperature (BMS
// status)', 'is_signed_var': True, 'len': 16, 'name': 'BATTERY_TEMPERATURE',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[-40|110]',
// 'physical_unit': '℃', 'precision': 1.0, 'type': 'int'}
int battery_temperature(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
CANBUS_COPTS = ["-DMODULE_NAME=\\\"canbus\\\""]
cc_library(
name = "canbus_ch_protocol",
deps = [
":brake_command_111",
":brake_status__511",
":ecu_status_1_515",
":ecu_status_2_516",
":ecu_status_3_517",
":ecu_status_4_518",
":gear_command_114",
":gear_status_514",
":steer_command_112",
":steer_status__512",
":throttle_command_110",
":throttle_status__510",
":turnsignal_command_113",
":turnsignal_status__513",
":vehicle_mode_command_116",
":vin_resp1_51b",
":vin_resp2_51c",
":vin_resp3_51d",
":wheelspeed_report_51e",
],
)
cc_library(
name = "brake_command_111",
srcs = ["brake_command_111.cc"],
hdrs = ["brake_command_111.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "brake_command_111_test",
size = "small",
srcs = ["brake_command_111_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "brake_status__511",
srcs = ["brake_status__511.cc"],
hdrs = ["brake_status__511.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "brake_status__511_test",
size = "small",
srcs = ["brake_status__511_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "ecu_status_1_515",
srcs = ["ecu_status_1_515.cc"],
hdrs = ["ecu_status_1_515.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "ecu_status_1_515_test",
size = "small",
srcs = ["ecu_status_1_515_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "ecu_status_2_516",
srcs = ["ecu_status_2_516.cc"],
hdrs = ["ecu_status_2_516.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "ecu_status_2_516_test",
size = "small",
srcs = ["ecu_status_2_516_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "ecu_status_3_517",
srcs = ["ecu_status_3_517.cc"],
hdrs = ["ecu_status_3_517.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "ecu_status_3_517_test",
size = "small",
srcs = ["ecu_status_3_517_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "ecu_status_4_518",
srcs = ["ecu_status_4_518.cc"],
hdrs = ["ecu_status_4_518.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_library(
name = "gear_command_114",
srcs = ["gear_command_114.cc"],
hdrs = ["gear_command_114.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "gear_command_114_test",
size = "small",
srcs = ["gear_command_114_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "gear_status_514",
srcs = ["gear_status_514.cc"],
hdrs = ["gear_status_514.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "gear_status_514_test",
size = "small",
srcs = ["gear_status_514_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "steer_command_112",
srcs = ["steer_command_112.cc"],
hdrs = ["steer_command_112.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "steer_command_112_test",
size = "small",
srcs = ["steer_command_112_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "steer_status__512",
srcs = ["steer_status__512.cc"],
hdrs = ["steer_status__512.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "steer_status__512_test",
size = "small",
srcs = ["steer_status__512_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "throttle_command_110",
srcs = ["throttle_command_110.cc"],
hdrs = ["throttle_command_110.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "throttle_command_110_test",
size = "small",
srcs = ["throttle_command_110_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "throttle_status__510",
srcs = ["throttle_status__510.cc"],
hdrs = ["throttle_status__510.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "throttle_status__510_test",
size = "small",
srcs = ["throttle_status__510_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "turnsignal_command_113",
srcs = ["turnsignal_command_113.cc"],
hdrs = ["turnsignal_command_113.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "turnsignal_command_113_test",
size = "small",
srcs = ["turnsignal_command_113_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
linkstatic = True,
)
cc_library(
name = "turnsignal_status__513",
srcs = ["turnsignal_status__513.cc"],
hdrs = ["turnsignal_status__513.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "turnsignal_status__513_test",
size = "small",
srcs = ["turnsignal_status__513_test.cc"],
deps = [
"//modules/canbus_vehicle/ch/protocol:canbus_ch_protocol",
"@com_google_googletest//:gtest_main",
],
)
cc_library(
name = "vehicle_mode_command_116",
srcs = ["vehicle_mode_command_116.cc"],
hdrs = ["vehicle_mode_command_116.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_library(
name = "vin_resp1_51b",
srcs = ["vin_resp1_51b.cc"],
hdrs = ["vin_resp1_51b.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_library(
name = "vin_resp2_51c",
srcs = ["vin_resp2_51c.cc"],
hdrs = ["vin_resp2_51c.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_library(
name = "vin_resp3_51d",
srcs = ["vin_resp3_51d.cc"],
hdrs = ["vin_resp3_51d.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_library(
name = "wheelspeed_report_51e",
srcs = ["wheelspeed_report_51e.cc"],
hdrs = ["wheelspeed_report_51e.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/ch/proto:ch_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_1_515.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Ecustatus1515 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Ecustatus1515();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'Current speed (Steering status)',
// 'is_signed_var': True, 'len': 16, 'name': 'SPEED', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double speed(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 16, 'description': 'Current acceleration (Steering
// status)', 'is_signed_var': True, 'len': 16, 'name': 'ACC_SPEED', 'offset':
// 0.0, 'order': 'intel', 'physical_range': '[0|0]', 'physical_unit': 'm/s^2',
// 'precision': 0.001, 'type': 'double'}
double acc_speed(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 32, 'description': 'Current Auto-mode state (Chassis
// status)', 'enum': {0: 'CTRL_STS_OUT_OF_CONTROL', 1:
// 'CTRL_STS_UNDER_CONTROL'}, 'is_signed_var': False, 'len': 8, 'name':
// 'CTRL_STS', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Ctrl_stsType ctrl_sts(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 40, 'description': 'Current chassis state (Chassis
// status)', 'is_signed_var': False, 'len': 8, 'name': 'CHASSIS_STS',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|255]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int chassis_sts(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 48, 'description': 'Chassis error code (Chassis
// status)', 'is_signed_var': False, 'len': 16, 'name': 'CHASSIS_ERR',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|65535]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'int'}
int chassis_err(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 48, 'description': 'Chassis error code (Chassis
// status)', 'enum': {0: 'CHASSIS_ADS_ERR_NOMAL', 1:
// 'CHASSIS_ADS_ERR_ADS_CAN_LOST', 2: 'CHASSIS_ADS_ERR_ADS_CAN_RECOVERY'},
// 'is_signed_var': False, 'len': 2, 'name': 'CHASSIS_ADS_ERR', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_ads_errType chassis_ads_err(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 50, 'enum': {0: 'CHASSIS_BMS_CAN_NORMAL', 1:
// 'CHASSIS_BMS_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_BMS_CAN', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_bms_canType chassis_bms_can(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 51, 'enum': {0: 'CHASSIS_EHB_CAN_NORMAL', 1:
// 'CHASSIS_EHB_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_EHB_CAN', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_ehb_canType chassis_ehb_can(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 52, 'enum': {0: 'CHASSIS_EHB_ERR_NORMAL', 1:
// 'CHASSIS_EHB_ERR_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_EHB_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_ehb_errType chassis_ehb_err(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 53, 'enum': {0: 'CHASSIS_EPS_CAN_NORMAL', 1:
// 'CHASSIS_EPS_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_EPS_CAN', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_eps_canType chassis_eps_can(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 54, 'enum': {0: 'CHASSIS_EPS_ERR_NORMAL', 1:
// 'CHASSIS_EPS_ERR_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_EPS_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_eps_errType chassis_eps_err(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 55, 'enum': {0: 'CHASSIS_HW_LOST_NORMAL', 1:
// 'CHASSIS_HW_LOST_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_HW_Lost', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_hw_lostType chassis_hw_lost(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 56, 'enum': {0: 'CHASSIS_MCU_CAN_NORMAL', 1:
// 'CHASSIS_MCU_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_MCU_CAN', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_mcu_canType chassis_mcu_can(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 57, 'enum': {0: 'CHASSIS_MCU_ERR_NORMAL', 1:
// 'CHASSIS_MCU_ERR_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'CHASSIS_MCU_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_mcu_errType chassis_mcu_err(
const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/brake_command_111_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/brake_command_111.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Brakecommand111Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Brakecommand111Test, simple) {
Brakecommand111 brake;
EXPECT_EQ(brake.GetPeriod(), 20 * 1000);
uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68};
brake.UpdateData(data);
EXPECT_EQ(data[0], 0b00000000);
EXPECT_EQ(data[1], 0b00000000);
EXPECT_EQ(data[2], 0b01100011);
EXPECT_EQ(data[3], 0b01100100);
EXPECT_EQ(data[4], 0b01100101);
EXPECT_EQ(data[5], 0b01100110);
EXPECT_EQ(data[6], 0b01100111);
EXPECT_EQ(data[7], 0b01101000);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/gear_command_114.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Gearcommand114 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Gearcommand114();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'bit': 0, 'description': 'PRND control(Command)', 'enum':
// {1: 'GEAR_CMD_PARK', 2: 'GEAR_CMD_REVERSE', 3: 'GEAR_CMD_NEUTRAL', 4:
// 'GEAR_CMD_DRIVE'}, 'is_signed_var': False, 'len': 8, 'name': 'GEAR_CMD',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[1|4]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Gearcommand114* set_gear_cmd(Gear_command_114::Gear_cmdType gear_cmd);
private:
// config detail: {'bit': 0, 'description': 'PRND control(Command)', 'enum':
// {1: 'GEAR_CMD_PARK', 2: 'GEAR_CMD_REVERSE', 3: 'GEAR_CMD_NEUTRAL', 4:
// 'GEAR_CMD_DRIVE'}, 'is_signed_var': False, 'len': 8, 'name': 'GEAR_CMD',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[1|4]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
void set_p_gear_cmd(uint8_t* data, Gear_command_114::Gear_cmdType gear_cmd);
private:
Gear_command_114::Gear_cmdType gear_cmd_;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/steer_command_112_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/steer_command_112.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Steercommand112Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Steercommand112Test, simple) {
Steercommand112 steercommand;
EXPECT_EQ(steercommand.GetPeriod(), 20 * 1000);
uint8_t data[8] = {0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68};
steercommand.UpdateData(data);
EXPECT_EQ(data[0], 0b00000000);
EXPECT_EQ(data[1], 0b00000000);
EXPECT_EQ(data[2], 0b00000000);
EXPECT_EQ(data[3], 0b01100100);
EXPECT_EQ(data[4], 0b01100101);
EXPECT_EQ(data[5], 0b01100110);
EXPECT_EQ(data[6], 0b01100111);
EXPECT_EQ(data[7], 0b01101000);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vehicle_mode_command_116.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Vehiclemodecommand116 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Vehiclemodecommand116();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'bit': 0, 'description': 'Request VIN(Command)', 'enum':
// {0: 'VIN_REQ_CMD_VIN_REQ_DISABLE', 1: 'VIN_REQ_CMD_VIN_REQ_ENABLE'},
// 'is_signed_var': False, 'len': 1, 'name': 'VIN_REQ_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|1]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
Vehiclemodecommand116* set_vin_req_cmd(
Vehicle_mode_command_116::Vin_req_cmdType vin_req_cmd);
private:
// config detail: {'bit': 0, 'description': 'Request VIN(Command)', 'enum':
// {0: 'VIN_REQ_CMD_VIN_REQ_DISABLE', 1: 'VIN_REQ_CMD_VIN_REQ_ENABLE'},
// 'is_signed_var': False, 'len': 1, 'name': 'VIN_REQ_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|1]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
void set_p_vin_req_cmd(uint8_t* data,
Vehicle_mode_command_116::Vin_req_cmdType vin_req_cmd);
private:
Vehicle_mode_command_116::Vin_req_cmdType vin_req_cmd_;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/turnsignal_status__513.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/turnsignal_status__513.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Turnsignalstatus513::Turnsignalstatus513() {}
const int32_t Turnsignalstatus513::ID = 0x513;
void Turnsignalstatus513::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_turnsignal_status__513()->set_turn_signal_sts(
turn_signal_sts(bytes, length));
chassis->mutable_turnsignal_status__513()->set_low_beam_sts(
low_beam_sts(bytes, length));
}
// config detail: {'bit': 0, 'description': 'Lighting control(Status)', 'enum':
// {0: 'TURN_SIGNAL_STS_NONE', 1: 'TURN_SIGNAL_STS_LEFT', 2:
// 'TURN_SIGNAL_STS_RIGHT', 3: 'TURN_SIGNAL_STS_HAZARD_WARNING_LAMPSTS_ON'},
// 'is_signed_var': False, 'len': 8, 'name': 'turn_signal_sts', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
Turnsignal_status__513::Turn_signal_stsType
Turnsignalstatus513::turn_signal_sts(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
Turnsignal_status__513::Turn_signal_stsType ret =
static_cast<Turnsignal_status__513::Turn_signal_stsType>(x);
return ret;
}
// config detail: {'bit': 8, 'description': 'Lighting control(Status)', 'enum':
// {0: 'LOW_BEAM_STS_ON', 1: 'LOW_BEAM_STS_OFF'}, 'is_signed_var': False, 'len':
// 2, 'name': 'low_beam_sts', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|2]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Turnsignal_status__513::Low_beam_stsType Turnsignalstatus513::low_beam_sts(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 2);
Turnsignal_status__513::Low_beam_stsType ret =
static_cast<Turnsignal_status__513::Low_beam_stsType>(x);
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/brake_command_111.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Brakecommand111 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Brakecommand111();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'bit': 0, 'description': 'brake pedal enable bit(Command)',
// 'enum': {0: 'BRAKE_PEDAL_EN_CTRL_DISABLE', 1:
// 'BRAKE_PEDAL_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'BRAKE_PEDAL_EN_CTRL', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Brakecommand111* set_brake_pedal_en_ctrl(
Brake_command_111::Brake_pedal_en_ctrlType brake_pedal_en_ctrl);
// config detail: {'bit': 8, 'description': 'Percentage of brake
// pedal(Command)', 'is_signed_var': False, 'len': 8, 'name':
// 'BRAKE_PEDAL_CMD', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
Brakecommand111* set_brake_pedal_cmd(int brake_pedal_cmd);
private:
// config detail: {'bit': 0, 'description': 'brake pedal enable bit(Command)',
// 'enum': {0: 'BRAKE_PEDAL_EN_CTRL_DISABLE', 1:
// 'BRAKE_PEDAL_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'BRAKE_PEDAL_EN_CTRL', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
void set_p_brake_pedal_en_ctrl(
uint8_t* data,
Brake_command_111::Brake_pedal_en_ctrlType brake_pedal_en_ctrl);
// config detail: {'bit': 8, 'description': 'Percentage of brake
// pedal(Command)', 'is_signed_var': False, 'len': 8, 'name':
// 'BRAKE_PEDAL_CMD', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
void set_p_brake_pedal_cmd(uint8_t* data, int brake_pedal_cmd);
private:
Brake_command_111::Brake_pedal_en_ctrlType brake_pedal_en_ctrl_;
int brake_pedal_cmd_;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_1_515.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/ecu_status_1_515.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Ecustatus1515::Ecustatus1515() {}
const int32_t Ecustatus1515::ID = 0x515;
void Ecustatus1515::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_ecu_status_1_515()->set_chassis_mcu_err(
chassis_mcu_err(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_mcu_can(
chassis_mcu_can(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_hw_lost(
chassis_hw_lost(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_eps_err(
chassis_eps_err(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_eps_can(
chassis_eps_can(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_ehb_err(
chassis_ehb_err(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_ehb_can(
chassis_ehb_can(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_bms_can(
chassis_bms_can(bytes, length));
chassis->mutable_ecu_status_1_515()->set_speed(
speed(bytes, length));
chassis->mutable_ecu_status_1_515()->set_acc_speed(
acc_speed(bytes, length));
chassis->mutable_ecu_status_1_515()->set_ctrl_sts(
ctrl_sts(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_sts(
chassis_sts(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_err(
chassis_err(bytes, length));
chassis->mutable_ecu_status_1_515()->set_chassis_ads_err(
chassis_ads_err(bytes, length));
}
// config detail: {'bit': 0, 'description': 'Current speed (Steering status)',
// 'is_signed_var': True, 'len': 16, 'name': 'speed', 'offset': 0.0, 'order':
// 'intel', 'physical_range': '[-327.68|327.67]', 'physical_unit': 'm/s',
// 'precision': 0.01, 'type': 'double'}
double Ecustatus1515::speed(const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 0);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.010000;
return ret;
}
// config detail: {'bit': 16, 'description': 'Current acceleration (Steering
// status)', 'is_signed_var': True, 'len': 16, 'name': 'acc_speed', 'offset':
// 0.0, 'order': 'intel', 'physical_range': '[0|0]', 'physical_unit': 'm/s^2',
// 'precision': 0.001, 'type': 'double'}
double Ecustatus1515::acc_speed(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.001000;
return ret;
}
// config detail: {'bit': 32, 'description': 'Current Auto-mode state (Chassis
// status)', 'enum': {0: 'CTRL_STS_OUT_OF_CONTROL', 1:
// 'CTRL_STS_UNDER_CONTROL'}, 'is_signed_var': False, 'len': 8, 'name':
// 'ctrl_sts', 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|1]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Ctrl_stsType Ecustatus1515::ctrl_sts(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
Ecu_status_1_515::Ctrl_stsType ret =
static_cast<Ecu_status_1_515::Ctrl_stsType>(x);
return ret;
}
// config detail: {'bit': 40, 'description': 'Current chassis state (Chassis
// status)', 'is_signed_var': False, 'len': 8, 'name': 'chassis_sts', 'offset':
// 0.0, 'order': 'intel', 'physical_range': '[0|255]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'int'}
int Ecustatus1515::chassis_sts(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'bit': 48, 'description': 'Chassis error code (Chassis
// status)', 'is_signed_var': False, 'len': 16, 'name': 'chassis_err', 'offset':
// 0.0, 'order': 'intel', 'physical_range': '[0|65535]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'int'}
int Ecustatus1515::chassis_err(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 6);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
int ret = x;
return ret;
}
// config detail: {'bit': 48, 'description': 'Chassis error code (Chassis
// status)', 'enum': {0: 'CHASSIS_ADS_ERR_NOMAL', 1:
// 'CHASSIS_ADS_ERR_ADS_CAN_LOST', 2: 'CHASSIS_ADS_ERR_ADS_CAN_RECOVERY'},
// 'is_signed_var': False, 'len': 2, 'name': 'chassis_ads_err', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[0|2]', 'physical_unit': '',
// 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_ads_errType Ecustatus1515::chassis_ads_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 2);
Ecu_status_1_515::Chassis_ads_errType ret =
static_cast<Ecu_status_1_515::Chassis_ads_errType>(x);
return ret;
}
// config detail: {'bit': 50, 'enum': {0: 'CHASSIS_BMS_CAN_NORMAL', 1:
// 'CHASSIS_BMS_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_bms_can', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_bms_canType Ecustatus1515::chassis_bms_can(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(2, 1);
Ecu_status_1_515::Chassis_bms_canType ret =
static_cast<Ecu_status_1_515::Chassis_bms_canType>(x);
return ret;
}
// config detail: {'bit': 51, 'enum': {0: 'CHASSIS_EHB_CAN_NORMAL', 1:
// 'CHASSIS_EHB_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_ehb_can', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_ehb_canType Ecustatus1515::chassis_ehb_can(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(3, 1);
Ecu_status_1_515::Chassis_ehb_canType ret =
static_cast<Ecu_status_1_515::Chassis_ehb_canType>(x);
return ret;
}
// config detail: {'bit': 52, 'enum': {0: 'CHASSIS_EHB_ERR_NORMAL', 1:
// 'CHASSIS_EHB_ERR_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_ehb_err', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_ehb_errType Ecustatus1515::chassis_ehb_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(4, 1);
Ecu_status_1_515::Chassis_ehb_errType ret =
static_cast<Ecu_status_1_515::Chassis_ehb_errType>(x);
return ret;
}
// config detail: {'bit': 53, 'enum': {0: 'CHASSIS_EPS_CAN_NORMAL', 1:
// 'CHASSIS_EPS_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_eps_can', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_eps_canType Ecustatus1515::chassis_eps_can(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(5, 1);
Ecu_status_1_515::Chassis_eps_canType ret =
static_cast<Ecu_status_1_515::Chassis_eps_canType>(x);
return ret;
}
// config detail: {'bit': 54, 'enum': {0: 'CHASSIS_EPS_ERR_NORMAL', 1:
// 'CHASSIS_EPS_ERR_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_eps_err', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_eps_errType Ecustatus1515::chassis_eps_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(6, 1);
Ecu_status_1_515::Chassis_eps_errType ret =
static_cast<Ecu_status_1_515::Chassis_eps_errType>(x);
return ret;
}
// config detail: {'bit': 55, 'enum': {0: 'CHASSIS_HW_LOST_NORMAL', 1:
// 'CHASSIS_HW_LOST_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_hw_lost', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_hw_lostType Ecustatus1515::chassis_hw_lost(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(7, 1);
Ecu_status_1_515::Chassis_hw_lostType ret =
static_cast<Ecu_status_1_515::Chassis_hw_lostType>(x);
return ret;
}
// config detail: {'bit': 56, 'enum': {0: 'CHASSIS_MCU_CAN_NORMAL', 1:
// 'CHASSIS_MCU_CAN_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_mcu_can', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_mcu_canType Ecustatus1515::chassis_mcu_can(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 1);
Ecu_status_1_515::Chassis_mcu_canType ret =
static_cast<Ecu_status_1_515::Chassis_mcu_canType>(x);
return ret;
}
// config detail: {'bit': 57, 'enum': {0: 'CHASSIS_MCU_ERR_NORMAL', 1:
// 'CHASSIS_MCU_ERR_ERROR'}, 'is_signed_var': False, 'len': 1, 'name':
// 'chassis_mcu_err', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Ecu_status_1_515::Chassis_mcu_errType Ecustatus1515::chassis_mcu_err(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(1, 1);
Ecu_status_1_515::Chassis_mcu_errType ret =
static_cast<Ecu_status_1_515::Chassis_mcu_errType>(x);
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/ecu_status_4_518.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Ecustatus4518 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Ecustatus4518();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'Ultrasonic detection distance 9
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_9', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_9(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 8, 'description': 'Ultrasonic detection distance 10
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_10', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_10(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 16, 'description': 'Ultrasonic detection distance 11
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_11', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_11(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 24, 'description': 'Ultrasonic detection distance 12
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_12', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_12(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 32, 'description': 'Ultrasonic detection distance 13
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_13', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_13(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 40, 'description': 'Ultrasonic detection distance 14
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_14', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_14(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 48, 'description': 'Ultrasonic detection distance 15
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_15', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_15(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'bit': 56, 'description': 'Ultrasonic detection distance 16
// (Ultrasound status)', 'is_signed_var': False, 'len': 8, 'name':
// 'ULTRASOUND_DIST_16', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|500]', 'physical_unit': 'cm', 'precision': 2.0, 'type': 'double'}
double ultrasound_dist_16(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/steer_command_112.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Steercommand112 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Steercommand112();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'bit': 0, 'description': 'steering angle enable
// bit(Command)', 'enum': {0: 'STEER_ANGLE_EN_CTRL_DISABLE', 1:
// 'STEER_ANGLE_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'STEER_ANGLE_EN_CTRL', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Steercommand112* set_steer_angle_en_ctrl(
Steer_command_112::Steer_angle_en_ctrlType steer_angle_en_ctrl);
// config detail: {'bit': 8, 'description': 'Current steering angle(Command)',
// 'is_signed_var': True, 'len': 16, 'name': 'STEER_ANGLE_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[-0.524|0.524]', 'physical_unit':
// 'radian', 'precision': 0.001, 'type': 'double'}
Steercommand112* set_steer_angle_cmd(double steer_angle_cmd);
private:
// config detail: {'bit': 0, 'description': 'steering angle enable
// bit(Command)', 'enum': {0: 'STEER_ANGLE_EN_CTRL_DISABLE', 1:
// 'STEER_ANGLE_EN_CTRL_ENABLE'}, 'is_signed_var': False, 'len': 8, 'name':
// 'STEER_ANGLE_EN_CTRL', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
void set_p_steer_angle_en_ctrl(
uint8_t* data,
Steer_command_112::Steer_angle_en_ctrlType steer_angle_en_ctrl);
// config detail: {'bit': 8, 'description': 'Current steering angle(Command)',
// 'is_signed_var': True, 'len': 16, 'name': 'STEER_ANGLE_CMD', 'offset': 0.0,
// 'order': 'intel', 'physical_range': '[-0.524|0.524]', 'physical_unit':
// 'radian', 'precision': 0.001, 'type': 'double'}
void set_p_steer_angle_cmd(uint8_t* data, double steer_angle_cmd);
private:
Steer_command_112::Steer_angle_en_ctrlType steer_angle_en_ctrl_;
double steer_angle_cmd_;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/throttle_status__510.h
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/ch/proto/ch.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace ch {
class Throttlestatus510 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Ch> {
public:
static const int32_t ID;
Throttlestatus510();
void Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const override;
private:
// config detail: {'bit': 0, 'description': 'throttle pedal enable
// bit(Status)', 'enum': {0: 'THROTTLE_PEDAL_EN_STS_DISABLE', 1:
// 'THROTTLE_PEDAL_EN_STS_ENABLE', 2: 'THROTTLE_PEDAL_EN_STS_TAKEOVER'},
// 'is_signed_var': False, 'len': 8, 'name': 'THROTTLE_PEDAL_EN_STS',
// 'offset': 0.0, 'order': 'intel', 'physical_range': '[0|2]',
// 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Throttle_status__510::Throttle_pedal_en_stsType throttle_pedal_en_sts(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 8, 'description': 'Percentage of throttle
// pedal(Status)', 'is_signed_var': False, 'len': 8, 'name':
// 'THROTTLE_PEDAL_STS', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|100]', 'physical_unit': '%', 'precision': 1.0, 'type': 'int'}
int throttle_pedal_sts(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 16, 'enum': {0: 'DRIVE_MOTOR_ERR_NOERR', 1:
// 'DRIVE_MOTOR_ERR_DRV_MOTOR_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'DRIVE_MOTOR_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Throttle_status__510::Drive_motor_errType drive_motor_err(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'bit': 24, 'enum': {0: 'BATTERY_BMS_ERR_NOERR', 1:
// 'BATTERY_BMS_ERR_BATTERY_ERR'}, 'is_signed_var': False, 'len': 8, 'name':
// 'BATTERY_BMS_ERR', 'offset': 0.0, 'order': 'intel', 'physical_range':
// '[0|1]', 'physical_unit': '', 'precision': 1.0, 'type': 'enum'}
Throttle_status__510::Battery_bms_errType battery_bms_err(
const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/steer_status__512_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/steer_status__512.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Steerstatus512Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Steerstatus512Test, General) {
uint8_t data[8] = {0x01, 0x02, 0x03, 0x01, 0x00, 0x12, 0x13, 0x14};
int32_t length = 8;
Ch cd;
Steerstatus512 steerstatus;
steerstatus.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000010);
EXPECT_EQ(data[2], 0b00000011);
EXPECT_EQ(data[3], 0b00000001);
EXPECT_EQ(data[4], 0b00000000);
EXPECT_EQ(data[5], 0b00010010);
EXPECT_EQ(data[6], 0b00010011);
EXPECT_EQ(data[7], 0b00010100);
EXPECT_EQ(cd.steer_status__512().steer_angle_en_sts(), 1);
EXPECT_DOUBLE_EQ(cd.steer_status__512().steer_angle_sts(),
0.77000000000000002);
EXPECT_EQ(cd.steer_status__512().steer_err(), 1);
EXPECT_EQ(cd.steer_status__512().sensor_err(), 0);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/brake_status__511_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/brake_status__511.h"
#include "gtest/gtest.h"
namespace apollo {
namespace canbus {
namespace ch {
class Brakestatus511Test : public ::testing::Test {
public:
virtual void SetUp() {}
};
TEST_F(Brakestatus511Test, General) {
uint8_t data[8] = {0x01, 0x02, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01};
int32_t length = 8;
Ch cd;
Brakestatus511 brake;
brake.Parse(data, length, &cd);
EXPECT_EQ(data[0], 0b00000001);
EXPECT_EQ(data[1], 0b00000010);
EXPECT_EQ(data[2], 0b00000001);
EXPECT_EQ(data[3], 0b00000000);
EXPECT_EQ(data[4], 0b00000001);
EXPECT_EQ(data[5], 0b00000001);
EXPECT_EQ(data[6], 0b00000000);
EXPECT_EQ(data[7], 0b00000001);
EXPECT_EQ(cd.brake_status__511().brake_pedal_en_sts(), 1);
EXPECT_EQ(cd.brake_status__511().brake_pedal_sts(), 2);
EXPECT_EQ(cd.brake_status__511().brake_err(), 1);
EXPECT_EQ(cd.brake_status__511().emergency_btn_env(), 0);
EXPECT_EQ(cd.brake_status__511().front_bump_env(), 1);
EXPECT_EQ(cd.brake_status__511().back_bump_env(), 1);
EXPECT_EQ(cd.brake_status__511().overspd_env(), 0);
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch
|
apollo_public_repos/apollo/modules/canbus_vehicle/ch/protocol/vin_resp3_51d.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/ch/protocol/vin_resp3_51d.h"
#include <string>
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace ch {
using ::apollo::drivers::canbus::Byte;
Vinresp351d::Vinresp351d() {}
const int32_t Vinresp351d::ID = 0x51D;
void Vinresp351d::Parse(const std::uint8_t* bytes, int32_t length,
Ch* chassis) const {
chassis->mutable_vin_resp3_51d()->set_vin17(
vin17(bytes, length));
}
// config detail: {'bit': 0, 'description': 'VIN Response', 'is_signed_var':
// False, 'len': 8, 'name': 'vin17', 'offset': 0.0, 'order': 'intel',
// 'physical_range': '[0|0]', 'physical_unit': '', 'precision': 1.0, 'type':
// 'int'}
std::string Vinresp351d::vin17(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
std::string ret = "";
ret += x;
return ret;
}
} // namespace ch
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_message_manager.h
|
/* Copyright 2018 The Apollo Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#pragma once
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::MessageManager;
class TransitMessageManager
: public MessageManager<::apollo::canbus::Transit> {
public:
TransitMessageManager();
virtual ~TransitMessageManager();
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_controller.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <memory>
#include <thread>
#include "modules/canbus/vehicle/vehicle_controller.h"
#include "modules/canbus/proto/canbus_conf.pb.h"
#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
#include "modules/canbus/proto/vehicle_parameter.pb.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
#include "modules/canbus_vehicle/transit/protocol/adc_auxiliarycontrol_110.h"
#include "modules/canbus_vehicle/transit/protocol/adc_motioncontrol1_10.h"
#include "modules/canbus_vehicle/transit/protocol/adc_motioncontrollimits1_12.h"
#include "modules/canbus_vehicle/transit/protocol/llc_diag_brakecontrol_721.h"
#include "modules/canbus_vehicle/transit/protocol/llc_diag_steeringcontrol_722.h"
namespace apollo {
namespace canbus {
namespace transit {
class TransitController final
: public VehicleController<::apollo::canbus::Transit> {
public:
TransitController() {}
virtual ~TransitController();
::apollo::common::ErrorCode Init(
const VehicleParameter& params,
CanSender<::apollo::canbus::Transit>* const can_sender,
MessageManager<::apollo::canbus::Transit>* const message_manager)
override;
bool Start() override;
/**
* @brief stop the vehicle controller.
*/
void Stop() override;
/**
* @brief calculate and return the chassis.
* @returns a copy of chassis. Use copy here to avoid multi-thread issues.
*/
Chassis chassis() override;
FRIEND_TEST(TransitControllerTest, SetDrivingMode);
FRIEND_TEST(TransitControllerTest, Status);
FRIEND_TEST(TransitControllerTest, UpdateDrivingMode);
private:
// main logical function for operation the car enter or exit the auto driving
void Emergency() override;
::apollo::common::ErrorCode EnableAutoMode() override;
::apollo::common::ErrorCode DisableAutoMode() override;
::apollo::common::ErrorCode EnableSteeringOnlyMode() override;
::apollo::common::ErrorCode EnableSpeedOnlyMode() override;
// NEUTRAL, REVERSE, DRIVE
void Gear(Chassis::GearPosition state) override;
// brake with new acceleration
// acceleration:0.00~99.99, unit:
// acceleration_spd: 60 ~ 100, suggest: 90
void Brake(double acceleration) override;
// drive with old acceleration
// gas:0.00~99.99 unit:
void Throttle(double throttle) override;
// drive with acceleration/deceleration
// acc:-7.0~5.0 unit:m/s^2
void Acceleration(double acc) override;
// steering with old angle speed
// angle:-99.99~0.00~99.99, unit:, left:+, right:-
void Steer(double angle) override;
// steering with new angle speed
// angle:-99.99~0.00~99.99, unit:, left:+, right:-
// angle_spd:0.00~99.99, unit:deg/s
void Steer(double angle, double angle_spd) override;
// set Electrical Park Brake
void SetEpbBreak(const ::apollo::control::ControlCommand& command) override;
void SetBeam(const ::apollo::control::ControlCommand& command) override;
void SetHorn(const ::apollo::control::ControlCommand& command) override;
void SetTurningSignal(
const ::apollo::control::ControlCommand& command) override;
bool VerifyID() override;
void ResetProtocol();
bool CheckChassisError();
bool CheckSafetyError(const canbus::Transit& chassis);
void SetLimits() override;
private:
void SecurityDogThreadFunc();
virtual bool CheckResponse();
void set_chassis_error_mask(const int32_t mask);
int32_t chassis_error_mask();
Chassis::ErrorCode chassis_error_code();
void set_chassis_error_code(const Chassis::ErrorCode& error_code);
private:
// control protocol
Adcauxiliarycontrol110* adc_auxiliarycontrol_110_ = nullptr;
Adcmotioncontrol110* adc_motioncontrol1_10_ = nullptr;
Adcmotioncontrollimits112* adc_motioncontrollimits1_12_ = nullptr;
Llcdiagbrakecontrol721* llc_diag_brakecontrol_721_ = nullptr;
Llcdiagsteeringcontrol722* llc_diag_steeringcontrol_722_ = nullptr;
Chassis chassis_;
std::unique_ptr<std::thread> thread_;
bool is_chassis_error_ = false;
std::mutex chassis_error_code_mutex_;
Chassis::ErrorCode chassis_error_code_ = Chassis::NO_ERROR;
std::mutex chassis_mask_mutex_;
int32_t chassis_error_mask_ = 0;
bool received_vin_ = false;
bool button_pressed_ = false;
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_vehicle_factory.h
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
/**
* @file transit_vehicle_factory.h
*/
#pragma once
#include <memory>
#include "modules/canbus/proto/canbus_conf.pb.h"
#include "modules/canbus/proto/vehicle_parameter.pb.h"
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
#include "cyber/cyber.h"
#include "modules/canbus/vehicle/abstract_vehicle_factory.h"
#include "modules/canbus/vehicle/vehicle_controller.h"
#include "modules/common/status/status.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_comm/can_receiver.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
/**
* @namespace apollo::canbus
* @brief apollo::canbus
*/
namespace apollo {
namespace canbus {
/**
* @class TransitVehicleFactory
*
* @brief this class is inherited from AbstractVehicleFactory. It can be used to
* create controller and message manager for transit vehicle.
*/
class TransitVehicleFactory : public AbstractVehicleFactory {
public:
/**
* @brief destructor
*/
virtual ~TransitVehicleFactory() = default;
/**
* @brief init vehicle factory
* @returns true if successfully initialized
*/
bool Init(const CanbusConf *canbus_conf) override;
/**
* @brief start canclient, cansender, canreceiver, vehicle controller
* @returns true if successfully started
*/
bool Start() override;
/**
* @brief create ch vehicle controller
* @returns a unique_ptr that points to the created controller
*/
void Stop() override;
/**
* @brief update control command
*/
void UpdateCommand(
const apollo::control::ControlCommand *control_command) override;
/**
* @brief publish chassis messages
*/
Chassis publish_chassis() override;
/**
* @brief publish chassis for vehicle messages
*/
void PublishChassisDetail() override;
private:
/**
* @brief create transit vehicle controller
* @returns a unique_ptr that points to the created controller
*/
std::unique_ptr<VehicleController<::apollo::canbus::Transit>>
CreateVehicleController();
/**
* @brief create transit message manager
* @returns a unique_ptr that points to the created message manager
*/
std::unique_ptr<MessageManager<::apollo::canbus::Transit>>
CreateMessageManager();
std::unique_ptr<::apollo::cyber::Node> node_ = nullptr;
std::unique_ptr<apollo::drivers::canbus::CanClient> can_client_;
CanSender<::apollo::canbus::Transit> can_sender_;
apollo::drivers::canbus::CanReceiver<::apollo::canbus::Transit> can_receiver_;
std::unique_ptr<MessageManager<::apollo::canbus::Transit>> message_manager_;
std::unique_ptr<VehicleController<::apollo::canbus::Transit>>
vehicle_controller_;
std::shared_ptr<::apollo::cyber::Writer<::apollo::canbus::Transit>>
chassis_detail_writer_;
};
CYBER_REGISTER_VEHICLEFACTORY(TransitVehicleFactory)
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/cyberfile.xml
|
<package format="2">
<name>canbus-vehicle-transit</name>
<version>local</version>
<description>
Dynamic loading for canbus module
</description>
<maintainer email="apollo-support@baidu.com">Apollo</maintainer>
<license>Apache License 2.0</license>
<url type="website">https://www.apollo.auto/</url>
<url type="repository">https://github.com/ApolloAuto/apollo</url>
<url type="bugtracker">https://github.com/ApolloAuto/apollo/issues</url>
<type>module</type>
<src_path url="https://github.com/ApolloAuto/apollo">//modules/canbus_vehicle/transit</src_path>
<depend type="binary" repo_name="cyber">cyber-dev</depend>
<depend type="binary" repo_name="common" lib_names="common">common-dev</depend>
<depend type="binary" repo_name="canbus" lib_names="canbus">canbus-dev</depend>
<depend repo_name="common-msgs" lib_names="common-msgs">common-msgs-dev</depend>
<depend type="binary" repo_name="drivers">drivers-dev</depend>
<depend repo_name="com_google_googletest" lib_names="gtest,gtest_main">3rd-gtest-dev</depend>
</package>
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_message_manager.cc
|
/* Copyright 2018 The Apollo Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "modules/canbus_vehicle/transit/transit_message_manager.h"
#include "modules/canbus_vehicle/transit/protocol/adc_auxiliarycontrol_110.h"
#include "modules/canbus_vehicle/transit/protocol/adc_motioncontrol1_10.h"
#include "modules/canbus_vehicle/transit/protocol/adc_motioncontrollimits1_12.h"
#include "modules/canbus_vehicle/transit/protocol/llc_diag_brakecontrol_721.h"
#include "modules/canbus_vehicle/transit/protocol/llc_diag_steeringcontrol_722.h"
#include "modules/canbus_vehicle/transit/protocol/llc_auxiliaryfeedback_120.h"
#include "modules/canbus_vehicle/transit/protocol/llc_diag_fault_620.h"
#include "modules/canbus_vehicle/transit/protocol/llc_motioncommandfeedback1_22.h"
#include "modules/canbus_vehicle/transit/protocol/llc_motionfeedback1_20.h"
#include "modules/canbus_vehicle/transit/protocol/llc_motionfeedback2_21.h"
#include "modules/canbus_vehicle/transit/protocol/llc_vehiclelimits_24.h"
#include "modules/canbus_vehicle/transit/protocol/llc_vehiclestatus_25.h"
namespace apollo {
namespace canbus {
namespace transit {
TransitMessageManager::TransitMessageManager() {
// Control Messages
AddSendProtocolData<Adcauxiliarycontrol110, true>();
AddSendProtocolData<Adcmotioncontrol110, true>();
AddSendProtocolData<Adcmotioncontrollimits112, true>();
AddSendProtocolData<Llcdiagbrakecontrol721, true>();
AddSendProtocolData<Llcdiagsteeringcontrol722, true>();
// Report Messages
AddRecvProtocolData<Llcauxiliaryfeedback120, true>();
AddRecvProtocolData<Llcdiagfault620, true>();
AddRecvProtocolData<Llcmotioncommandfeedback122, true>();
AddRecvProtocolData<Llcmotionfeedback120, true>();
AddRecvProtocolData<Llcmotionfeedback221, true>();
AddRecvProtocolData<Llcvehiclelimits24, true>();
AddRecvProtocolData<Llcvehiclestatus25, true>();
}
TransitMessageManager::~TransitMessageManager() {}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_vehicle_factory.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/transit_vehicle_factory.h"
#include "cyber/common/log.h"
#include "modules/canbus/common/canbus_gflags.h"
#include "modules/canbus_vehicle/transit/transit_controller.h"
#include "modules/canbus_vehicle/transit/transit_message_manager.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/common/util/util.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
using apollo::common::ErrorCode;
using apollo::control::ControlCommand;
using apollo::drivers::canbus::CanClientFactory;
namespace apollo {
namespace canbus {
bool TransitVehicleFactory::Init(const CanbusConf *canbus_conf) {
// Init can client
auto can_factory = CanClientFactory::Instance();
can_factory->RegisterCanClients();
can_client_ = can_factory->CreateCANClient(canbus_conf->can_card_parameter());
if (!can_client_) {
AERROR << "Failed to create can client.";
return false;
}
AINFO << "Can client is successfully created.";
message_manager_ = this->CreateMessageManager();
if (message_manager_ == nullptr) {
AERROR << "Failed to create message manager.";
return false;
}
AINFO << "Message manager is successfully created.";
if (can_receiver_.Init(can_client_.get(), message_manager_.get(),
canbus_conf->enable_receiver_log()) != ErrorCode::OK) {
AERROR << "Failed to init can receiver.";
return false;
}
AINFO << "The can receiver is successfully initialized.";
if (can_sender_.Init(can_client_.get(), message_manager_.get(),
canbus_conf->enable_sender_log()) != ErrorCode::OK) {
AERROR << "Failed to init can sender.";
return false;
}
AINFO << "The can sender is successfully initialized.";
vehicle_controller_ = CreateVehicleController();
if (vehicle_controller_ == nullptr) {
AERROR << "Failed to create vehicle controller.";
return false;
}
AINFO << "The vehicle controller is successfully created.";
if (vehicle_controller_->Init(canbus_conf->vehicle_parameter(), &can_sender_,
message_manager_.get()) != ErrorCode::OK) {
AERROR << "Failed to init vehicle controller.";
return false;
}
AINFO << "The vehicle controller is successfully"
<< " initialized with canbus conf as : "
<< canbus_conf->vehicle_parameter().ShortDebugString();
node_ = ::apollo::cyber::CreateNode("chassis_detail");
chassis_detail_writer_ = node_->CreateWriter<::apollo::canbus::Transit>(
FLAGS_chassis_detail_topic);
return true;
}
bool TransitVehicleFactory::Start() {
// 1. init and start the can card hardware
if (can_client_->Start() != ErrorCode::OK) {
AERROR << "Failed to start can client";
return false;
}
AINFO << "Can client is started.";
// 2. start receive first then send
if (can_receiver_.Start() != ErrorCode::OK) {
AERROR << "Failed to start can receiver.";
return false;
}
AINFO << "Can receiver is started.";
// 3. start send
if (can_sender_.Start() != ErrorCode::OK) {
AERROR << "Failed to start can sender.";
return false;
}
// 4. start controller
if (!vehicle_controller_->Start()) {
AERROR << "Failed to start vehicle controller.";
return false;
}
return true;
}
void TransitVehicleFactory::Stop() {
can_sender_.Stop();
can_receiver_.Stop();
can_client_->Stop();
vehicle_controller_->Stop();
AINFO << "Cleanup cansender, canreceiver, canclient, vehicle controller.";
}
void TransitVehicleFactory::UpdateCommand(
const apollo::control::ControlCommand *control_command) {
if (vehicle_controller_->Update(*control_command) != ErrorCode::OK) {
AERROR << "Failed to process callback function OnControlCommand because "
"vehicle_controller_->Update error.";
return;
}
can_sender_.Update();
}
Chassis TransitVehicleFactory::publish_chassis() {
Chassis chassis = vehicle_controller_->chassis();
ADEBUG << chassis.ShortDebugString();
return chassis;
}
void TransitVehicleFactory::PublishChassisDetail() {
Transit chassis_detail;
message_manager_->GetSensorData(&chassis_detail);
ADEBUG << chassis_detail.ShortDebugString();
chassis_detail_writer_->Write(chassis_detail);
}
std::unique_ptr<VehicleController<::apollo::canbus::Transit>>
TransitVehicleFactory::CreateVehicleController() {
return std::unique_ptr<VehicleController<::apollo::canbus::Transit>>(
new transit::TransitController());
}
std::unique_ptr<MessageManager<::apollo::canbus::Transit>>
TransitVehicleFactory::CreateMessageManager() {
return std::unique_ptr<MessageManager<::apollo::canbus::Transit>>(
new transit::TransitMessageManager());
}
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools/install:install.bzl", "install", "install_files", "install_src_files")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
CANBUS_COPTS = ["-DMODULE_NAME=\\\"canbus\\\""]
cc_library(
name = "transit_vehicle_factory",
srcs = ["transit_vehicle_factory.cc"],
hdrs = ["transit_vehicle_factory.h"],
copts = CANBUS_COPTS,
alwayslink = True,
deps = [
":transit_controller",
":transit_message_manager",
"//modules/canbus/common:canbus_gflags",
"//modules/common/adapters:adapter_gflags",
"//modules/common/status",
"//modules/canbus/vehicle:abstract_vehicle_factory",
"//modules/drivers/canbus:sensor_canbus_lib",
],
)
cc_binary(
name = "libtransit_vehicle_factory_lib.so",
linkshared = True,
linkstatic = True,
deps = [":transit_vehicle_factory"],
)
cc_library(
name = "transit_message_manager",
srcs = ["transit_message_manager.cc"],
hdrs = ["transit_message_manager.h"],
copts = CANBUS_COPTS,
deps = [
"//modules/canbus_vehicle/transit/proto:transit_cc_proto",
"//modules/canbus_vehicle/transit/protocol:canbus_transit_protocol",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_library(
name = "transit_controller",
srcs = ["transit_controller.cc"],
hdrs = ["transit_controller.h"],
copts = CANBUS_COPTS,
deps = [
":transit_message_manager",
"//modules/common_msgs/chassis_msgs:chassis_cc_proto",
"//modules/canbus/vehicle:vehicle_controller_base",
"//modules/common/kv_db",
"//modules/common_msgs/basic_msgs:vehicle_signal_cc_proto",
"//modules/drivers/canbus/can_comm:can_sender",
"//modules/drivers/canbus/common:canbus_common",
],
)
cc_test(
name = "transit_vehicle_factory_test",
size = "small",
srcs = ["transit_vehicle_factory_test.cc"],
data = ["//modules/canbus:test_data"],
linkstatic = True,
deps = [
":transit_vehicle_factory",
"@com_google_googletest//:gtest_main",
],
)
cc_test(
name = "transit_controller_test",
size = "small",
srcs = ["transit_controller_test.cc"],
data = ["//modules/canbus:test_data"],
deps = [
":transit_controller",
"//modules/common/util",
"@com_google_googletest//:gtest_main",
],
)
install(
name = "install",
library_dest = "canbus-vehicle-transit/lib",
data_dest = "canbus-vehicle-transit",
data = [
":runtime_data",
":cyberfile.xml",
":canbus-vehicle-transit.BUILD",
],
targets = [
":libtransit_vehicle_factory_lib.so",
],
deps = [
":pb_transit",
":pb_hdrs",
],
)
install(
name = "pb_hdrs",
data_dest = "canbus-vehicle-transit/include",
data = [
"//modules/canbus_vehicle/transit/proto:transit_cc_proto",
],
)
install_files(
name = "pb_transit",
dest = "canbus-vehicle-transit",
files = [
"//modules/canbus_vehicle/transit/proto:transit_py_pb2",
],
)
filegroup(
name = "runtime_data",
srcs = glob([
"testdata/**",
]),
)
install_src_files(
name = "install_src",
deps = [
":install_transit_src",
":install_transit_hdrs"
],
)
install_src_files(
name = "install_transit_src",
src_dir = ["."],
dest = "canbus-vehicle-transit/src",
filter = "*",
)
install_src_files(
name = "install_transit_hdrs",
src_dir = ["."],
dest = "canbus-vehicle-transit/include",
filter = "*.h",
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_controller.cc
|
/******************************************************************************
* Copyright 2017 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/transit_controller.h"
#include "modules/common_msgs/basic_msgs/vehicle_signal.pb.h"
#include "cyber/common/log.h"
#include "cyber/time/time.h"
#include "modules/canbus_vehicle/transit/transit_message_manager.h"
#include "modules/canbus/vehicle/vehicle_controller.h"
#include "modules/common/kv_db/kv_db.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::common::ErrorCode;
using ::apollo::control::ControlCommand;
using ::apollo::drivers::canbus::ProtocolData;
namespace {
const int32_t kMaxFailAttempt = 10;
const int32_t CHECK_RESPONSE_STEER_UNIT_FLAG = 1;
const int32_t CHECK_RESPONSE_SPEED_UNIT_FLAG = 2;
} // namespace
ErrorCode TransitController::Init(
const VehicleParameter& params,
CanSender<::apollo::canbus::Transit>* const can_sender,
MessageManager<::apollo::canbus::Transit>* const message_manager) {
if (is_initialized_) {
AINFO << "TransitController has already been initialized.";
return ErrorCode::CANBUS_ERROR;
}
vehicle_params_.CopyFrom(
common::VehicleConfigHelper::Instance()->GetConfig().vehicle_param());
params_.CopyFrom(params);
if (!params_.has_driving_mode()) {
AERROR << "Vehicle conf pb not set driving_mode.";
return ErrorCode::CANBUS_ERROR;
}
if (can_sender == nullptr) {
AERROR << "Canbus sender is null.";
return ErrorCode::CANBUS_ERROR;
}
can_sender_ = can_sender;
if (message_manager == nullptr) {
AERROR << "protocol manager is null.";
return ErrorCode::CANBUS_ERROR;
}
message_manager_ = message_manager;
// sender part
adc_auxiliarycontrol_110_ = dynamic_cast<Adcauxiliarycontrol110*>(
message_manager_->GetMutableProtocolDataById(Adcauxiliarycontrol110::ID));
if (adc_auxiliarycontrol_110_ == nullptr) {
AERROR << "Adcauxiliarycontrol110 does not exist in the "
"TransitMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
adc_motioncontrol1_10_ = dynamic_cast<Adcmotioncontrol110*>(
message_manager_->GetMutableProtocolDataById(Adcmotioncontrol110::ID));
if (adc_motioncontrol1_10_ == nullptr) {
AERROR
<< "Adcmotioncontrol110 does not exist in the TransitMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
adc_motioncontrollimits1_12_ = dynamic_cast<Adcmotioncontrollimits112*>(
message_manager_->GetMutableProtocolDataById(
Adcmotioncontrollimits112::ID));
if (adc_motioncontrollimits1_12_ == nullptr) {
AERROR << "Adcmotioncontrollimits112 does not exist in the "
"TransitMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
llc_diag_brakecontrol_721_ = dynamic_cast<Llcdiagbrakecontrol721*>(
message_manager_->GetMutableProtocolDataById(Llcdiagbrakecontrol721::ID));
if (llc_diag_brakecontrol_721_ == nullptr) {
AERROR << "Llcdiagbrakecontrol721 does not exist in the "
"TransitMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
llc_diag_steeringcontrol_722_ = dynamic_cast<Llcdiagsteeringcontrol722*>(
message_manager_->GetMutableProtocolDataById(
Llcdiagsteeringcontrol722::ID));
if (llc_diag_steeringcontrol_722_ == nullptr) {
AERROR << "Llcdiagsteeringcontrol722 does not exist in the "
"TransitMessageManager!";
return ErrorCode::CANBUS_ERROR;
}
can_sender_->AddMessage(Adcauxiliarycontrol110::ID, adc_auxiliarycontrol_110_,
false);
can_sender_->AddMessage(Adcmotioncontrol110::ID, adc_motioncontrol1_10_,
false);
can_sender_->AddMessage(Adcmotioncontrollimits112::ID,
adc_motioncontrollimits1_12_, false);
can_sender_->AddMessage(Llcdiagbrakecontrol721::ID,
llc_diag_brakecontrol_721_, false);
can_sender_->AddMessage(Llcdiagsteeringcontrol722::ID,
llc_diag_steeringcontrol_722_, false);
// need sleep to ensure all messages received
AINFO << "TransitController is initialized.";
is_initialized_ = true;
return ErrorCode::OK;
}
TransitController::~TransitController() {}
bool TransitController::Start() {
if (!is_initialized_) {
AERROR << "TransitController has NOT been initiated.";
return false;
}
const auto& update_func = [this] { SecurityDogThreadFunc(); };
thread_.reset(new std::thread(update_func));
return true;
}
void TransitController::Stop() {
if (!is_initialized_) {
AERROR << "TransitController stops or starts improperly!";
return;
}
if (thread_ != nullptr && thread_->joinable()) {
thread_->join();
thread_.reset();
AINFO << "TransitController stopped.";
}
}
Chassis TransitController::chassis() {
chassis_.Clear();
Transit chassis_detail;
message_manager_->GetSensorData(&chassis_detail);
// 21, 22, previously 1, 2
if (driving_mode() == Chassis::EMERGENCY_MODE) {
set_chassis_error_code(Chassis::NO_ERROR);
}
chassis_.set_driving_mode(driving_mode());
chassis_.set_error_code(chassis_error_code());
// 3
chassis_.set_engine_started(true);
auto& motion20 = chassis_detail.llc_motionfeedback1_20();
if (motion20.has_llc_fbk_throttleposition()) {
chassis_.set_throttle_percentage(
static_cast<float>(motion20.llc_fbk_throttleposition()));
}
button_pressed_ = (chassis_detail.llc_motionfeedback1_20().llc_fbk_state() ==
Llc_motionfeedback1_20::LLC_FBK_STATE_AUTONOMY);
if (motion20.has_llc_fbk_brakepercentrear()) {
// TODO(Udelv): fix scaling
chassis_.set_brake_percentage(
static_cast<float>(motion20.llc_fbk_brakepercentrear()));
}
if (motion20.has_llc_fbk_gear()) {
switch (motion20.llc_fbk_gear()) {
case Llc_motionfeedback1_20::LLC_FBK_GEAR_P_PARK:
chassis_.set_gear_location(Chassis::GEAR_PARKING);
break;
case Llc_motionfeedback1_20::LLC_FBK_GEAR_D_DRIVE:
chassis_.set_gear_location(Chassis::GEAR_DRIVE);
break;
case Llc_motionfeedback1_20::LLC_FBK_GEAR_N_NEUTRAL:
chassis_.set_gear_location(Chassis::GEAR_NEUTRAL);
break;
case Llc_motionfeedback1_20::LLC_FBK_GEAR_R_REVERSE:
chassis_.set_gear_location(Chassis::GEAR_REVERSE);
break;
default:
break;
}
}
auto& motion21 = chassis_detail.llc_motionfeedback2_21();
if (motion21.has_llc_fbk_vehiclespeed()) {
chassis_.set_speed_mps(static_cast<float>(motion21.llc_fbk_vehiclespeed()));
}
if (motion21.has_llc_fbk_steeringangle()) {
chassis_.set_steering_percentage(
static_cast<float>(-1.0 * motion21.llc_fbk_steeringangle() * M_PI /
180 / vehicle_params_.max_steer_angle() * 100));
}
auto& aux = chassis_detail.llc_auxiliaryfeedback_120();
if (aux.has_llc_fbk_turnsignal()) {
switch (aux.llc_fbk_turnsignal()) {
case Adc_auxiliarycontrol_110::ADC_CMD_TURNSIGNAL_LEFT:
chassis_.mutable_signal()->set_turn_signal(
common::VehicleSignal::TURN_LEFT);
break;
case Adc_auxiliarycontrol_110::ADC_CMD_TURNSIGNAL_RIGHT:
chassis_.mutable_signal()->set_turn_signal(
common::VehicleSignal::TURN_RIGHT);
break;
case Adc_auxiliarycontrol_110::ADC_CMD_TURNSIGNAL_NONE:
chassis_.mutable_signal()->set_turn_signal(
common::VehicleSignal::TURN_NONE);
break;
default:
break;
}
}
return chassis_;
}
bool TransitController::VerifyID() { return true; }
void TransitController::Emergency() {
set_driving_mode(Chassis::EMERGENCY_MODE);
ResetProtocol();
}
ErrorCode TransitController::EnableAutoMode() {
if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE) {
AINFO << "Already in COMPLETE_AUTO_DRIVE mode";
return ErrorCode::OK;
}
SetLimits();
adc_motioncontrol1_10_->set_adc_cmd_autonomyrequest(
Adc_motioncontrol1_10::ADC_CMD_AUTONOMYREQUEST_AUTONOMY_REQUESTED);
adc_motioncontrol1_10_->set_adc_cmd_steeringcontrolmode(
Adc_motioncontrol1_10::ADC_CMD_STEERINGCONTROLMODE_ANGLE);
adc_motioncontrol1_10_->set_adc_cmd_longitudinalcontrolmode(
Adc_motioncontrol1_10::
ADC_CMD_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE);
can_sender_->Update();
if (!CheckResponse()) {
AERROR << "Failed to switch to COMPLETE_AUTO_DRIVE mode.";
Emergency();
return ErrorCode::CANBUS_ERROR;
}
if (button_pressed_) {
set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok.";
} else {
set_driving_mode(Chassis::COMPLETE_MANUAL);
AINFO << "Physical button not pressed yet.";
}
return ErrorCode::OK;
}
ErrorCode TransitController::DisableAutoMode() {
ResetProtocol();
can_sender_->Update();
set_driving_mode(Chassis::COMPLETE_MANUAL);
set_chassis_error_code(Chassis::NO_ERROR);
AINFO << "Switch to COMPLETE_MANUAL ok.";
return ErrorCode::OK;
}
ErrorCode TransitController::EnableSteeringOnlyMode() {
if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE ||
driving_mode() == Chassis::AUTO_STEER_ONLY) {
set_driving_mode(Chassis::AUTO_STEER_ONLY);
AINFO << "Already in AUTO_STEER_ONLY mode";
return ErrorCode::OK;
}
SetLimits();
adc_motioncontrol1_10_->set_adc_cmd_autonomyrequest(
Adc_motioncontrol1_10::ADC_CMD_AUTONOMYREQUEST_AUTONOMY_REQUESTED);
adc_motioncontrol1_10_->set_adc_cmd_steeringcontrolmode(
Adc_motioncontrol1_10::ADC_CMD_STEERINGCONTROLMODE_ANGLE);
adc_motioncontrol1_10_->set_adc_cmd_longitudinalcontrolmode(
Adc_motioncontrol1_10::ADC_CMD_LONGITUDINALCONTROLMODE_NONE);
can_sender_->Update();
set_driving_mode(Chassis::AUTO_STEER_ONLY);
return ErrorCode::OK;
}
ErrorCode TransitController::EnableSpeedOnlyMode() {
if (driving_mode() == Chassis::COMPLETE_AUTO_DRIVE ||
driving_mode() == Chassis::AUTO_SPEED_ONLY) {
set_driving_mode(Chassis::AUTO_SPEED_ONLY);
AINFO << "Already in AUTO_SPEED_ONLY mode";
return ErrorCode::OK;
}
SetLimits();
adc_motioncontrol1_10_->set_adc_cmd_autonomyrequest(
Adc_motioncontrol1_10::ADC_CMD_AUTONOMYREQUEST_AUTONOMY_REQUESTED);
adc_motioncontrol1_10_->set_adc_cmd_steeringcontrolmode(
Adc_motioncontrol1_10::ADC_CMD_STEERINGCONTROLMODE_NONE);
adc_motioncontrol1_10_->set_adc_cmd_longitudinalcontrolmode(
Adc_motioncontrol1_10::
ADC_CMD_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE);
can_sender_->Update();
if (!CheckResponse()) {
AERROR << "Failed to switch to AUTO_STEER_ONLY mode.";
Emergency();
set_chassis_error_code(Chassis::CHASSIS_ERROR);
return ErrorCode::CANBUS_ERROR;
}
if (button_pressed_) {
set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
AINFO << "Switch to COMPLETE_AUTO_DRIVE mode ok.";
} else {
set_driving_mode(Chassis::COMPLETE_MANUAL);
AINFO << "Physical button not pressed yet.";
}
return ErrorCode::OK;
}
// NEUTRAL, REVERSE, DRIVE
void TransitController::Gear(Chassis::GearPosition gear_position) {
if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE &&
driving_mode() != Chassis::AUTO_SPEED_ONLY) {
AINFO << "This drive mode no need to set gear.";
return;
}
switch (gear_position) {
case Chassis::GEAR_NEUTRAL: {
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_N_NEUTRAL);
break;
}
case Chassis::GEAR_REVERSE: {
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_R_REVERSE);
break;
}
case Chassis::GEAR_DRIVE: {
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_D_DRIVE);
break;
}
case Chassis::GEAR_PARKING: {
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_P_PARK);
break;
}
case Chassis::GEAR_LOW: {
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_D_DRIVE);
break;
}
case Chassis::GEAR_NONE: {
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_N_NEUTRAL);
break;
}
case Chassis::GEAR_INVALID: {
AERROR << "Gear command is invalid!";
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_N_NEUTRAL);
break;
}
default: {
adc_motioncontrol1_10_->set_adc_cmd_gear(
Adc_motioncontrol1_10::ADC_CMD_GEAR_N_NEUTRAL);
break;
}
}
}
// brake with new acceleration
// acceleration:0.00~99.99, unit:
// acceleration:0.0 ~ 7.0, unit:m/s^2
// acceleration_spd:60 ~ 100, suggest: 90
// -> pedal
void TransitController::Brake(double pedal) {
// double real_value = params_.max_acc() * acceleration / 100;
// TODO(QiL): Update brake value based on mode
if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE &&
driving_mode() != Chassis::AUTO_SPEED_ONLY) {
AINFO << "The current drive mode does not need to set acceleration.";
return;
}
if (button_pressed_) {
adc_motioncontrol1_10_->set_adc_cmd_brakepercentage(pedal);
} else {
adc_motioncontrol1_10_->set_adc_cmd_brakepercentage(0.0);
}
}
// drive with old acceleration
// gas:0.00~99.99 unit:
void TransitController::Throttle(double pedal) {
if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE &&
driving_mode() != Chassis::AUTO_SPEED_ONLY) {
AINFO << "The current drive mode does not need to set acceleration.";
return;
}
if (button_pressed_) {
adc_motioncontrol1_10_->set_adc_cmd_throttleposition(pedal);
} else {
adc_motioncontrol1_10_->set_adc_cmd_throttleposition(0.0);
}
}
// drive with acceleration/deceleration
// acc:-7.0 ~ 5.0, unit:m/s^2
void TransitController::Acceleration(double acc) {
if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE &&
driving_mode() != Chassis::AUTO_SPEED_ONLY) {
AINFO << "The current drive mode does not need to set acceleration.";
return;
}
// None
}
// transit default, -470 ~ 470, left:+, right:-
// need to be compatible with control module, so reverse
// steering with old angle speed
// angle:-99.99~0.00~99.99, unit:, left:-, right:+
void TransitController::Steer(double angle) {
if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE &&
driving_mode() != Chassis::AUTO_STEER_ONLY) {
AINFO << "The current driving mode does not need to set steer.";
return;
}
// TODO(All): remove -1.0 once Udelv has a complete fix.
const double real_angle =
button_pressed_
? vehicle_params_.max_steer_angle() * angle / 100.0 * 180 / M_PI
: 0;
adc_motioncontrol1_10_->set_adc_cmd_steerwheelangle(real_angle);
}
// steering with new angle speed
// angle:-99.99~0.00~99.99, unit:, left:-, right:+
// angle_spd:0.00~99.99, unit:deg/s
void TransitController::Steer(double angle, double angle_spd) {
if (driving_mode() != Chassis::COMPLETE_AUTO_DRIVE &&
driving_mode() != Chassis::AUTO_STEER_ONLY) {
AINFO << "The current driving mode does not need to set steer.";
return;
}
// TODO(All): remove -1.0 once Udelv has a complete fix.
const double real_angle =
button_pressed_
? vehicle_params_.max_steer_angle() * angle / 100.0 * 180 / M_PI
: 0;
adc_motioncontrol1_10_->set_adc_cmd_steerwheelangle(real_angle);
// TODO(QiL) : re-enable the angle_spd ajustment
}
void TransitController::SetEpbBreak(const ControlCommand& command) {
if (command.parking_brake()) {
adc_motioncontrol1_10_->set_adc_cmd_parkingbrake(true);
} else {
adc_motioncontrol1_10_->set_adc_cmd_parkingbrake(false);
}
}
void TransitController::SetBeam(const ControlCommand& command) {
if (command.signal().high_beam()) {
adc_auxiliarycontrol_110_->set_adc_cmd_highbeam(true);
} else if (command.signal().low_beam()) {
adc_auxiliarycontrol_110_->set_adc_cmd_lowbeam(true);
} else {
adc_auxiliarycontrol_110_->set_adc_cmd_highbeam(false);
adc_auxiliarycontrol_110_->set_adc_cmd_lowbeam(false);
}
}
void TransitController::SetHorn(const ControlCommand& command) {
if (command.signal().horn()) {
adc_auxiliarycontrol_110_->set_adc_cmd_horn(true);
} else {
adc_auxiliarycontrol_110_->set_adc_cmd_horn(false);
}
}
void TransitController::SetTurningSignal(const ControlCommand& command) {
// Set Turn Signal
auto signal = command.signal().turn_signal();
if (signal == common::VehicleSignal::TURN_LEFT) {
adc_auxiliarycontrol_110_->set_adc_cmd_turnsignal(
Adc_auxiliarycontrol_110::ADC_CMD_TURNSIGNAL_LEFT);
} else if (signal == common::VehicleSignal::TURN_RIGHT) {
adc_auxiliarycontrol_110_->set_adc_cmd_turnsignal(
Adc_auxiliarycontrol_110::ADC_CMD_TURNSIGNAL_RIGHT);
} else {
adc_auxiliarycontrol_110_->set_adc_cmd_turnsignal(
Adc_auxiliarycontrol_110::ADC_CMD_TURNSIGNAL_NONE);
}
}
void TransitController::ResetProtocol() {
message_manager_->ResetSendMessages();
}
bool TransitController::CheckChassisError() {
// TODO(QiL): re-design later
return true;
}
void TransitController::SecurityDogThreadFunc() {
int32_t vertical_ctrl_fail = 0;
int32_t horizontal_ctrl_fail = 0;
if (can_sender_ == nullptr) {
AERROR << "Failed to run SecurityDogThreadFunc() because can_sender_ is "
"nullptr.";
return;
}
while (!can_sender_->IsRunning()) {
std::this_thread::yield();
}
std::chrono::duration<double, std::micro> default_period{50000};
int64_t start = 0;
int64_t end = 0;
while (can_sender_->IsRunning()) {
start = ::apollo::cyber::Time::Now().ToMicrosecond();
const Chassis::DrivingMode mode = driving_mode();
bool emergency_mode = false;
// 1. horizontal control check
if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
mode == Chassis::AUTO_STEER_ONLY) &&
!CheckResponse()) {
++horizontal_ctrl_fail;
if (horizontal_ctrl_fail >= kMaxFailAttempt) {
emergency_mode = true;
set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
}
} else {
horizontal_ctrl_fail = 0;
}
// 2. vertical control check
if ((mode == Chassis::COMPLETE_AUTO_DRIVE ||
mode == Chassis::AUTO_SPEED_ONLY) &&
!CheckResponse()) {
++vertical_ctrl_fail;
if (vertical_ctrl_fail >= kMaxFailAttempt) {
emergency_mode = true;
set_chassis_error_code(Chassis::MANUAL_INTERVENTION);
}
} else {
vertical_ctrl_fail = 0;
}
if (emergency_mode && mode != Chassis::EMERGENCY_MODE) {
set_driving_mode(Chassis::EMERGENCY_MODE);
message_manager_->ResetSendMessages();
}
end = ::apollo::cyber::Time::Now().ToMicrosecond();
std::chrono::duration<double, std::micro> elapsed{end - start};
if (elapsed < default_period) {
std::this_thread::sleep_for(default_period - elapsed);
} else {
AERROR
<< "Too much time consumption in TransitController looping process:"
<< elapsed.count();
}
}
}
bool TransitController::CheckResponse() {
// TODO(Udelv): Add separate indicators
Transit chassis_detail;
if (message_manager_->GetSensorData(&chassis_detail) != ErrorCode::OK) {
AERROR_EVERY(100) << "get chassis detail failed.";
return false;
}
auto& motion1_20 = chassis_detail.llc_motionfeedback1_20();
return (motion1_20.llc_fbk_state() ==
Llc_motionfeedback1_20::LLC_FBK_STATE_AUTONOMY_NOT_ALLOWED ||
motion1_20.llc_fbk_state() ==
Llc_motionfeedback1_20::LLC_FBK_STATE_AUTONOMY_ALLOWED ||
motion1_20.llc_fbk_state() ==
Llc_motionfeedback1_20::LLC_FBK_STATE_AUTONOMY_REQUESTED ||
motion1_20.llc_fbk_state() ==
Llc_motionfeedback1_20::LLC_FBK_STATE_AUTONOMY);
}
void TransitController::set_chassis_error_mask(const int32_t mask) {
std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
chassis_error_mask_ = mask;
}
int32_t TransitController::chassis_error_mask() {
std::lock_guard<std::mutex> lock(chassis_mask_mutex_);
return chassis_error_mask_;
}
Chassis::ErrorCode TransitController::chassis_error_code() {
std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
return chassis_error_code_;
}
void TransitController::set_chassis_error_code(
const Chassis::ErrorCode& error_code) {
std::lock_guard<std::mutex> lock(chassis_error_code_mutex_);
chassis_error_code_ = error_code;
}
bool TransitController::CheckSafetyError(
const ::apollo::canbus::Transit& chassis_detail) {
return true;
}
void TransitController::SetLimits() {
adc_motioncontrollimits1_12_->set_adc_cmd_throttlecommandlimit(100);
adc_motioncontrollimits1_12_->set_adc_cmd_steerwheelanglelimit(1275);
adc_motioncontrollimits1_12_->set_adc_cmd_steeringrate(500);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_controller_test.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/transit_controller.h"
#include <string>
#include "cyber/common/file.h"
#include "gtest/gtest.h"
#include "modules/canbus/proto/canbus_conf.pb.h"
#include "modules/common_msgs/chassis_msgs/chassis.pb.h"
#include "modules/canbus_vehicle/transit/transit_message_manager.h"
#include "modules/common_msgs/control_msgs/control_cmd.pb.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::common::ErrorCode;
using ::apollo::control::ControlCommand;
class TransitControllerTest : public ::testing::Test {
public:
virtual void SetUp() {
std::string canbus_conf_file =
"/apollo/modules/canbus/testdata/conf/transit_canbus_conf_test.pb.txt";
cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_);
params_ = canbus_conf_.vehicle_parameter();
}
protected:
TransitController controller_;
CanSender<::apollo::canbus::Transit> sender_;
CanbusConf canbus_conf_;
VehicleParameter params_;
TransitMessageManager msg_manager_;
ControlCommand control_cmd_;
};
TEST_F(TransitControllerTest, Init) {
ErrorCode ret = controller_.Init(params_, &sender_, &msg_manager_);
EXPECT_EQ(ret, ErrorCode::OK);
}
TEST_F(TransitControllerTest, SetDrivingMode) {
Chassis chassis;
chassis.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
controller_.Init(params_, &sender_, &msg_manager_);
controller_.set_driving_mode(chassis.driving_mode());
EXPECT_EQ(controller_.driving_mode(), chassis.driving_mode());
EXPECT_EQ(controller_.SetDrivingMode(chassis.driving_mode()), ErrorCode::OK);
}
TEST_F(TransitControllerTest, Status) {
controller_.Init(params_, &sender_, &msg_manager_);
controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
EXPECT_EQ(controller_.Update(control_cmd_), ErrorCode::OK);
controller_.SetHorn(control_cmd_);
controller_.SetBeam(control_cmd_);
controller_.SetTurningSignal(control_cmd_);
EXPECT_TRUE(controller_.CheckChassisError());
}
TEST_F(TransitControllerTest, UpdateDrivingMode) {
controller_.Init(params_, &sender_, &msg_manager_);
controller_.set_driving_mode(Chassis::COMPLETE_AUTO_DRIVE);
EXPECT_EQ(controller_.SetDrivingMode(Chassis::COMPLETE_MANUAL),
ErrorCode::OK);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/transit_vehicle_factory_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/transit_vehicle_factory.h"
#include "gtest/gtest.h"
#include "modules/canbus/proto/canbus_conf.pb.h"
#include "modules/canbus/proto/vehicle_parameter.pb.h"
#include "cyber/common/file.h"
namespace apollo {
namespace canbus {
class TransitVehicleFactoryTest : public ::testing::Test {
public:
virtual void SetUp() {
std::string canbus_conf_file =
"/apollo/modules/canbus_vehicle/transit/testdata/"
"transit_canbus_conf_test.pb.txt";
cyber::common::GetProtoFromFile(canbus_conf_file, &canbus_conf_);
params_ = canbus_conf_.vehicle_parameter();
params_.set_brand(apollo::common::TRANSIT);
transit_factory_.SetVehicleParameter(params_);
}
virtual void TearDown() {}
protected:
TransitVehicleFactory transit_factory_;
CanbusConf canbus_conf_;
VehicleParameter params_;
};
TEST_F(TransitVehicleFactoryTest, Init) {
apollo::cyber::Init("vehicle_factory_test");
EXPECT_EQ(transit_factory_.Init(&canbus_conf_), true);
}
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/testdata/transit_canbus_conf_test.pb.txt
|
vehicle_parameter {
brand: TRANSIT
max_enable_fail_attempt: 5
driving_mode: COMPLETE_AUTO_DRIVE
}
can_card_parameter {
brand:SOCKET_CAN_RAW
type: PCI_CARD
channel_id: CHANNEL_ID_ZERO
}
enable_debug_mode: false
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/proto/transit.proto
|
syntax = "proto2";
package apollo.canbus;
message Llc_vehiclelimits_24 {
// Report Message
// Steering angle feedback [deg] [0|4095]
optional int32 llc_fbk_maxsteeringangle = 1;
// Front brake pressure feedback [%] [0|113.8132]
optional double llc_fbk_maxbrakepercent = 2;
}
message Adc_motioncontrol1_10 {
// Control Message
enum Adc_cmd_steeringcontrolmodeType {
ADC_CMD_STEERINGCONTROLMODE_NONE = 0;
ADC_CMD_STEERINGCONTROLMODE_ANGLE = 1;
ADC_CMD_STEERINGCONTROLMODE_RESERVED_CURVATURE = 2;
ADC_CMD_STEERINGCONTROLMODE_RESERVED = 3;
}
enum Adc_cmd_gearType {
ADC_CMD_GEAR_P_PARK = 0;
ADC_CMD_GEAR_D_DRIVE = 1;
ADC_CMD_GEAR_N_NEUTRAL = 2;
ADC_CMD_GEAR_R_REVERSE = 3;
}
enum Adc_cmd_autonomyrequestType {
ADC_CMD_AUTONOMYREQUEST_AUTONOMY_NOT_REQUESTED = 0;
ADC_CMD_AUTONOMYREQUEST_AUTONOMY_REQUESTED = 1;
ADC_CMD_AUTONOMYREQUEST_RESERVED0 = 2;
ADC_CMD_AUTONOMYREQUEST_RESERVED1 = 3;
}
enum Adc_cmd_longitudinalcontrolmodeType {
ADC_CMD_LONGITUDINALCONTROLMODE_NONE = 0;
ADC_CMD_LONGITUDINALCONTROLMODE_RESERVED_VELOCITY_AND_ACCELERATION = 1;
ADC_CMD_LONGITUDINALCONTROLMODE_RESERVED_FORCE = 2;
ADC_CMD_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE = 3;
}
// Setpoint for steering wheel angle. Positive for CW [deg] [-1638.4|1638.35]
optional double adc_cmd_steerwheelangle = 1;
// Select steering control mode [] [0|3]
optional Adc_cmd_steeringcontrolmodeType adc_cmd_steeringcontrolmode = 2;
// (Reserved) Control parking brake [T/F] [0|1]
optional bool adc_cmd_parkingbrake = 3;
// Transmission control - only used in direct longitudinal control [] [0|7]
optional Adc_cmd_gearType adc_cmd_gear = 4;
// Motion Control 1 checksum [] [0|255]
optional int32 adc_motioncontrol1_checksum = 5;
// Brake pressure for direct longitudinal control [%] [0|113.8132]
optional double adc_cmd_brakepercentage = 6;
// Throttle pedal position percentage for direct longitudinal control [%]
// [0|100]
optional double adc_cmd_throttleposition = 7;
// Motion control 1 Heartbeat counter [] [0|3]
optional int32 adc_motioncontrol1_counter = 8;
// Request from ADC to LLC for autonomy [] [0|3]
optional Adc_cmd_autonomyrequestType adc_cmd_autonomyrequest = 9;
// Select longitudinal control mode [] [0|3]
optional Adc_cmd_longitudinalcontrolmodeType adc_cmd_longitudinalcontrolmode =
10;
}
message Adc_motioncontrollimits1_12 {
// Control Message
// Set limit for throttle position [%] [0|100]
optional double adc_cmd_throttlecommandlimit = 1;
// Set steering rate [deg/s] [0|3276.75]
optional double adc_cmd_steeringrate = 2;
// Set limit for steering wheel angle. Applies in both positive and negative
// [deg] [0|1275]
optional double adc_cmd_steerwheelanglelimit = 3;
}
message Llc_motionfeedback1_20 {
// Report Message
enum Llc_fbk_gearType {
LLC_FBK_GEAR_P_PARK = 0;
LLC_FBK_GEAR_D_DRIVE = 1;
LLC_FBK_GEAR_N_NEUTRAL = 2;
LLC_FBK_GEAR_R_REVERSE = 3;
}
enum Llc_fbk_steeringcontrolmodeType {
LLC_FBK_STEERINGCONTROLMODE_NONE = 0;
LLC_FBK_STEERINGCONTROLMODE_ANGLE = 1;
LLC_FBK_STEERINGCONTROLMODE_RESERVED_CURVATURE = 2;
LLC_FBK_STEERINGCONTROLMODE_RESERVED = 3;
}
enum Llc_fbk_longitudinalcontrolmodeType {
LLC_FBK_LONGITUDINALCONTROLMODE_NONE = 0;
LLC_FBK_LONGITUDINALCONTROLMODE_RESERVED_VELOCITY_AND_ACCELERATION = 1;
LLC_FBK_LONGITUDINALCONTROLMODE_RESERVED_FORCE = 2;
LLC_FBK_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE = 3;
}
enum Llc_fbk_stateType {
LLC_FBK_STATE_RESERVED0 = 0;
LLC_FBK_STATE_AUTONOMY_NOT_ALLOWED = 1;
LLC_FBK_STATE_AUTONOMY_ALLOWED = 2;
LLC_FBK_STATE_AUTONOMY_REQUESTED = 3;
LLC_FBK_STATE_AUTONOMY = 4;
LLC_FBK_STATE_RESERVED1 = 5;
LLC_FBK_STATE_RESERVED2 = 6;
LLC_FBK_STATE_RESERVED3 = 7;
LLC_FBK_STATE_RESERVED4 = 8;
LLC_FBK_STATE_RESERVED5 = 9;
LLC_FBK_STATE_RESERVED6 = 10;
LLC_FBK_STATE_RESERVED7 = 11;
LLC_FBK_STATE_RESERVED8 = 12;
LLC_FBK_STATE_DISENGAGE_REQUESTED = 13;
LLC_FBK_STATE_DISENGAGED = 14;
LLC_FBK_STATE_FAULT = 15;
}
// Current gear [] [0|3]
optional Llc_fbk_gearType llc_fbk_gear = 1;
// Parking brake applied [T/F] [0|1]
optional bool llc_fbk_parkingbrake = 2;
// Throttle position feedback [%] [0|102.3]
optional double llc_fbk_throttleposition = 3;
// Rear brake pressure feedback [%] [0|113.8132]
optional double llc_fbk_brakepercentrear = 4;
// Front brake pressure feedback [%] [0|113.8132]
optional double llc_fbk_brakepercentfront = 5;
// Current steering control mode [] [0|3]
optional Llc_fbk_steeringcontrolmodeType llc_fbk_steeringcontrolmode = 6;
// Motion feedback 1 heartbeat counter [] [0|3]
optional int32 llc_motionfeedback1_counter = 7;
// Motion feedback 1 checksum [] [0|255]
optional int32 llc_motionfeedback1_checksum = 8;
// Autonomy command aligned with vehicle state according to calibration limits
// [T/F] [0|1]
optional bool llc_fbk_commandaligned = 9;
// Estop is pressed [T/F] [0|1]
optional bool llc_fbk_estoppressed = 10;
// Indicates that ADC is requesting autonomy mode [T/F] [0|1]
optional bool llc_fbk_adcrequestautonomy = 11;
// Indicates that LLC is ready to allow autonomy mode [T/F] [0|1]
optional bool llc_fbk_allowautonomy = 12;
// Report current longitudinal control mode [] [0|3]
optional Llc_fbk_longitudinalcontrolmodeType llc_fbk_longitudinalcontrolmode =
13;
// Current Autonomy State [] [0|15]
optional Llc_fbk_stateType llc_fbk_state = 14;
}
message Llc_motionfeedback2_21 {
// Report Message
// [m/s] [0|655.35]
optional double llc_fbk_vehiclespeed = 1;
// Motion feedback 2 heartbeat counter [] [0|3]
optional int32 llc_motionfeedback2_counter = 2;
// Motion feedback 2 checksum [] [0|255]
optional int32 llc_motionfeedback2_checksum = 3;
// Steer wheel angle feedback from SbW motor (? rate) [deg/s] [-1638.4|1638.3]
optional double llc_fbk_steeringrate = 4;
// Steering angle feedback [deg] [-1638.4|1638.35]
optional double llc_fbk_steeringangle = 5;
}
message Llc_motioncommandfeedback1_22 {
// Report Message
// Steering angle setpoint (after limits) [deg] [-1638.4|1638.35]
optional double llc_fbk_steeringanglesetpoint = 1;
// Current throttle setpoint (after limits) [%] [0|102.3]
optional double llc_fbk_throttlesetpoint = 2;
// Front brake pressure setpoint (after limits) [%] [0|113.8132]
optional double llc_fbk_brakepercentsetpoint = 3;
// Motion command feedback 2 heartbeat counter [] [0|3]
optional int32 llc_motioncommandfeedback1_count = 4;
// Motion command feedback 1 checksum [] [0|255]
optional int32 llc_motioncommandfeedback1_check = 5;
}
message Llc_vehiclestatus_25 {
// Report Message
// Vehicle 12V voltage feedback [Volt] [0|25.5]
optional double llc_fbk_12voltage = 1;
}
message Llc_auxiliaryfeedback_120 {
// Report Message
enum Llc_fbk_turnsignalType {
LLC_FBK_TURNSIGNAL_NONE = 0;
LLC_FBK_TURNSIGNAL_LEFT = 1;
LLC_FBK_TURNSIGNAL_RIGHT = 2;
LLC_FBK_TURNSIGNAL_RESERVE = 3;
}
// Inverter enabled [T/F] [0|1]
optional bool llc_fbk_inverter = 1;
// PDU Channel 8 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch8 = 2;
// PDU Channel 7 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch7 = 3;
// PDU Channel 6 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch6 = 4;
// PDU Channel 5 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch5 = 5;
// PDU Channel 4 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch4 = 6;
// PDU Channel 3 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch3 = 7;
// PDU Channel 2 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch2 = 8;
// PDU Channel 1 enabled [T/F] [0|1]
optional bool llc_fbk_pdu_ch1 = 9;
// Hazard lights enabled [T/F] [0|1]
optional bool llc_fbk_hazardlights = 10;
// Autonomy indicator green LED on [T/F] [0|1]
optional bool llc_fbk_ledgreenon = 11;
// Horn enabled [T/F] [0|1]
optional bool llc_fbk_horn = 12;
// Buzzer enabled [T/F] [0|1]
optional bool llc_fbk_buzzeron = 13;
// Current turn signal status [] [0|3]
optional Llc_fbk_turnsignalType llc_fbk_turnsignal = 14;
// Low beam enabled [T/F] [0|1]
optional bool llc_fbk_lowbeam = 15;
// High beam enabled [T/F] [0|1]
optional bool llc_fbk_highbeam = 16;
// Autonomy indicator red LED on [T/F] [0|1]
optional bool llc_fbk_ledredon = 17;
// Autonomy button is pressed [T/F] [0|1]
optional bool llc_fbk_autonomybuttonpressed = 18;
}
message Llc_diag_fault_620 {
// Report Message
// Counts the number of times that the driver has disengaged autonomy by
// applying the brakes since system reset.. [] [0|255]
optional int32 llc_disengagecounter_brake = 1;
// Counts the number of times that the driver has disengaged autonomy by
// moving the steering wheel since system reset. [] [0|255]
optional int32 llc_disengagecounter_steer = 2;
// Counts the number of times that the driver has disengaged autonomy by
// applying throttle since system reset. [] [0|255]
optional int32 llc_disengagecounter_throttle = 3;
// Counts the number of faults that have occurred since system reset. []
// [0|255]
optional int32 llc_fbk_faultcounter = 4;
// Counts the number of times that the driver has disengaged autonomy by
// applying the brakes since system reset.. [] [0|255]
optional int32 llc_disengagecounter_button = 5;
// Firmware version [g] [2017|2144]
optional int32 llc_fbk_version_year = 6;
// Firmware version [Month] [0|15]
optional int32 llc_fbk_version_month = 7;
// Firmware version [Day] [0|31]
optional int32 llc_fbk_version_day = 8;
// Firmware version [Hour] [0|31]
optional int32 llc_fbk_version_hour = 9;
}
message Llc_diag_steeringcontrol_722 {
// Control Message
// Brake control feedforward contribution [rev] [-6.5536|6.5534]
optional double llc_dbg_steeringsensorposition = 1;
// Brake control feedforward contribution [counts] [-32768|32767]
optional int32 llc_dbg_steeringrackinputtorque = 2;
// Brake control feedforward contribution [rev] [-83.88608|83.88607]
optional double llc_dbg_steeringmotorposition = 3;
}
message Adc_auxiliarycontrol_110 {
// Control Message
enum Adc_cmd_turnsignalType {
ADC_CMD_TURNSIGNAL_NONE = 0;
ADC_CMD_TURNSIGNAL_LEFT = 1;
ADC_CMD_TURNSIGNAL_RIGHT = 2;
ADC_CMD_TURNSIGNAL_RESERVE = 3;
}
// Aux control heartbeat counter [] [0|3]
optional int32 adc_auxcontrol_counter = 1;
// Aux control checksum [] [0|255]
optional int32 adc_auxcontrol_checksum = 2;
// Control inverter override (default ON if not overridden) [T/F] [0|1]
optional bool adc_cmd_inverter_controlenable = 3;
// Control inverter [T/F] [0|1]
optional bool adc_cmd_inverter = 4;
// (Reserved) Control wiper [] [0|3]
optional int32 adc_cmd_wiper = 5;
// PDU Control Override (all channels default ON if not overridden) [T/F]
// [0|1]
optional bool adc_cmd_pdu_controlenable = 6;
// Control PDU Ch 8 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch8 = 7;
// Control PDU Ch 7 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch7 = 8;
// Control PDU Ch 6 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch6 = 9;
// Control PDU Ch 5 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch5 = 10;
// Control PDU Ch 4 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch4 = 11;
// Control PDU Ch 3 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch3 = 12;
// Control PDU Ch 2 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch2 = 13;
// Control PDU Ch 1 (when override enabled) [T/F] [0|1]
optional bool adc_cmd_pdu_ch1 = 14;
// Control hazard lights [T/F] [0|1]
optional bool adc_cmd_hazardlights = 15;
// Control high beam [T/F] [0|1]
optional bool adc_cmd_highbeam = 16;
// Control low beam [T/F] [0|1]
optional bool adc_cmd_lowbeam = 17;
// Control horn [T/F] [0|1]
optional bool adc_cmd_horn = 18;
// Requested turn signals [] [0|3]
optional Adc_cmd_turnsignalType adc_cmd_turnsignal = 19;
}
message Llc_diag_brakecontrol_721 {
// Control Message
// Brake control loop P contribution [mrev] [-51.2|51.1]
optional double llc_dbg_brakepidcontribution_p = 1;
// Brake control loop I contribution [mrev] [-51.2|51.1]
optional double llc_dbg_brakepidcontribution_i = 2;
// Brake control loop D contribution [mrev] [-51.2|51.1]
optional double llc_dbg_brakepidcontribution_d = 3;
// Brake control loop output [mrev] [-51.2|51.1]
optional double llc_dbg_brakepid_output = 4;
// Brake control loop error [psi] [-2048|2047]
optional int32 llc_dbg_brakepid_error = 5;
// Brake control feedforward contribution [mrev] [-1024|1023.5]
optional double llc_dbg_brakefeedforward = 6;
}
// CheckResponseSignal
message CheckResponseSignal {
optional bool is_eps_online = 1 [default = false];
optional bool is_epb_online = 2 [default = false];
optional bool is_esp_online = 3 [default = false];
optional bool is_vtog_online = 4 [default = false];
optional bool is_scu_online = 5 [default = false];
optional bool is_switch_online = 6 [default = false];
optional bool is_vcu_online = 7 [default = false];
}
message Transit {
optional Llc_vehiclelimits_24 llc_vehiclelimits_24 = 1; // report message
optional Adc_motioncontrol1_10 adc_motioncontrol1_10 = 2; // control message
optional Adc_motioncontrollimits1_12 adc_motioncontrollimits1_12 =
3; // control message
optional Llc_motionfeedback1_20 llc_motionfeedback1_20 = 4; // report message
optional Llc_motionfeedback2_21 llc_motionfeedback2_21 = 5; // report message
optional Llc_motioncommandfeedback1_22 llc_motioncommandfeedback1_22 =
6; // report message
optional Llc_vehiclestatus_25 llc_vehiclestatus_25 = 7; // report message
optional Llc_auxiliaryfeedback_120 llc_auxiliaryfeedback_120 =
8; // report message
optional Llc_diag_fault_620 llc_diag_fault_620 = 9; // report message
optional Llc_diag_steeringcontrol_722 llc_diag_steeringcontrol_722 =
10; // control message
optional Adc_auxiliarycontrol_110 adc_auxiliarycontrol_110 =
11; // control message
optional Llc_diag_brakecontrol_721 llc_diag_brakecontrol_721 =
12; // control message
optional CheckResponseSignal check_response = 100;
}
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/proto/BUILD
|
## Auto generated by `proto_build_generator.py`
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_proto_library")
load("//tools:python_rules.bzl", "py_proto_library")
package(default_visibility = ["//visibility:public"])
cc_proto_library(
name = "transit_cc_proto",
deps = [
":transit_proto",
],
)
proto_library(
name = "transit_proto",
srcs = ["transit.proto"],
)
py_proto_library(
name = "transit_py_pb2",
deps = [
":transit_proto",
],
)
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_auxiliaryfeedback_120.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_auxiliaryfeedback_120.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
Llcauxiliaryfeedback120::Llcauxiliaryfeedback120() {}
const int32_t Llcauxiliaryfeedback120::ID = 0x120;
void Llcauxiliaryfeedback120::Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const {
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_inverter(
llc_fbk_inverter(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch8(
llc_fbk_pdu_ch8(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch7(
llc_fbk_pdu_ch7(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch6(
llc_fbk_pdu_ch6(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch5(
llc_fbk_pdu_ch5(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch4(
llc_fbk_pdu_ch4(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch3(
llc_fbk_pdu_ch3(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch2(
llc_fbk_pdu_ch2(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_pdu_ch1(
llc_fbk_pdu_ch1(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_hazardlights(
llc_fbk_hazardlights(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_ledgreenon(
llc_fbk_ledgreenon(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_horn(
llc_fbk_horn(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_buzzeron(
llc_fbk_buzzeron(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_turnsignal(
llc_fbk_turnsignal(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_lowbeam(
llc_fbk_lowbeam(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_highbeam(
llc_fbk_highbeam(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()->set_llc_fbk_ledredon(
llc_fbk_ledredon(bytes, length));
chassis->mutable_llc_auxiliaryfeedback_120()
->set_llc_fbk_autonomybuttonpressed(
llc_fbk_autonomybuttonpressed(bytes, length));
}
// config detail: {'description': 'Inverter enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_inverter', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 2, 'type': 'bool', 'order': 'intel',
// 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_inverter(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(2, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 8 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch8', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 15, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch8(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(7, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 7 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch7', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 14, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch7(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(6, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 6 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch6', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 13, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch6(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(5, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 5 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch5', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 12, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch5(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(4, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 4 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch4', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 11, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch4(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(3, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 3 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch3', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 10, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch3(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(2, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 2 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch2', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 9, 'type': 'bool', 'order': 'intel',
// 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch2(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(1, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'PDU Channel 1 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_pdu_ch1', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 8, 'type': 'bool', 'order': 'intel',
// 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_pdu_ch1(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Hazard lights enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_hazardlights', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 28, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_hazardlights(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(4, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Autonomy indicator green LED on', 'offset':
// 0.0, 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_ledgreenon',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 17, 'type': 'bool',
// 'order': 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_ledgreenon(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(1, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Horn enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_horn', 'is_signed_var': False,
// 'physical_range': '[0|1]', 'bit': 3, 'type': 'bool', 'order': 'intel',
// 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_horn(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(3, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Buzzer enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_buzzeron', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 19, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_buzzeron(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(3, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Current turn signal status', 'enum': {0:
// 'LLC_FBK_TURNSIGNAL_NONE', 1: 'LLC_FBK_TURNSIGNAL_LEFT', 2:
// 'LLC_FBK_TURNSIGNAL_RIGHT', 3: 'LLC_FBK_TURNSIGNAL_RESERVE'},
// 'precision': 1.0, 'len': 2, 'name': 'llc_fbk_turnsignal', 'is_signed_var':
// False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 24, 'type': 'enum',
// 'order': 'intel', 'physical_unit': ''}
Llc_auxiliaryfeedback_120::Llc_fbk_turnsignalType
Llcauxiliaryfeedback120::llc_fbk_turnsignal(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 2);
Llc_auxiliaryfeedback_120::Llc_fbk_turnsignalType ret =
static_cast<Llc_auxiliaryfeedback_120::Llc_fbk_turnsignalType>(x);
return ret;
}
// config detail: {'description': 'Low beam enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_lowbeam', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 26, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_lowbeam(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(2, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'High beam enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_highbeam', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 27, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_highbeam(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(3, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Autonomy indicator red LED on', 'offset':
// 0.0, 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_ledredon', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 18, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_ledredon(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(2, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Autonomy button is pressed', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_autonomybuttonpressed',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 16, 'type': 'bool',
// 'order': 'intel', 'physical_unit': 'T/F'}
bool Llcauxiliaryfeedback120::llc_fbk_autonomybuttonpressed(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 1);
bool ret = x;
return ret;
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_motionfeedback2_21.h
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "gtest/gtest_prod.h"
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace transit {
class Llcmotionfeedback221 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Transit> {
public:
static const int32_t ID;
Llcmotionfeedback221();
void Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const override;
FRIEND_TEST(llc_motionfeedback2_21Test, motion_fdk);
private:
// config detail: {'name': 'LLC_FBK_VehicleSpeed', 'offset': 0.0, 'precision':
// 0.01, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|655.35]',
// 'bit': 32, 'type': 'double', 'order': 'intel', 'physical_unit': 'm/s'}
double llc_fbk_vehiclespeed(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Motion feedback 2 heartbeat counter',
// 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name':
// 'LLC_MotionFeedback2_Counter', 'is_signed_var': False, 'physical_range':
// '[0|3]', 'bit': 54, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int llc_motionfeedback2_counter(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Motion feedback 2 checksum', 'offset': 0.0,
// 'precision': 1.0, 'len': 8, 'name': 'LLC_MotionFeedback2_Checksum',
// 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 56, 'type':
// 'int', 'order': 'intel', 'physical_unit': ''}
int llc_motionfeedback2_checksum(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Steer wheel angle feedback from SbW motor
// (? rate)', 'offset': 0.0, 'precision': 0.05, 'len': 16, 'name':
// 'LLC_FBK_SteeringRate', 'is_signed_var': True, 'physical_range':
// '[-1638.4|1638.3]', 'bit': 16, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'deg/s'}
double llc_fbk_steeringrate(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Steering angle feedback', 'offset': 0.0,
// 'precision': 0.05, 'len': 16, 'name': 'LLC_FBK_SteeringAngle',
// 'is_signed_var': True, 'physical_range': '[-1638.4|1638.35]', 'bit': 0,
// 'type': 'double', 'order': 'intel', 'physical_unit': 'deg'}
double llc_fbk_steeringangle(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_motionfeedback2_21.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_motionfeedback2_21.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
Llcmotionfeedback221::Llcmotionfeedback221() {}
const int32_t Llcmotionfeedback221::ID = 0x21;
void Llcmotionfeedback221::Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const {
chassis->mutable_llc_motionfeedback2_21()->set_llc_fbk_vehiclespeed(
llc_fbk_vehiclespeed(bytes, length));
chassis->mutable_llc_motionfeedback2_21()->set_llc_motionfeedback2_counter(
llc_motionfeedback2_counter(bytes, length));
chassis->mutable_llc_motionfeedback2_21()->set_llc_motionfeedback2_checksum(
llc_motionfeedback2_checksum(bytes, length));
chassis->mutable_llc_motionfeedback2_21()->set_llc_fbk_steeringrate(
llc_fbk_steeringrate(bytes, length));
chassis->mutable_llc_motionfeedback2_21()->set_llc_fbk_steeringangle(
llc_fbk_steeringangle(bytes, length));
}
// config detail: {'name': 'llc_fbk_vehiclespeed', 'offset': 0.0, 'precision':
// 0.01, 'len': 16, 'is_signed_var': False, 'physical_range': '[0|655.35]',
// 'bit': 32, 'type': 'double', 'order': 'intel', 'physical_unit': 'm/s'}
double Llcmotionfeedback221::llc_fbk_vehiclespeed(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 4);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
double ret = x * 0.010000;
return ret;
}
// config detail: {'description': 'Motion feedback 2 heartbeat counter',
// 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name':
// 'llc_motionfeedback2_counter', 'is_signed_var': False, 'physical_range':
// '[0|3]', 'bit': 54, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int Llcmotionfeedback221::llc_motionfeedback2_counter(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(6, 2);
int ret = x;
return ret;
}
// config detail: {'description': 'Motion feedback 2 checksum', 'offset': 0.0,
// 'precision': 1.0, 'len': 8, 'name': 'llc_motionfeedback2_checksum',
// 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 56, 'type':
// 'int', 'order': 'intel', 'physical_unit': ''}
int Llcmotionfeedback221::llc_motionfeedback2_checksum(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'description': 'Steer wheel angle feedback from SbW motor (?
// rate)', 'offset': 0.0, 'precision': 0.05, 'len': 16, 'name':
// 'llc_fbk_steeringrate', 'is_signed_var': True, 'physical_range':
// '[-1638.4|1638.3]', 'bit': 16, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'deg/s'}
double Llcmotionfeedback221::llc_fbk_steeringrate(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.050000;
return ret;
}
// config detail: {'description': 'Steering angle feedback', 'offset': 0.0,
// 'precision': 0.05, 'len': 16, 'name': 'llc_fbk_steeringangle',
// 'is_signed_var': True, 'physical_range': '[-1638.4|1638.35]', 'bit': 0,
// 'type': 'double', 'order': 'intel', 'physical_unit': 'deg'}
double Llcmotionfeedback221::llc_fbk_steeringangle(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 0);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.050000;
return ret;
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_motioncommandfeedback1_22_test.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_motioncommandfeedback1_22.h"
#include "gtest/gtest.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
class Motioncommandfeedback1_22_test : public ::testing::Test {
public:
virtual void SetUp() {}
protected:
Llcmotioncommandfeedback122 feedback_;
};
TEST_F(Motioncommandfeedback1_22_test, General) {
const uint8_t bytes[8] = {0x8f, 0x9e, 0xad, 0xbc, 0xcb, 0xda, 0xe9, 0xf8};
const int32_t length_Steeringanglesetpoint = 16;
const int32_t length_Throttlesetpoint = 10;
const int32_t length_Brakepercentsetpoint = 11;
const int32_t length_Motioncommandfeedback1_count = 2;
const int32_t length_Motioncommandfeedback1_check = 8;
const double equivalent_Steeringanglesetpoint = 1201.85;
const double equivalent_Throttlesetpoint = 43.50;
const double equivalent_Brakepercentsetpoint = 93.3524;
const int equivalent_Motioncommandfeedback1_count = 3;
const int equivalent_Motioncommandfeedback1_check = 248;
EXPECT_DOUBLE_EQ(feedback_.llc_fbk_steeringanglesetpoint(
bytes, length_Steeringanglesetpoint),
equivalent_Steeringanglesetpoint);
EXPECT_DOUBLE_EQ(
feedback_.llc_fbk_throttlesetpoint(bytes, length_Throttlesetpoint),
equivalent_Throttlesetpoint);
EXPECT_DOUBLE_EQ(feedback_.llc_fbk_brakepercentsetpoint(
bytes, length_Brakepercentsetpoint),
equivalent_Brakepercentsetpoint);
EXPECT_EQ(feedback_.llc_motioncommandfeedback1_count(
bytes, length_Motioncommandfeedback1_count),
equivalent_Motioncommandfeedback1_count);
EXPECT_EQ(feedback_.llc_motioncommandfeedback1_check(
bytes, length_Motioncommandfeedback1_check),
equivalent_Motioncommandfeedback1_check);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_motionfeedback1_20.h
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "gtest/gtest_prod.h"
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace transit {
class Llcmotionfeedback120 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Transit> {
public:
static const int32_t ID;
Llcmotionfeedback120();
void Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const override;
FRIEND_TEST(Motionfeedback1_20_test, General);
private:
// config detail: {'description': 'Current gear', 'enum': {0:
// 'LLC_FBK_GEAR_P_PARK', 1: 'LLC_FBK_GEAR_D_DRIVE', 2:
// 'LLC_FBK_GEAR_N_NEUTRAL', 3: 'LLC_FBK_GEAR_R_REVERSE'}, 'precision': 1.0,
// 'len': 3, 'name': 'LLC_FBK_Gear', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|3]', 'bit': 50, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_gearType llc_fbk_gear(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'Parking brake applied', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_ParkingBrake',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 53, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_parkingbrake(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Throttle position feedback', 'offset': 0.0,
// 'precision': 0.1, 'len': 10, 'name': 'LLC_FBK_ThrottlePosition',
// 'is_signed_var': False, 'physical_range': '[0|102.3]', 'bit': 38, 'type':
// 'double', 'order': 'intel', 'physical_unit': '%'}
double llc_fbk_throttleposition(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Rear brake pressure feedback', 'offset':
// 0.0, 'precision': 0.0556, 'len': 11, 'name': 'LLC_FBK_BrakePercentRear',
// 'is_signed_var': False, 'physical_range': '[0|113.8132]', 'bit': 27,
// 'type': 'double', 'order': 'intel', 'physical_unit': '%'}
double llc_fbk_brakepercentrear(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Front brake pressure feedback', 'offset':
// 0.0, 'precision': 0.0556, 'len': 11, 'name': 'LLC_FBK_BrakePercentFront',
// 'is_signed_var': False, 'physical_range': '[0|113.8132]', 'bit': 16,
// 'type': 'double', 'order': 'intel', 'physical_unit': '%'}
double llc_fbk_brakepercentfront(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Current steering control mode', 'enum': {0:
// 'LLC_FBK_STEERINGCONTROLMODE_NONE', 1: 'LLC_FBK_STEERINGCONTROLMODE_ANGLE',
// 2: 'LLC_FBK_STEERINGCONTROLMODE_RESERVED_CURVATURE', 3:
// 'LLC_FBK_STEERINGCONTROLMODE_RESERVED'}, 'precision': 1.0, 'len': 2,
// 'name': 'LLC_FBK_SteeringControlMode', 'is_signed_var': False, 'offset':
// 0.0, 'physical_range': '[0|3]', 'bit': 6, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_steeringcontrolmodeType
llc_fbk_steeringcontrolmode(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Motion feedback 1 heartbeat counter',
// 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name':
// 'LLC_MotionFeedback1_Counter', 'is_signed_var': False, 'physical_range':
// '[0|3]', 'bit': 54, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int llc_motionfeedback1_counter(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Motion feedback 1 checksum', 'offset': 0.0,
// 'precision': 1.0, 'len': 8, 'name': 'LLC_MotionFeedback1_Checksum',
// 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 56, 'type':
// 'int', 'order': 'intel', 'physical_unit': ''}
int llc_motionfeedback1_checksum(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Autonomy command aligned with vehicle state
// according to calibration limits', 'offset': 0.0, 'precision': 1.0, 'len':
// 1, 'name': 'LLC_FBK_CommandAligned', 'is_signed_var': False,
// 'physical_range': '[0|1]', 'bit': 11, 'type': 'bool', 'order': 'intel',
// 'physical_unit': 'T/F'}
bool llc_fbk_commandaligned(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Estop is pressed', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_EstopPressed',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 10, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_estoppressed(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Indicates that ADC is requesting autonomy
// mode', 'offset': 0.0, 'precision': 1.0, 'len': 1, 'name':
// 'LLC_FBK_AdcRequestAutonomy', 'is_signed_var': False, 'physical_range':
// '[0|1]', 'bit': 9, 'type': 'bool', 'order': 'intel', 'physical_unit':
// 'T/F'}
bool llc_fbk_adcrequestautonomy(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Indicates that LLC is ready to allow
// autonomy mode', 'offset': 0.0, 'precision': 1.0, 'len': 1, 'name':
// 'LLC_FBK_allowAutonomy', 'is_signed_var': False, 'physical_range': '[0|1]',
// 'bit': 8, 'type': 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_allowautonomy(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Report current longitudinal control mode',
// 'enum': {0: 'LLC_FBK_LONGITUDINALCONTROLMODE_NONE', 1:
// 'LLC_FBK_LONGITUDINALCONTROLMODE_RESERVED_VELOCITY_AND_ACCELERATION', 2:
// 'LLC_FBK_LONGITUDINALCONTROLMODE_RESERVED_FORCE', 3:
// 'LLC_FBK_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE'}, 'precision': 1.0,
// 'len': 2, 'name': 'LLC_FBK_LongitudinalControlMode', 'is_signed_var':
// False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 4, 'type': 'enum',
// 'order': 'intel', 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_longitudinalcontrolmodeType
llc_fbk_longitudinalcontrolmode(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Current Autonomy State', 'enum': {0:
// 'LLC_FBK_STATE_RESERVED0', 1: 'LLC_FBK_STATE_AUTONOMY_NOT_ALLOWED', 2:
// 'LLC_FBK_STATE_AUTONOMY_ALLOWED', 3: 'LLC_FBK_STATE_AUTONOMY_REQUESTED', 4:
// 'LLC_FBK_STATE_AUTONOMY', 5: 'LLC_FBK_STATE_RESERVED1', 6:
// 'LLC_FBK_STATE_RESERVED2', 7: 'LLC_FBK_STATE_RESERVED3', 8:
// 'LLC_FBK_STATE_RESERVED4', 9: 'LLC_FBK_STATE_RESERVED5', 10:
// 'LLC_FBK_STATE_RESERVED6', 11: 'LLC_FBK_STATE_RESERVED7', 12:
// 'LLC_FBK_STATE_RESERVED8', 13: 'LLC_FBK_STATE_DISENGAGE_REQUESTED', 14:
// 'LLC_FBK_STATE_DISENGAGED', 15: 'LLC_FBK_STATE_FAULT'}, 'precision': 1.0,
// 'len': 4, 'name': 'LLC_FBK_State', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|15]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_stateType llc_fbk_state(
const std::uint8_t* bytes, const int32_t length) const;
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_motioncommandfeedback1_22.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_motioncommandfeedback1_22.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
Llcmotioncommandfeedback122::Llcmotioncommandfeedback122() {}
const int32_t Llcmotioncommandfeedback122::ID = 0x22;
void Llcmotioncommandfeedback122::Parse(const std::uint8_t* bytes,
int32_t length,
Transit* chassis) const {
chassis->mutable_llc_motioncommandfeedback1_22()
->set_llc_fbk_steeringanglesetpoint(
llc_fbk_steeringanglesetpoint(bytes, length));
chassis->mutable_llc_motioncommandfeedback1_22()
->set_llc_fbk_throttlesetpoint(llc_fbk_throttlesetpoint(bytes, length));
chassis->mutable_llc_motioncommandfeedback1_22()
->set_llc_fbk_brakepercentsetpoint(
llc_fbk_brakepercentsetpoint(bytes, length));
chassis->mutable_llc_motioncommandfeedback1_22()
->set_llc_motioncommandfeedback1_count(
llc_motioncommandfeedback1_count(bytes, length));
chassis->mutable_llc_motioncommandfeedback1_22()
->set_llc_motioncommandfeedback1_check(
llc_motioncommandfeedback1_check(bytes, length));
}
// config detail: {'description': 'Steering angle setpoint (after limits)',
// 'offset': 0.0, 'precision': 0.05, 'len': 16, 'name':
// 'llc_fbk_steeringanglesetpoint', 'is_signed_var': True, 'physical_range':
// '[-1638.4|1638.35]', 'bit': 21, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'deg'}
double Llcmotioncommandfeedback122::llc_fbk_steeringanglesetpoint(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 5);
Byte t1(bytes + 3);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
Byte t2(bytes + 2);
t = t2.get_byte(5, 3);
x <<= 3;
x |= t;
x <<= 16;
x >>= 16;
double ret = x * 0.050000;
return ret;
}
// config detail: {'description': 'Current throttle setpoint (after limits)',
// 'offset': 0.0, 'precision': 0.1, 'len': 10, 'name':
// 'llc_fbk_throttlesetpoint', 'is_signed_var': False, 'physical_range':
// '[0|102.3]', 'bit': 11, 'type': 'double', 'order': 'intel', 'physical_unit':
// '%'}
double Llcmotioncommandfeedback122::llc_fbk_throttlesetpoint(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 5);
Byte t1(bytes + 1);
int32_t t = t1.get_byte(3, 5);
x <<= 5;
x |= t;
double ret = x * 0.100000;
return ret;
}
// config detail: {'description': 'Front brake pressure setpoint (after
// limits)', 'offset': 0.0, 'precision': 0.0556, 'len': 11, 'name':
// 'llc_fbk_brakepercentsetpoint', 'is_signed_var': False, 'physical_range':
// '[0|113.8132]', 'bit': 0, 'type': 'double', 'order': 'intel',
// 'physical_unit': '%'}
double Llcmotioncommandfeedback122::llc_fbk_brakepercentsetpoint(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 3);
Byte t1(bytes + 0);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
double ret = x * 0.055600;
return ret;
}
// config detail: {'description': 'Motion command feedback 2 heartbeat counter',
// 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name':
// 'llc_motioncommandfeedback1_count', 'is_signed_var': False, 'physical_range':
// '[0|3]', 'bit': 54, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int Llcmotioncommandfeedback122::llc_motioncommandfeedback1_count(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(6, 2);
int ret = x;
return ret;
}
// config detail: {'description': 'Motion command feedback 1 checksum',
// 'offset': 0.0, 'precision': 1.0, 'len': 8, 'name':
// 'llc_motioncommandfeedback1_check', 'is_signed_var': False, 'physical_range':
// '[0|255]', 'bit': 56, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int Llcmotioncommandfeedback122::llc_motioncommandfeedback1_check(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_diag_steeringcontrol_722_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_diag_steeringcontrol_722.h"
#include "gtest/gtest.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
class llc_diag_steeringcontrol_722Test : public ::testing ::Test {
public:
virtual void SetUp() {}
};
TEST_F(llc_diag_steeringcontrol_722Test, General) {
Llcdiagsteeringcontrol722 steeringctrl_722_;
uint8_t data[7] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
EXPECT_EQ(steeringctrl_722_.GetPeriod(), 10 * 1000);
double pos = 3;
int torque = 0xF;
steeringctrl_722_.set_llc_dbg_steeringsensorposition(pos);
steeringctrl_722_.set_llc_dbg_steeringrackinputtorque(torque);
steeringctrl_722_.set_llc_dbg_steeringmotorposition(pos);
steeringctrl_722_.UpdateData(data);
EXPECT_EQ(data[0], 0xE0);
EXPECT_EQ(data[1], 0x93);
EXPECT_EQ(data[2], 0x4);
EXPECT_EQ(data[3], 0xF);
EXPECT_EQ(data[4], 0x0);
EXPECT_EQ(data[5], 0x98);
EXPECT_EQ(data[6], 0x3A);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_diag_brakecontrol_721.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_diag_brakecontrol_721.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
const int32_t Llcdiagbrakecontrol721::ID = 0x721;
// public
Llcdiagbrakecontrol721::Llcdiagbrakecontrol721() { Reset(); }
uint32_t Llcdiagbrakecontrol721::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 10 * 1000;
return PERIOD;
}
void Llcdiagbrakecontrol721::UpdateData(uint8_t* data) {
set_p_llc_dbg_brakepidcontribution_p(data, llc_dbg_brakepidcontribution_p_);
set_p_llc_dbg_brakepidcontribution_i(data, llc_dbg_brakepidcontribution_i_);
set_p_llc_dbg_brakepidcontribution_d(data, llc_dbg_brakepidcontribution_d_);
set_p_llc_dbg_brakepid_output(data, llc_dbg_brakepid_output_);
set_p_llc_dbg_brakepid_error(data, llc_dbg_brakepid_error_);
set_p_llc_dbg_brakefeedforward(data, llc_dbg_brakefeedforward_);
}
void Llcdiagbrakecontrol721::Reset() {
// TODO(All) : you should check this manually
llc_dbg_brakepidcontribution_p_ = 0.0;
llc_dbg_brakepidcontribution_i_ = 0.0;
llc_dbg_brakepidcontribution_d_ = 0.0;
llc_dbg_brakepid_output_ = 0.0;
llc_dbg_brakepid_error_ = 0;
llc_dbg_brakefeedforward_ = 0.0;
}
Llcdiagbrakecontrol721*
Llcdiagbrakecontrol721::set_llc_dbg_brakepidcontribution_p(
double llc_dbg_brakepidcontribution_p) {
llc_dbg_brakepidcontribution_p_ = llc_dbg_brakepidcontribution_p;
return this;
}
// config detail: {'description': 'Brake control loop P contribution', 'offset':
// 0.0, 'precision': 0.1, 'len': 10, 'name': 'LLC_DBG_BrakePidContribution_P',
// 'is_signed_var': True, 'physical_range': '[-51.2|51.1]', 'bit': 34, 'type':
// 'double', 'order': 'intel', 'physical_unit': 'mrev'}
void Llcdiagbrakecontrol721::set_p_llc_dbg_brakepidcontribution_p(
uint8_t* data, double llc_dbg_brakepidcontribution_p) {
llc_dbg_brakepidcontribution_p =
ProtocolData::BoundedValue(-51.2, 51.1, llc_dbg_brakepidcontribution_p);
int x = static_cast<int>(llc_dbg_brakepidcontribution_p / 0.100000);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0x3F);
Byte to_set0(data + 4);
to_set0.set_value(t, 2, 6);
x >>= 6;
t = static_cast<uint8_t>(x & 0xF);
Byte to_set1(data + 5);
to_set1.set_value(t, 0, 4);
}
Llcdiagbrakecontrol721*
Llcdiagbrakecontrol721::set_llc_dbg_brakepidcontribution_i(
double llc_dbg_brakepidcontribution_i) {
llc_dbg_brakepidcontribution_i_ = llc_dbg_brakepidcontribution_i;
return this;
}
// config detail: {'description': 'Brake control loop I contribution', 'offset':
// 0.0, 'precision': 0.1, 'len': 10, 'name': 'LLC_DBG_BrakePidContribution_I',
// 'is_signed_var': True, 'physical_range': '[-51.2|51.1]', 'bit': 44, 'type':
// 'double', 'order': 'intel', 'physical_unit': 'mrev'}
void Llcdiagbrakecontrol721::set_p_llc_dbg_brakepidcontribution_i(
uint8_t* data, double llc_dbg_brakepidcontribution_i) {
llc_dbg_brakepidcontribution_i =
ProtocolData::BoundedValue(-51.2, 51.1, llc_dbg_brakepidcontribution_i);
int x = static_cast<int>(llc_dbg_brakepidcontribution_i / 0.100000);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xF);
Byte to_set0(data + 5);
to_set0.set_value(t, 4, 4);
x >>= 4;
t = static_cast<uint8_t>(x & 0x3F);
Byte to_set1(data + 6);
to_set1.set_value(t, 0, 6);
}
Llcdiagbrakecontrol721*
Llcdiagbrakecontrol721::set_llc_dbg_brakepidcontribution_d(
double llc_dbg_brakepidcontribution_d) {
llc_dbg_brakepidcontribution_d_ = llc_dbg_brakepidcontribution_d;
return this;
}
// config detail: {'description': 'Brake control loop D contribution', 'offset':
// 0.0, 'precision': 0.1, 'len': 10, 'name': 'LLC_DBG_BrakePidContribution_D',
// 'is_signed_var': True, 'physical_range': '[-51.2|51.1]', 'bit': 54, 'type':
// 'double', 'order': 'intel', 'physical_unit': 'mrev'}
void Llcdiagbrakecontrol721::set_p_llc_dbg_brakepidcontribution_d(
uint8_t* data, double llc_dbg_brakepidcontribution_d) {
llc_dbg_brakepidcontribution_d =
ProtocolData::BoundedValue(-51.2, 51.1, llc_dbg_brakepidcontribution_d);
int x = static_cast<int>(llc_dbg_brakepidcontribution_d / 0.100000);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0x3);
Byte to_set0(data + 6);
to_set0.set_value(t, 6, 2);
x >>= 2;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set1(data + 7);
to_set1.set_value(t, 0, 8);
}
Llcdiagbrakecontrol721* Llcdiagbrakecontrol721::set_llc_dbg_brakepid_output(
double llc_dbg_brakepid_output) {
llc_dbg_brakepid_output_ = llc_dbg_brakepid_output;
return this;
}
// config detail: {'description': 'Brake control loop output', 'offset': 0.0,
// 'precision': 0.1, 'len': 10, 'name': 'LLC_DBG_BrakePID_Output',
// 'is_signed_var': True, 'physical_range': '[-51.2|51.1]', 'bit': 12, 'type':
// 'double', 'order': 'intel', 'physical_unit': 'mrev'}
void Llcdiagbrakecontrol721::set_p_llc_dbg_brakepid_output(
uint8_t* data, double llc_dbg_brakepid_output) {
llc_dbg_brakepid_output =
ProtocolData::BoundedValue(-51.2, 51.1, llc_dbg_brakepid_output);
int x = static_cast<int>(llc_dbg_brakepid_output / 0.100000);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xF);
Byte to_set0(data + 1);
to_set0.set_value(t, 4, 4);
x >>= 4;
t = static_cast<uint8_t>(x & 0x3F);
Byte to_set1(data + 2);
to_set1.set_value(t, 0, 6);
}
Llcdiagbrakecontrol721* Llcdiagbrakecontrol721::set_llc_dbg_brakepid_error(
int llc_dbg_brakepid_error) {
llc_dbg_brakepid_error_ = llc_dbg_brakepid_error;
return this;
}
// config detail: {'description': 'Brake control loop error', 'offset': 0.0,
// 'precision': 1.0, 'len': 12, 'name': 'LLC_DBG_BrakePID_Error',
// 'is_signed_var': True, 'physical_range': '[-2048|2047]', 'bit': 0, 'type':
// 'int', 'order': 'intel', 'physical_unit': 'psi'}
void Llcdiagbrakecontrol721::set_p_llc_dbg_brakepid_error(
uint8_t* data, int llc_dbg_brakepid_error) {
llc_dbg_brakepid_error =
ProtocolData::BoundedValue(-2048, 2047, llc_dbg_brakepid_error);
int x = llc_dbg_brakepid_error;
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set0(data + 0);
to_set0.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0xF);
Byte to_set1(data + 1);
to_set1.set_value(t, 0, 4);
}
Llcdiagbrakecontrol721* Llcdiagbrakecontrol721::set_llc_dbg_brakefeedforward(
double llc_dbg_brakefeedforward) {
llc_dbg_brakefeedforward_ = llc_dbg_brakefeedforward;
return this;
}
// config detail: {'description': 'Brake control feedforward contribution',
// 'offset': 0.0, 'precision': 0.5, 'len': 12, 'name':
// 'LLC_DBG_BrakeFeedforward', 'is_signed_var': True, 'physical_range':
// '[-1024|1023.5]', 'bit': 22, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'mrev'}
void Llcdiagbrakecontrol721::set_p_llc_dbg_brakefeedforward(
uint8_t* data, double llc_dbg_brakefeedforward) {
llc_dbg_brakefeedforward =
ProtocolData::BoundedValue(-1024.0, 1023.5, llc_dbg_brakefeedforward);
int x = static_cast<int>(llc_dbg_brakefeedforward / 0.500000);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0x3);
Byte to_set0(data + 2);
to_set0.set_value(t, 6, 2);
x >>= 2;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set1(data + 3);
to_set1.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0x3);
Byte to_set2(data + 4);
to_set2.set_value(t, 0, 2);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/adc_motioncontrol1_10.h
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
#include "gtest/gtest_prod.h"
namespace apollo {
namespace canbus {
namespace transit {
class Adcmotioncontrol110 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Transit> {
public:
static const int32_t ID;
Adcmotioncontrol110();
uint32_t GetPeriod() const override;
void UpdateData(uint8_t* data) override;
void Reset() override;
// config detail: {'description': 'Setpoint for steering wheel angle. Positive
// for CW', 'offset': 0.0, 'precision': -0.05, 'len': 16, 'name':
// 'ADC_CMD_SteerWheelAngle', 'is_signed_var': True, 'physical_range':
// '[-1638.4|1638.35]', 'bit': 27, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'deg'}
Adcmotioncontrol110* set_adc_cmd_steerwheelangle(
double adc_cmd_steerwheelangle);
// config detail: {'description': 'Select steering control mode', 'enum': {0:
// 'ADC_CMD_STEERINGCONTROLMODE_NONE', 1: 'ADC_CMD_STEERINGCONTROLMODE_ANGLE',
// 2: 'ADC_CMD_STEERINGCONTROLMODE_RESERVED_CURVATURE', 3:
// 'ADC_CMD_STEERINGCONTROLMODE_RESERVED'}, 'precision': 1.0, 'len': 2,
// 'name': 'ADC_CMD_SteeringControlMode', 'is_signed_var': False, 'offset':
// 0.0, 'physical_range': '[0|3]', 'bit': 4, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Adcmotioncontrol110* set_adc_cmd_steeringcontrolmode(
Adc_motioncontrol1_10::Adc_cmd_steeringcontrolmodeType
adc_cmd_steeringcontrolmode);
// config detail: {'description': '(Reserved) Control parking brake',
// 'offset': 0.0, 'precision': 1.0, 'len': 1, 'name': 'ADC_CMD_ParkingBrake',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 53, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
Adcmotioncontrol110* set_adc_cmd_parkingbrake(bool adc_cmd_parkingbrake);
// config detail: {'description': 'Transmission control - only used in direct
// longitudinal control', 'enum': {0: 'ADC_CMD_GEAR_P_PARK', 1:
// 'ADC_CMD_GEAR_D_DRIVE', 2: 'ADC_CMD_GEAR_N_NEUTRAL', 3:
// 'ADC_CMD_GEAR_R_REVERSE'}, 'precision': 1.0, 'len': 3, 'name':
// 'ADC_CMD_Gear', 'is_signed_var': False, 'offset': 0.0, 'physical_range':
// '[0|7]', 'bit': 50, 'type': 'enum', 'order': 'intel', 'physical_unit': ''}
Adcmotioncontrol110* set_adc_cmd_gear(
Adc_motioncontrol1_10::Adc_cmd_gearType adc_cmd_gear);
// config detail: {'description': 'Motion Control 1 checksum', 'offset': 0.0,
// 'precision': 1.0, 'len': 8, 'name': 'ADC_MotionControl1_Checksum',
// 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 56, 'type':
// 'int', 'order': 'intel', 'physical_unit': ''}
Adcmotioncontrol110* set_adc_motioncontrol1_checksum(
int adc_motioncontrol1_checksum);
// config detail: {'description': 'Brake pressure for direct longitudinal
// control', 'offset': 0.0, 'precision': 0.0556, 'len': 11, 'name':
// 'ADC_CMD_BrakePercentage', 'is_signed_var': False, 'physical_range':
// '[0|113.8132]', 'bit': 6, 'type': 'double', 'order': 'intel',
// 'physical_unit': '%'}
Adcmotioncontrol110* set_adc_cmd_brakepercentage(
double adc_cmd_brakepercentage);
// config detail: {'description': 'Throttle pedal position percentage for
// direct longitudinal control', 'offset': 0.0, 'precision': 0.1, 'len': 10,
// 'name': 'ADC_CMD_ThrottlePosition', 'is_signed_var': False,
// 'physical_range': '[0|100]', 'bit': 17, 'type': 'double', 'order': 'intel',
// 'physical_unit': '%'}
Adcmotioncontrol110* set_adc_cmd_throttleposition(
double adc_cmd_throttleposition);
// config detail: {'description': 'Motion control 1 Heartbeat counter',
// 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name':
// 'ADC_MotionControl1_Counter', 'is_signed_var': False, 'physical_range':
// '[0|3]', 'bit': 54, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
Adcmotioncontrol110* set_adc_motioncontrol1_counter(
int adc_motioncontrol1_counter);
// config detail: {'description': 'Request from ADC to LLC for autonomy',
// 'enum': {0: 'ADC_CMD_AUTONOMYREQUEST_AUTONOMY_NOT_REQUESTED', 1:
// 'ADC_CMD_AUTONOMYREQUEST_AUTONOMY_REQUESTED', 2:
// 'ADC_CMD_AUTONOMYREQUEST_RESERVED0', 3:
// 'ADC_CMD_AUTONOMYREQUEST_RESERVED1'}, 'precision': 1.0, 'len': 2, 'name':
// 'ADC_CMD_AutonomyRequest', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|3]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Adcmotioncontrol110* set_adc_cmd_autonomyrequest(
Adc_motioncontrol1_10::Adc_cmd_autonomyrequestType
adc_cmd_autonomyrequest);
// config detail: {'description': 'Select longitudinal control mode', 'enum':
// {0: 'ADC_CMD_LONGITUDINALCONTROLMODE_NONE', 1:
// 'ADC_CMD_LONGITUDINALCONTROLMODE_RESERVED_VELOCITY_AND_ACCELERATION', 2:
// 'ADC_CMD_LONGITUDINALCONTROLMODE_RESERVED_FORCE', 3:
// 'ADC_CMD_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE'}, 'precision': 1.0,
// 'len': 2, 'name': 'ADC_CMD_LongitudinalControlMode', 'is_signed_var':
// False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 2, 'type': 'enum',
// 'order': 'intel', 'physical_unit': ''}
Adcmotioncontrol110* set_adc_cmd_longitudinalcontrolmode(
Adc_motioncontrol1_10::Adc_cmd_longitudinalcontrolmodeType
adc_cmd_longitudinalcontrolmode);
FRIEND_TEST(adc_motioncontrol1_10Test, part1);
FRIEND_TEST(adc_motioncontrol1_10Test, part2);
FRIEND_TEST(adc_motioncontrol1_10Test, part3);
FRIEND_TEST(adc_motioncontrol1_10Test, part4);
private:
// config detail: {'description': 'Setpoint for steering wheel angle. Positive
// for CW', 'offset': 0.0, 'precision': -0.05, 'len': 16, 'name':
// 'ADC_CMD_SteerWheelAngle', 'is_signed_var': True, 'physical_range':
// '[-1638.4|1638.35]', 'bit': 27, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'deg'}
void set_p_adc_cmd_steerwheelangle(uint8_t* data,
double adc_cmd_steerwheelangle);
// config detail: {'description': 'Select steering control mode', 'enum': {0:
// 'ADC_CMD_STEERINGCONTROLMODE_NONE', 1: 'ADC_CMD_STEERINGCONTROLMODE_ANGLE',
// 2: 'ADC_CMD_STEERINGCONTROLMODE_RESERVED_CURVATURE', 3:
// 'ADC_CMD_STEERINGCONTROLMODE_RESERVED'}, 'precision': 1.0, 'len': 2,
// 'name': 'ADC_CMD_SteeringControlMode', 'is_signed_var': False, 'offset':
// 0.0, 'physical_range': '[0|3]', 'bit': 4, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
void set_p_adc_cmd_steeringcontrolmode(
uint8_t* data, Adc_motioncontrol1_10::Adc_cmd_steeringcontrolmodeType
adc_cmd_steeringcontrolmode);
// config detail: {'description': '(Reserved) Control parking brake',
// 'offset': 0.0, 'precision': 1.0, 'len': 1, 'name': 'ADC_CMD_ParkingBrake',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 53, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
void set_p_adc_cmd_parkingbrake(uint8_t* data, bool adc_cmd_parkingbrake);
// config detail: {'description': 'Transmission control - only used in direct
// longitudinal control', 'enum': {0: 'ADC_CMD_GEAR_P_PARK', 1:
// 'ADC_CMD_GEAR_D_DRIVE', 2: 'ADC_CMD_GEAR_N_NEUTRAL', 3:
// 'ADC_CMD_GEAR_R_REVERSE'}, 'precision': 1.0, 'len': 3, 'name':
// 'ADC_CMD_Gear', 'is_signed_var': False, 'offset': 0.0, 'physical_range':
// '[0|7]', 'bit': 50, 'type': 'enum', 'order': 'intel', 'physical_unit': ''}
void set_p_adc_cmd_gear(uint8_t* data,
Adc_motioncontrol1_10::Adc_cmd_gearType adc_cmd_gear);
// config detail: {'description': 'Motion Control 1 checksum', 'offset': 0.0,
// 'precision': 1.0, 'len': 8, 'name': 'ADC_MotionControl1_Checksum',
// 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 56, 'type':
// 'int', 'order': 'intel', 'physical_unit': ''}
void set_p_adc_motioncontrol1_checksum(uint8_t* data,
int adc_motioncontrol1_checksum);
// config detail: {'description': 'Brake pressure for direct longitudinal
// control', 'offset': 0.0, 'precision': 0.0556, 'len': 11, 'name':
// 'ADC_CMD_BrakePercentage', 'is_signed_var': False, 'physical_range':
// '[0|113.8132]', 'bit': 6, 'type': 'double', 'order': 'intel',
// 'physical_unit': '%'}
void set_p_adc_cmd_brakepercentage(uint8_t* data,
double adc_cmd_brakepercentage);
// config detail: {'description': 'Throttle pedal position percentage for
// direct longitudinal control', 'offset': 0.0, 'precision': 0.1, 'len': 10,
// 'name': 'ADC_CMD_ThrottlePosition', 'is_signed_var': False,
// 'physical_range': '[0|100]', 'bit': 17, 'type': 'double', 'order': 'intel',
// 'physical_unit': '%'}
void set_p_adc_cmd_throttleposition(uint8_t* data,
double adc_cmd_throttleposition);
// config detail: {'description': 'Motion control 1 Heartbeat counter',
// 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name':
// 'ADC_MotionControl1_Counter', 'is_signed_var': False, 'physical_range':
// '[0|3]', 'bit': 54, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
void set_p_adc_motioncontrol1_counter(uint8_t* data,
int adc_motioncontrol1_counter);
// config detail: {'description': 'Request from ADC to LLC for autonomy',
// 'enum': {0: 'ADC_CMD_AUTONOMYREQUEST_AUTONOMY_NOT_REQUESTED', 1:
// 'ADC_CMD_AUTONOMYREQUEST_AUTONOMY_REQUESTED', 2:
// 'ADC_CMD_AUTONOMYREQUEST_RESERVED0', 3:
// 'ADC_CMD_AUTONOMYREQUEST_RESERVED1'}, 'precision': 1.0, 'len': 2, 'name':
// 'ADC_CMD_AutonomyRequest', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|3]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
void set_p_adc_cmd_autonomyrequest(
uint8_t* data, Adc_motioncontrol1_10::Adc_cmd_autonomyrequestType
adc_cmd_autonomyrequest);
// config detail: {'description': 'Select longitudinal control mode', 'enum':
// {0: 'ADC_CMD_LONGITUDINALCONTROLMODE_NONE', 1:
// 'ADC_CMD_LONGITUDINALCONTROLMODE_RESERVED_VELOCITY_AND_ACCELERATION', 2:
// 'ADC_CMD_LONGITUDINALCONTROLMODE_RESERVED_FORCE', 3:
// 'ADC_CMD_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE'}, 'precision': 1.0,
// 'len': 2, 'name': 'ADC_CMD_LongitudinalControlMode', 'is_signed_var':
// False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 2, 'type': 'enum',
// 'order': 'intel', 'physical_unit': ''}
void set_p_adc_cmd_longitudinalcontrolmode(
uint8_t* data, Adc_motioncontrol1_10::Adc_cmd_longitudinalcontrolmodeType
adc_cmd_longitudinalcontrolmode);
private:
double adc_cmd_steerwheelangle_;
Adc_motioncontrol1_10::Adc_cmd_steeringcontrolmodeType
adc_cmd_steeringcontrolmode_;
bool adc_cmd_parkingbrake_;
Adc_motioncontrol1_10::Adc_cmd_gearType adc_cmd_gear_;
int adc_motioncontrol1_checksum_;
double adc_cmd_brakepercentage_;
double adc_cmd_throttleposition_;
int adc_motioncontrol1_counter_;
Adc_motioncontrol1_10::Adc_cmd_autonomyrequestType adc_cmd_autonomyrequest_;
Adc_motioncontrol1_10::Adc_cmd_longitudinalcontrolmodeType
adc_cmd_longitudinalcontrolmode_;
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_diag_fault_620_test.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_diag_fault_620.h"
#include "gtest/gtest.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
class Diag_fault_620_test : public ::testing::Test {
public:
virtual void SetUp() {}
protected:
Llcdiagfault620 diagfault_;
};
TEST_F(Diag_fault_620_test, General) {
const uint8_t bytes[8] = {0x8f, 0x9e, 0xad, 0xbc, 0xcb, 0xda, 0xe9, 0xf8};
const int32_t length_disengagecounter_brake = 8;
const int32_t length_disengagecounter_steer = 8;
const int32_t length_disengagecounter_throttle = 8;
const int32_t length_fbk_faultcounter = 8;
const int32_t length_disengagecounter_button = 8;
const int32_t length_fbk_version_year = 7;
const int32_t length_fbk_version_month = 4;
const int32_t length_fbk_version_day = 5;
const int32_t length_fbk_version_hour = 5;
const int equivalent_disengagecounter_brake = 0xcb;
const int equivalent_disengagecounter_steer = 0xad;
const int equivalent_disengagecounter_throttle = 0xbc;
const int equivalent_fbk_faultcounter = 0x8f;
const int equivalent_disengagecounter_button = 0x9e;
const int equivalent_fbk_version_year = 0x83b;
const int equivalent_fbk_version_month = 0x03;
const int equivalent_fbk_version_day = 0x1d;
const int equivalent_fbk_version_hour = 0x18;
EXPECT_EQ(diagfault_.llc_disengagecounter_brake(
bytes, length_disengagecounter_brake),
equivalent_disengagecounter_brake);
EXPECT_EQ(diagfault_.llc_disengagecounter_steer(
bytes, length_disengagecounter_steer),
equivalent_disengagecounter_steer);
EXPECT_EQ(diagfault_.llc_disengagecounter_throttle(
bytes, length_disengagecounter_throttle),
equivalent_disengagecounter_throttle);
EXPECT_EQ(diagfault_.llc_fbk_faultcounter(bytes, length_fbk_faultcounter),
equivalent_fbk_faultcounter);
EXPECT_EQ(diagfault_.llc_disengagecounter_button(
bytes, length_disengagecounter_button),
equivalent_disengagecounter_button);
EXPECT_EQ(diagfault_.llc_fbk_version_year(bytes, length_fbk_version_year),
equivalent_fbk_version_year);
EXPECT_EQ(diagfault_.llc_fbk_version_month(bytes, length_fbk_version_month),
equivalent_fbk_version_month);
EXPECT_EQ(diagfault_.llc_fbk_version_day(bytes, length_fbk_version_day),
equivalent_fbk_version_day);
EXPECT_EQ(diagfault_.llc_fbk_version_hour(bytes, length_fbk_version_hour),
equivalent_fbk_version_hour);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_diag_fault_620.h
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "gtest/gtest_prod.h"
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace transit {
class Llcdiagfault620 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Transit> {
public:
static const int32_t ID;
Llcdiagfault620();
void Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const override;
FRIEND_TEST(Diag_fault_620_test, General);
private:
// config detail: {'description': 'Counts the number of times that the driver
// has disengaged autonomy by applying the brakes since system reset..',
// 'offset': 0.0, 'precision': 1.0, 'len': 8, 'name':
// 'LLC_DisengageCounter_Brake', 'is_signed_var': False, 'physical_range':
// '[0|255]', 'bit': 32, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int llc_disengagecounter_brake(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Counts the number of times that the driver
// has disengaged autonomy by moving the steering wheel since system reset.',
// 'offset': 0.0, 'precision': 1.0, 'len': 8, 'name':
// 'LLC_DisengageCounter_Steer', 'is_signed_var': False, 'physical_range':
// '[0|255]', 'bit': 16, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int llc_disengagecounter_steer(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Counts the number of times that the driver
// has disengaged autonomy by applying throttle since system reset.',
// 'offset': 0.0, 'precision': 1.0, 'len': 8, 'name':
// 'LLC_DisengageCounter_Throttle', 'is_signed_var': False, 'physical_range':
// '[0|255]', 'bit': 24, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int llc_disengagecounter_throttle(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Counts the number of faults that have
// occurred since system reset.', 'offset': 0.0, 'precision': 1.0, 'len': 8,
// 'name': 'LLC_FBK_FaultCounter', 'is_signed_var': False, 'physical_range':
// '[0|255]', 'bit': 0, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int llc_fbk_faultcounter(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Counts the number of times that the driver
// has disengaged autonomy by applying the brakes since system reset..',
// 'offset': 0.0, 'precision': 1.0, 'len': 8, 'name':
// 'LLC_DisengageCounter_Button', 'is_signed_var': False, 'physical_range':
// '[0|255]', 'bit': 8, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int llc_disengagecounter_button(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Firmware version', 'offset': 2017.0,
// 'precision': 1.0, 'len': 7, 'name': 'LLC_FBK_Version_Year',
// 'is_signed_var': False, 'physical_range': '[2017|2144]', 'bit': 40, 'type':
// 'int', 'order': 'intel', 'physical_unit': 'g'}
int llc_fbk_version_year(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Firmware version', 'offset': 0.0,
// 'precision': 1.0, 'len': 4, 'name': 'LLC_FBK_Version_Month',
// 'is_signed_var': False, 'physical_range': '[0|15]', 'bit': 47, 'type':
// 'int', 'order': 'intel', 'physical_unit': 'Month'}
int llc_fbk_version_month(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Firmware version', 'offset': 0.0,
// 'precision': 1.0, 'len': 5, 'name': 'LLC_FBK_Version_Day', 'is_signed_var':
// False, 'physical_range': '[0|31]', 'bit': 51, 'type': 'int', 'order':
// 'intel', 'physical_unit': 'Day'}
int llc_fbk_version_day(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Firmware version', 'offset': 0.0,
// 'precision': 1.0, 'len': 5, 'name': 'LLC_FBK_Version_Hour',
// 'is_signed_var': False, 'physical_range': '[0|31]', 'bit': 56, 'type':
// 'int', 'order': 'intel', 'physical_unit': 'Hour'}
int llc_fbk_version_hour(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_vehiclestatus_25_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_vehiclestatus_25.h"
#include "gtest/gtest.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
class llc_vehiclestatus_25Test : public ::testing ::Test {
public:
virtual void SetUp() {}
protected:
Llcvehiclestatus25 Llcauxiliary_status25_;
};
TEST_F(llc_vehiclestatus_25Test, 12voltage) {
const std::uint8_t kBytes = 0xFF;
std::int32_t length = 8;
EXPECT_DOUBLE_EQ(Llcauxiliary_status25_.llc_fbk_12voltage(&kBytes, length),
25.5);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_auxiliaryfeedback_120.h
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "gtest/gtest_prod.h"
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace transit {
class Llcauxiliaryfeedback120 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Transit> {
public:
static const int32_t ID;
Llcauxiliaryfeedback120();
void Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const override;
FRIEND_TEST(llc_auxiliaryfeedback_120Test, General);
private:
// config detail: {'description': 'Inverter enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_Inverter', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 2, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_inverter(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 8 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch8', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 15, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch8(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 7 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch7', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 14, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch7(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 6 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch6', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 13, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch6(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 5 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch5', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 12, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch5(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 4 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch4', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 11, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch4(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 3 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch3', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 10, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch3(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 2 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch2', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 9, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch2(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'PDU Channel 1 enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_PDU_Ch1', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 8, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_pdu_ch1(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'Hazard lights enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_HazardLights',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 28, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_hazardlights(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Autonomy indicator green LED on', 'offset':
// 0.0, 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_LedGreenOn',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 17, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_ledgreenon(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Horn enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_Horn', 'is_signed_var': False,
// 'physical_range': '[0|1]', 'bit': 3, 'type': 'bool', 'order': 'intel',
// 'physical_unit': 'T/F'}
bool llc_fbk_horn(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'Buzzer enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_BuzzerOn', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 19, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_buzzeron(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'Current turn signal status', 'enum': {0:
// 'LLC_FBK_TURNSIGNAL_NONE', 1: 'LLC_FBK_TURNSIGNAL_LEFT', 2:
// 'LLC_FBK_TURNSIGNAL_RIGHT', 3: 'LLC_FBK_TURNSIGNAL_RESERVE'},
// 'precision': 1.0, 'len': 2, 'name': 'LLC_FBK_TurnSignal', 'is_signed_var':
// False, 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 24, 'type': 'enum',
// 'order': 'intel', 'physical_unit': ''}
Llc_auxiliaryfeedback_120::Llc_fbk_turnsignalType llc_fbk_turnsignal(
const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'Low beam enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_LowBeam', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 26, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_lowbeam(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'High beam enabled', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_HighBeam', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 27, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_highbeam(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'Autonomy indicator red LED on', 'offset':
// 0.0, 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_LedRedOn',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 18, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_ledredon(const std::uint8_t* bytes, const int32_t length) const;
// config detail: {'description': 'Autonomy button is pressed', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'LLC_FBK_AutonomyButtonPressed',
// 'is_signed_var': False, 'physical_range': '[0|1]', 'bit': 16, 'type':
// 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool llc_fbk_autonomybuttonpressed(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_motionfeedback1_20.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_motionfeedback1_20.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
Llcmotionfeedback120::Llcmotionfeedback120() {}
const int32_t Llcmotionfeedback120::ID = 0x20;
void Llcmotionfeedback120::Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const {
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_gear(
llc_fbk_gear(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_parkingbrake(
llc_fbk_parkingbrake(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_throttleposition(
llc_fbk_throttleposition(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_brakepercentrear(
llc_fbk_brakepercentrear(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_brakepercentfront(
llc_fbk_brakepercentfront(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_steeringcontrolmode(
llc_fbk_steeringcontrolmode(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_motionfeedback1_counter(
llc_motionfeedback1_counter(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_motionfeedback1_checksum(
llc_motionfeedback1_checksum(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_commandaligned(
llc_fbk_commandaligned(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_estoppressed(
llc_fbk_estoppressed(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_adcrequestautonomy(
llc_fbk_adcrequestautonomy(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_allowautonomy(
llc_fbk_allowautonomy(bytes, length));
chassis->mutable_llc_motionfeedback1_20()
->set_llc_fbk_longitudinalcontrolmode(
llc_fbk_longitudinalcontrolmode(bytes, length));
chassis->mutable_llc_motionfeedback1_20()->set_llc_fbk_state(
llc_fbk_state(bytes, length));
}
// config detail: {'description': 'Current gear', 'enum': {0:
// 'LLC_FBK_GEAR_P_PARK', 1: 'LLC_FBK_GEAR_D_DRIVE', 2:
// 'LLC_FBK_GEAR_N_NEUTRAL', 3: 'LLC_FBK_GEAR_R_REVERSE'}, 'precision': 1.0,
// 'len': 3, 'name': 'llc_fbk_gear', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|3]', 'bit': 50, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_gearType Llcmotionfeedback120::llc_fbk_gear(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(2, 3);
Llc_motionfeedback1_20::Llc_fbk_gearType ret =
static_cast<Llc_motionfeedback1_20::Llc_fbk_gearType>(x);
return ret;
}
// config detail: {'description': 'Parking brake applied', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_parkingbrake', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 53, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcmotionfeedback120::llc_fbk_parkingbrake(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(5, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Throttle position feedback', 'offset': 0.0,
// 'precision': 0.1, 'len': 10, 'name': 'llc_fbk_throttleposition',
// 'is_signed_var': False, 'physical_range': '[0|102.3]', 'bit': 38, 'type':
// 'double', 'order': 'intel', 'physical_unit': '%'}
double Llcmotionfeedback120::llc_fbk_throttleposition(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 4);
int32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
double ret = x * 0.100000;
return ret;
}
// config detail: {'description': 'Rear brake pressure feedback', 'offset': 0.0,
// 'precision': 0.0556, 'len': 11, 'name': 'llc_fbk_brakepercentrear',
// 'is_signed_var': False, 'physical_range': '[0|113.8132]', 'bit': 27, 'type':
// 'double', 'order': 'intel', 'physical_unit': '%'}
double Llcmotionfeedback120::llc_fbk_brakepercentrear(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 6);
Byte t1(bytes + 3);
int32_t t = t1.get_byte(3, 5);
x <<= 5;
x |= t;
double ret = x * 0.055600;
return ret;
}
// config detail: {'description': 'Front brake pressure feedback', 'offset':
// 0.0, 'precision': 0.0556, 'len': 11, 'name': 'llc_fbk_brakepercentfront',
// 'is_signed_var': False, 'physical_range': '[0|113.8132]', 'bit': 16, 'type':
// 'double', 'order': 'intel', 'physical_unit': '%'}
double Llcmotionfeedback120::llc_fbk_brakepercentfront(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 3);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
double ret = x * 0.055600;
return ret;
}
// config detail: {'description': 'Current steering control mode', 'enum': {0:
// 'LLC_FBK_STEERINGCONTROLMODE_NONE', 1: 'LLC_FBK_STEERINGCONTROLMODE_ANGLE',
// 2: 'LLC_FBK_STEERINGCONTROLMODE_RESERVED_CURVATURE', 3:
// 'LLC_FBK_STEERINGCONTROLMODE_RESERVED'}, 'precision': 1.0, 'len': 2, 'name':
// 'llc_fbk_steeringcontrolmode', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|3]', 'bit': 6, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_steeringcontrolmodeType
Llcmotionfeedback120::llc_fbk_steeringcontrolmode(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(6, 2);
Llc_motionfeedback1_20::Llc_fbk_steeringcontrolmodeType ret =
static_cast<Llc_motionfeedback1_20::Llc_fbk_steeringcontrolmodeType>(x);
return ret;
}
// config detail: {'description': 'Motion feedback 1 heartbeat counter',
// 'offset': 0.0, 'precision': 1.0, 'len': 2, 'name':
// 'llc_motionfeedback1_counter', 'is_signed_var': False, 'physical_range':
// '[0|3]', 'bit': 54, 'type': 'int', 'order': 'intel', 'physical_unit': ''}
int Llcmotionfeedback120::llc_motionfeedback1_counter(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(6, 2);
int ret = x;
return ret;
}
// config detail: {'description': 'Motion feedback 1 checksum', 'offset': 0.0,
// 'precision': 1.0, 'len': 8, 'name': 'llc_motionfeedback1_checksum',
// 'is_signed_var': False, 'physical_range': '[0|255]', 'bit': 56, 'type':
// 'int', 'order': 'intel', 'physical_unit': ''}
int Llcmotionfeedback120::llc_motionfeedback1_checksum(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
// config detail: {'description': 'Autonomy command aligned with vehicle state
// according to calibration limits', 'offset': 0.0, 'precision': 1.0, 'len': 1,
// 'name': 'llc_fbk_commandaligned', 'is_signed_var': False, 'physical_range':
// '[0|1]', 'bit': 11, 'type': 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool Llcmotionfeedback120::llc_fbk_commandaligned(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(3, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Estop is pressed', 'offset': 0.0,
// 'precision': 1.0, 'len': 1, 'name': 'llc_fbk_estoppressed', 'is_signed_var':
// False, 'physical_range': '[0|1]', 'bit': 10, 'type': 'bool', 'order':
// 'intel', 'physical_unit': 'T/F'}
bool Llcmotionfeedback120::llc_fbk_estoppressed(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(2, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Indicates that ADC is requesting autonomy
// mode', 'offset': 0.0, 'precision': 1.0, 'len': 1, 'name':
// 'llc_fbk_adcrequestautonomy', 'is_signed_var': False, 'physical_range':
// '[0|1]', 'bit': 9, 'type': 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool Llcmotionfeedback120::llc_fbk_adcrequestautonomy(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(1, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Indicates that LLC is ready to allow autonomy
// mode', 'offset': 0.0, 'precision': 1.0, 'len': 1, 'name':
// 'llc_fbk_allowautonomy', 'is_signed_var': False, 'physical_range': '[0|1]',
// 'bit': 8, 'type': 'bool', 'order': 'intel', 'physical_unit': 'T/F'}
bool Llcmotionfeedback120::llc_fbk_allowautonomy(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 1);
bool ret = x;
return ret;
}
// config detail: {'description': 'Report current longitudinal control mode',
// 'enum': {0: 'LLC_FBK_LONGITUDINALCONTROLMODE_NONE', 1:
// 'LLC_FBK_LONGITUDINALCONTROLMODE_RESERVED_VELOCITY_AND_ACCELERATION', 2:
// 'LLC_FBK_LONGITUDINALCONTROLMODE_RESERVED_FORCE', 3:
// 'LLC_FBK_LONGITUDINALCONTROLMODE_DIRECT_THROTTLE_BRAKE'}, 'precision': 1.0,
// 'len': 2, 'name': 'llc_fbk_longitudinalcontrolmode', 'is_signed_var': False,
// 'offset': 0.0, 'physical_range': '[0|3]', 'bit': 4, 'type': 'enum', 'order':
// 'intel', 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_longitudinalcontrolmodeType
Llcmotionfeedback120::llc_fbk_longitudinalcontrolmode(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(4, 2);
Llc_motionfeedback1_20::Llc_fbk_longitudinalcontrolmodeType ret =
static_cast<Llc_motionfeedback1_20::Llc_fbk_longitudinalcontrolmodeType>(
x);
return ret;
}
// config detail: {'description': 'Current Autonomy State', 'enum': {0:
// 'LLC_FBK_STATE_RESERVED0', 1: 'LLC_FBK_STATE_AUTONOMY_NOT_ALLOWED', 2:
// 'LLC_FBK_STATE_AUTONOMY_ALLOWED', 3: 'LLC_FBK_STATE_AUTONOMY_REQUESTED', 4:
// 'LLC_FBK_STATE_AUTONOMY', 5: 'LLC_FBK_STATE_RESERVED1', 6:
// 'LLC_FBK_STATE_RESERVED2', 7: 'LLC_FBK_STATE_RESERVED3', 8:
// 'LLC_FBK_STATE_RESERVED4', 9: 'LLC_FBK_STATE_RESERVED5', 10:
// 'LLC_FBK_STATE_RESERVED6', 11: 'LLC_FBK_STATE_RESERVED7', 12:
// 'LLC_FBK_STATE_RESERVED8', 13: 'LLC_FBK_STATE_DISENGAGE_REQUESTED', 14:
// 'LLC_FBK_STATE_DISENGAGED', 15: 'LLC_FBK_STATE_FAULT'}, 'precision': 1.0,
// 'len': 4, 'name': 'llc_fbk_state', 'is_signed_var': False, 'offset': 0.0,
// 'physical_range': '[0|15]', 'bit': 0, 'type': 'enum', 'order': 'intel',
// 'physical_unit': ''}
Llc_motionfeedback1_20::Llc_fbk_stateType Llcmotionfeedback120::llc_fbk_state(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 4);
Llc_motionfeedback1_20::Llc_fbk_stateType ret =
static_cast<Llc_motionfeedback1_20::Llc_fbk_stateType>(x);
return ret;
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_motionfeedback2_21_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_motionfeedback2_21.h"
#include "gtest/gtest.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
class llc_motionfeedback2_21Test : public ::testing ::Test {
public:
virtual void SetUp() {}
protected:
Llcmotionfeedback221 motionfdk2_21_;
};
TEST_F(llc_motionfeedback2_21Test, motion_fdk) {
const uint8_t kData[8] = {0x9A, 0xFC, 0x56, 0xF7, 0x12, 0x34, 0xFF, 0xFF};
int32_t speed_len = 8;
int32_t counter_len = 2;
int32_t checksum_len = 8;
int32_t steeringrate_len = 8;
int32_t steeringangle_len = 8;
EXPECT_DOUBLE_EQ(motionfdk2_21_.llc_fbk_vehiclespeed(kData, speed_len),
133.3);
EXPECT_EQ(motionfdk2_21_.llc_motionfeedback2_counter(kData, counter_len), 3);
EXPECT_EQ(motionfdk2_21_.llc_motionfeedback2_checksum(kData, checksum_len),
0xFF);
EXPECT_DOUBLE_EQ(motionfdk2_21_.llc_fbk_steeringrate(kData, steeringrate_len),
-110.9);
EXPECT_DOUBLE_EQ(
motionfdk2_21_.llc_fbk_steeringangle(kData, steeringangle_len), -43.5);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_diag_steeringcontrol_722.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_diag_steeringcontrol_722.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
const int32_t Llcdiagsteeringcontrol722::ID = 0x722;
// public
Llcdiagsteeringcontrol722::Llcdiagsteeringcontrol722() { Reset(); }
uint32_t Llcdiagsteeringcontrol722::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 10 * 1000;
return PERIOD;
}
void Llcdiagsteeringcontrol722::UpdateData(uint8_t* data) {
set_p_llc_dbg_steeringsensorposition(data, llc_dbg_steeringsensorposition_);
set_p_llc_dbg_steeringrackinputtorque(data, llc_dbg_steeringrackinputtorque_);
set_p_llc_dbg_steeringmotorposition(data, llc_dbg_steeringmotorposition_);
}
void Llcdiagsteeringcontrol722::Reset() {
// TODO(All) : you should check this manually
llc_dbg_steeringsensorposition_ = 0.0;
llc_dbg_steeringrackinputtorque_ = 0;
llc_dbg_steeringmotorposition_ = 0.0;
}
Llcdiagsteeringcontrol722*
Llcdiagsteeringcontrol722::set_llc_dbg_steeringsensorposition(
double llc_dbg_steeringsensorposition) {
llc_dbg_steeringsensorposition_ = llc_dbg_steeringsensorposition;
return this;
}
// config detail: {'description': 'Brake control feedforward contribution',
// 'offset': 0.0, 'precision': 0.0002, 'len': 16, 'name':
// 'LLC_DBG_SteeringSensorPosition', 'is_signed_var': True, 'physical_range':
// '[-6.5536|6.5534]', 'bit': 40, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'rev'}
void Llcdiagsteeringcontrol722::set_p_llc_dbg_steeringsensorposition(
uint8_t* data, double llc_dbg_steeringsensorposition) {
llc_dbg_steeringsensorposition = ProtocolData::BoundedValue(
-6.5536, 6.5534, llc_dbg_steeringsensorposition);
int x = static_cast<int>(llc_dbg_steeringsensorposition / 0.000200);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set0(data + 5);
to_set0.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set1(data + 6);
to_set1.set_value(t, 0, 8);
}
Llcdiagsteeringcontrol722*
Llcdiagsteeringcontrol722::set_llc_dbg_steeringrackinputtorque(
int llc_dbg_steeringrackinputtorque) {
llc_dbg_steeringrackinputtorque_ = llc_dbg_steeringrackinputtorque;
return this;
}
// config detail: {'description': 'Brake control feedforward contribution',
// 'offset': 0.0, 'precision': 1.0, 'len': 16, 'name':
// 'LLC_DBG_SteeringRackInputTorque', 'is_signed_var': True, 'physical_range':
// '[-32768|32767]', 'bit': 24, 'type': 'int', 'order': 'intel',
// 'physical_unit': 'counts'}
void Llcdiagsteeringcontrol722::set_p_llc_dbg_steeringrackinputtorque(
uint8_t* data, int llc_dbg_steeringrackinputtorque) {
llc_dbg_steeringrackinputtorque = ProtocolData::BoundedValue(
-32768, 32767, llc_dbg_steeringrackinputtorque);
int x = llc_dbg_steeringrackinputtorque;
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set0(data + 3);
to_set0.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set1(data + 4);
to_set1.set_value(t, 0, 8);
}
Llcdiagsteeringcontrol722*
Llcdiagsteeringcontrol722::set_llc_dbg_steeringmotorposition(
double llc_dbg_steeringmotorposition) {
llc_dbg_steeringmotorposition_ = llc_dbg_steeringmotorposition;
return this;
}
// config detail: {'description': 'Brake control feedforward contribution',
// 'offset': 0.0, 'precision': 1e-05, 'len': 24, 'name':
// 'LLC_DBG_SteeringMotorPosition', 'is_signed_var': True, 'physical_range':
// '[-83.88608|83.88607]', 'bit': 0, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'rev'}
void Llcdiagsteeringcontrol722::set_p_llc_dbg_steeringmotorposition(
uint8_t* data, double llc_dbg_steeringmotorposition) {
llc_dbg_steeringmotorposition = ProtocolData::BoundedValue(
-83.88608, 83.88607, llc_dbg_steeringmotorposition);
int x = static_cast<int>(llc_dbg_steeringmotorposition / 0.000010);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set0(data + 0);
to_set0.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set1(data + 1);
to_set1.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set2(data + 2);
to_set2.set_value(t, 0, 8);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_vehiclestatus_25.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_vehiclestatus_25.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
Llcvehiclestatus25::Llcvehiclestatus25() {}
const int32_t Llcvehiclestatus25::ID = 0x25;
void Llcvehiclestatus25::Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const {
chassis->mutable_llc_vehiclestatus_25()->set_llc_fbk_12voltage(
llc_fbk_12voltage(bytes, length));
}
// config detail: {'description': 'Vehicle 12V voltage feedback', 'offset': 0.0,
// 'precision': 0.1, 'len': 8, 'name': 'llc_fbk_12voltage', 'is_signed_var':
// False, 'physical_range': '[0|25.5]', 'bit': 0, 'type': 'double', 'order':
// 'intel', 'physical_unit': 'Volt'}
double Llcvehiclestatus25::llc_fbk_12voltage(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 0);
int32_t x = t0.get_byte(0, 8);
double ret = x * 0.100000;
return ret;
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/adc_motioncontrollimits1_12.cc
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/adc_motioncontrollimits1_12.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
const int32_t Adcmotioncontrollimits112::ID = 0x12;
// public
Adcmotioncontrollimits112::Adcmotioncontrollimits112() { Reset(); }
uint32_t Adcmotioncontrollimits112::GetPeriod() const {
// TODO(All) : modify every protocol's period manually
static const uint32_t PERIOD = 10 * 1000;
return PERIOD;
}
void Adcmotioncontrollimits112::UpdateData(uint8_t* data) {
set_p_adc_cmd_throttlecommandlimit(data, adc_cmd_throttlecommandlimit_);
set_p_adc_cmd_steeringrate(data, adc_cmd_steeringrate_);
set_p_adc_cmd_steerwheelanglelimit(data, adc_cmd_steerwheelanglelimit_);
}
void Adcmotioncontrollimits112::Reset() {
// TODO(All) : you should check this manually
adc_cmd_throttlecommandlimit_ = 0.0;
adc_cmd_steeringrate_ = 0.0;
adc_cmd_steerwheelanglelimit_ = 0.0;
}
Adcmotioncontrollimits112*
Adcmotioncontrollimits112::set_adc_cmd_throttlecommandlimit(
double adc_cmd_throttlecommandlimit) {
adc_cmd_throttlecommandlimit_ = adc_cmd_throttlecommandlimit;
return this;
}
// config detail: {'description': 'Set limit for throttle position', 'offset':
// 0.0, 'precision': 0.5, 'len': 8, 'name': 'ADC_CMD_ThrottleCommandLimit',
// 'is_signed_var': False, 'physical_range': '[0|100]', 'bit': 24, 'type':
// 'double', 'order': 'intel', 'physical_unit': '%'}
void Adcmotioncontrollimits112::set_p_adc_cmd_throttlecommandlimit(
uint8_t* data, double adc_cmd_throttlecommandlimit) {
adc_cmd_throttlecommandlimit =
ProtocolData::BoundedValue(0.0, 100.0, adc_cmd_throttlecommandlimit);
int x = static_cast<int>(adc_cmd_throttlecommandlimit / 0.500000);
Byte to_set(data + 3);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
Adcmotioncontrollimits112* Adcmotioncontrollimits112::set_adc_cmd_steeringrate(
double adc_cmd_steeringrate) {
adc_cmd_steeringrate_ = adc_cmd_steeringrate;
return this;
}
// config detail: {'description': 'Set steering rate', 'offset': 0.0,
// 'precision': 0.05, 'len': 16, 'name': 'ADC_CMD_SteeringRate',
// 'is_signed_var': False, 'physical_range': '[0|3276.75]', 'bit': 0, 'type':
// 'double', 'order': 'intel', 'physical_unit': 'deg/s'}
void Adcmotioncontrollimits112::set_p_adc_cmd_steeringrate(
uint8_t* data, double adc_cmd_steeringrate) {
adc_cmd_steeringrate =
ProtocolData::BoundedValue(0.0, 3276.75, adc_cmd_steeringrate);
int x = static_cast<int>(adc_cmd_steeringrate / 0.050000);
uint8_t t = 0;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set0(data + 0);
to_set0.set_value(t, 0, 8);
x >>= 8;
t = static_cast<uint8_t>(x & 0xFF);
Byte to_set1(data + 1);
to_set1.set_value(t, 0, 8);
}
Adcmotioncontrollimits112*
Adcmotioncontrollimits112::set_adc_cmd_steerwheelanglelimit(
double adc_cmd_steerwheelanglelimit) {
adc_cmd_steerwheelanglelimit_ = adc_cmd_steerwheelanglelimit;
return this;
}
// config detail: {'description': 'Set limit for steering wheel angle. Applies
// in both positive and negative', 'offset': 0.0, 'precision': 5.0, 'len': 8,
// 'name': 'ADC_CMD_SteerWheelAngleLimit', 'is_signed_var': False,
// 'physical_range': '[0|1275]', 'bit': 16, 'type': 'double', 'order': 'intel',
// 'physical_unit': 'deg'}
void Adcmotioncontrollimits112::set_p_adc_cmd_steerwheelanglelimit(
uint8_t* data, double adc_cmd_steerwheelanglelimit) {
adc_cmd_steerwheelanglelimit =
ProtocolData::BoundedValue(0.0, 1275.0, adc_cmd_steerwheelanglelimit);
int x = static_cast<int>(adc_cmd_steerwheelanglelimit / 5.000000);
Byte to_set(data + 2);
to_set.set_value(static_cast<uint8_t>(x), 0, 8);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_diag_brakecontrol_721_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/llc_diag_brakecontrol_721.h"
#include "gtest/gtest.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
class llc_diag_brakecontrol_721Test : public ::testing ::Test {
public:
virtual void SetUp() {}
};
TEST_F(llc_diag_brakecontrol_721Test, part1) {
Llcdiagbrakecontrol721 brakectrl_721_;
uint8_t data[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
double x = 0.0;
brakectrl_721_.set_p_llc_dbg_brakepidcontribution_p(data, x);
brakectrl_721_.set_p_llc_dbg_brakepidcontribution_d(data, x);
brakectrl_721_.set_p_llc_dbg_brakepid_output(data, x);
EXPECT_EQ(data[1], 0xF);
EXPECT_EQ(data[2], 0xC0);
EXPECT_EQ(data[4], 0x3);
EXPECT_EQ(data[5], 0xF0);
EXPECT_EQ(data[6], 0x3F);
EXPECT_EQ(data[7], 0x0);
}
TEST_F(llc_diag_brakecontrol_721Test, part2) {
Llcdiagbrakecontrol721 brakectrl_721_;
uint8_t data[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
double x = 0.0;
int a = 0;
brakectrl_721_.set_p_llc_dbg_brakepidcontribution_i(data, x);
brakectrl_721_.set_p_llc_dbg_brakepid_error(data, a);
brakectrl_721_.set_p_llc_dbg_brakefeedforward(data, x);
EXPECT_EQ(data[0], 0x0);
EXPECT_EQ(data[1], 0xF0);
EXPECT_EQ(data[2], 0x3F);
EXPECT_EQ(data[3], 0x0);
EXPECT_EQ(data[4], 0xFC);
EXPECT_EQ(data[5], 0xF);
EXPECT_EQ(data[6], 0xC0);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/llc_vehiclelimits_24.h
|
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include "gtest/gtest_prod.h"
#include "modules/canbus_vehicle/transit/proto/transit.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
namespace apollo {
namespace canbus {
namespace transit {
class Llcvehiclelimits24 : public ::apollo::drivers::canbus::ProtocolData<
::apollo::canbus::Transit> {
public:
static const int32_t ID;
Llcvehiclelimits24();
void Parse(const std::uint8_t* bytes, int32_t length,
Transit* chassis) const override;
FRIEND_TEST(Vehiclelimits_24_test, General);
private:
// config detail: {'description': 'Steering angle feedback', 'offset': 0.0,
// 'precision': 1.0, 'len': 12, 'name': 'LLC_FBK_MaxSteeringAngle',
// 'is_signed_var': False, 'physical_range': '[0|4095]', 'bit': 12, 'type':
// 'int', 'order': 'intel', 'physical_unit': 'deg'}
int llc_fbk_maxsteeringangle(const std::uint8_t* bytes,
const int32_t length) const;
// config detail: {'description': 'Front brake pressure feedback', 'offset':
// 0.0, 'precision': 1.0, 'len': 12, 'name': 'LLC_FBK_MaxBrakePercent',
// 'is_signed_var': False, 'physical_range': '[0|113.8132]', 'bit': 0, 'type':
// 'double', 'order': 'intel', 'physical_unit': '%'}
double llc_fbk_maxbrakepercent(const std::uint8_t* bytes,
const int32_t length) const;
};
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit
|
apollo_public_repos/apollo/modules/canbus_vehicle/transit/protocol/adc_motioncontrol1_10_test.cc
|
/******************************************************************************
* Copyright 2019 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/canbus_vehicle/transit/protocol/adc_motioncontrol1_10.h"
#include "gtest/gtest.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace canbus {
namespace transit {
using ::apollo::drivers::canbus::Byte;
class adc_motioncontrol1_10Test : public ::testing ::Test {
public:
virtual void SetUp() {}
};
TEST_F(adc_motioncontrol1_10Test, part1) {
Adcmotioncontrol110 motion_ctrl_110_;
uint8_t data[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
double x = 0.0;
int i = 0;
motion_ctrl_110_.set_p_adc_cmd_steerwheelangle(data, x);
motion_ctrl_110_.set_p_adc_cmd_gear(data, motion_ctrl_110_.adc_cmd_gear_);
motion_ctrl_110_.set_p_adc_motioncontrol1_checksum(data, i);
motion_ctrl_110_.set_p_adc_cmd_brakepercentage(data, x);
EXPECT_EQ(data[0], 0x3F);
EXPECT_EQ(data[1], 0x0);
EXPECT_EQ(data[2], 0xFE);
EXPECT_EQ(data[3], 0x7);
EXPECT_EQ(data[4], 0x0);
EXPECT_EQ(data[5], 0xF8);
EXPECT_EQ(data[6], 0xE3);
EXPECT_EQ(data[7], 0x0);
}
TEST_F(adc_motioncontrol1_10Test, part2) {
Adcmotioncontrol110 motion_ctrl_110_;
uint8_t data[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
double x = 0.0;
bool flag = false;
motion_ctrl_110_.set_p_adc_cmd_steeringcontrolmode(
data, motion_ctrl_110_.adc_cmd_steeringcontrolmode_);
motion_ctrl_110_.set_p_adc_cmd_parkingbrake(data, flag);
motion_ctrl_110_.set_p_adc_cmd_throttleposition(data, x);
EXPECT_EQ(data[0], 0xCF);
EXPECT_EQ(data[1], 0xFF);
EXPECT_EQ(data[2], 0x01);
EXPECT_EQ(data[3], 0xF8);
EXPECT_EQ(data[4], 0xFF);
EXPECT_EQ(data[5], 0xFF);
EXPECT_EQ(data[6], 0xDF);
EXPECT_EQ(data[7], 0xFF);
}
TEST_F(adc_motioncontrol1_10Test, part3) {
Adcmotioncontrol110 motion_ctrl_110_;
uint8_t data[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
int i = 0;
motion_ctrl_110_.set_p_adc_motioncontrol1_counter(data, i);
motion_ctrl_110_.set_p_adc_cmd_autonomyrequest(
data, motion_ctrl_110_.adc_cmd_autonomyrequest_);
EXPECT_EQ(data[0], 0xFC);
EXPECT_EQ(data[1], 0xFF);
EXPECT_EQ(data[2], 0xFF);
EXPECT_EQ(data[3], 0xFF);
EXPECT_EQ(data[4], 0xFF);
EXPECT_EQ(data[5], 0xFF);
EXPECT_EQ(data[6], 0x3F);
EXPECT_EQ(data[7], 0xFF);
}
TEST_F(adc_motioncontrol1_10Test, part4) {
Adcmotioncontrol110 motion_ctrl_110_;
uint8_t data = 0xFF;
motion_ctrl_110_.set_p_adc_cmd_longitudinalcontrolmode(
&data, motion_ctrl_110_.adc_cmd_longitudinalcontrolmode_);
EXPECT_EQ(data, 0xF3);
}
} // namespace transit
} // namespace canbus
} // namespace apollo
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.