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/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/common/byte.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
* @brief Defines the Byte class.
*/
#pragma once
#include <string>
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
/**
* @class Byte
* @brief The class of one byte, which is 8 bits.
* It includes some operations on one byte.
*/
class Byte {
public:
/**
* @brief Constructor which takes a pointer to a one-byte unsigned integer.
* @param value The pointer to a one-byte unsigned integer for construction.
*/
explicit Byte(const uint8_t *value);
/**
* @brief Constructor which takes a reference to a one-byte unsigned integer.
* @param value The reference to a one-byte unsigned integer for construction.
*/
Byte(const Byte &value);
/**
* @brief Desctructor.
*/
~Byte() = default;
/**
* @brief Transform an integer with the size of one byte to its hexadecimal
* represented by a string.
* @param value The target integer to transform.
* @return Hexadecimal representing the target integer.
*/
static std::string byte_to_hex(const uint8_t value);
/**
* @brief Transform an integer with the size of 4 bytes to its hexadecimal
* represented by a string.
* @param value The target integer to transform.
* @return Hexadecimal representing the target integer.
*/
static std::string byte_to_hex(const uint32_t value);
/**
* @brief Transform an integer with the size of one byte to its binary
* represented by a string.
* @param value The target integer to transform.
* @return Binary representing the target integer.
*/
static std::string byte_to_binary(const uint8_t value);
/**
* @brief Set the bit on a specified position to one.
* @param pos The position of the bit to be set to one.
*/
void set_bit_1(const int32_t pos);
/**
* @brief Set the bit on a specified position to zero.
* @param pos The position of the bit to be set to zero.
*/
void set_bit_0(const int32_t pos);
/**
* @brief Check if the bit on a specified position is one.
* @param pos The position of the bit to check.
* @return If the bit on a specified position is one.
*/
bool is_bit_1(const int32_t pos) const;
/**
* @brief Reset this Byte by a specified one-byte unsigned integer.
* @param value The one-byte unsigned integer to set this Byte.
*/
void set_value(const uint8_t value);
/**
* @brief Reset the higher 4 bits as the higher 4 bits of a specified one-byte
* unsigned integer.
* @param value The one-byte unsigned integer whose higher 4 bits are used to
* set this Byte's higher 4 bits.
*/
void set_value_high_4_bits(const uint8_t value);
/**
* @brief Reset the lower 4 bits as the lower 4 bits of a specified one-byte
* unsigned integer.
* @param value The one-byte unsigned integer whose lower 4 bits are used to
* set this Byte's lower 4 bits.
*/
void set_value_low_4_bits(const uint8_t value);
/**
* @brief Reset some consecutive bits starting from a specified position with
* a certain length of another one-byte unsigned integer.
* @param value The one-byte unsigned integer whose certain bits are used
* to set this Byte.
* @param start_pos The starting position (from the lowest) of the bits.
* @param length The length of the consecutive bits.
*/
void set_value(const uint8_t value, const int32_t start_pos,
const int32_t length);
/**
* @brief Get the one-byte unsigned integer.
* @return The one-byte unsigned integer.
*/
uint8_t get_byte() const;
/**
* @brief Get a one-byte unsigned integer representing the higher 4 bits.
* @return The one-byte unsigned integer representing the higher 4 bits.
*/
uint8_t get_byte_high_4_bits() const;
/**
* @brief Get a one-byte unsigned integer representing the lower 4 bits.
* @return The one-byte unsigned integer representing the lower 4 bits.
*/
uint8_t get_byte_low_4_bits() const;
/**
* @brief Get a one-byte unsigned integer representing the consecutive bits
* from a specified position (from lowest) by a certain length.
* @param start_pos The starting position (from lowest) of bits.
* @param length The length of the selected consecutive bits.
* @return The one-byte unsigned integer representing the selected bits.
*/
uint8_t get_byte(const int32_t start_pos, const int32_t length) const;
/**
* @brief Transform to its hexadecimal represented by a string.
* @return Hexadecimal representing the Byte.
*/
std::string to_hex_string() const;
/**
* @brief Transform to its binary represented by a string.
* @return Binary representing the Byte.
*/
std::string to_binary_string() const;
private:
uint8_t *value_;
};
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/can_client_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
* @brief Defines the CanClientFactory class.
*/
#pragma once
#include <memory>
#include <unordered_map>
#include "cyber/common/macros.h"
#include "modules/common/util/factory.h"
#include "modules/drivers/canbus/can_client/can_client.h"
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
/**
* @class CanClientFactory
* @brief CanClientFactory inherites apollo::common::util::Factory.
*/
class CanClientFactory
: public apollo::common::util::Factory<CANCardParameter::CANCardBrand,
CanClient> {
public:
/**
* @brief Register the CAN clients of all brands. This function call the
* Function apollo::common::util::Factory::Register() for all of the
* CAN clients.
*/
void RegisterCanClients();
/**
* @brief Create a pointer to a specified brand of CAN client. The brand is
* set in the parameter.
* @param parameter The parameter to create the CAN client.
* @return A pointer to the created CAN client.
*/
std::unique_ptr<CanClient> CreateCANClient(const CANCardParameter ¶meter);
private:
DECLARE_SINGLETON(CanClientFactory)
};
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/can_client_factory_test.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/drivers/canbus/can_client/can_client_factory.h"
#include "gtest/gtest.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
namespace apollo {
namespace drivers {
namespace canbus {
TEST(CanClientFactoryTest, CreateCanClient) {
auto can_factory = CanClientFactory::Instance();
EXPECT_NE(can_factory, nullptr);
can_factory->RegisterCanClients();
#if USE_ESD_CAN
CANCardParameter can_card_parameter;
can_card_parameter.set_brand(CANCardParameter::ESD_CAN);
can_card_parameter.set_type(CANCardParameter::PCI_CARD);
can_card_parameter.set_channel_id(CANCardParameter::CHANNEL_ID_ZERO);
EXPECT_NE(can_factory->CreateCANClient(can_card_parameter), nullptr);
#endif
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//tools:cpplint.bzl", "cpplint")
load("//tools/platform:build_defs.bzl", "copts_if_esd_can", "if_esd_can")
load("//tools/install:install.bzl", "install")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
runtime_dest = "drivers/bin",
targets = [
":can_client_tool",
],
)
cc_library(
name = "can_client_factory",
srcs = ["can_client_factory.cc"],
hdrs = ["can_client_factory.h"],
alwayslink = True,
copts = copts_if_esd_can(),
deps = [
"//cyber",
"//modules/common/util:util_tool",
"//modules/drivers/canbus/can_client",
"//modules/drivers/canbus/can_client/fake:fake_can_client",
"//modules/drivers/canbus/can_client/hermes_can:hermes_can_client",
"//modules/drivers/canbus/can_client/socket:socket_can_client_raw",
"//modules/drivers/canbus/common:canbus_common",
"//modules/common_msgs/drivers_msgs:can_card_parameter_cc_proto",
] + if_esd_can([
"//modules/drivers/canbus/can_client/esd:esd_can_client",
]),
)
cc_library(
name = "can_client",
hdrs = ["can_client.h"],
alwayslink = True,
deps = [
"//modules/common/util",
"//modules/drivers/canbus/common:canbus_common",
"//modules/common_msgs/drivers_msgs:can_card_parameter_cc_proto",
],
)
cc_binary(
name = "can_client_tool",
srcs = ["can_client_tool.cc"],
deps = [
"//cyber",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/common_msgs/drivers_msgs:can_card_parameter_cc_proto",
"@com_github_gflags_gflags//:gflags",
],
)
cc_test(
name = "can_client_factory_test",
size = "small",
srcs = ["can_client_factory_test.cc"],
deps = [
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/common_msgs/drivers_msgs:can_card_parameter_cc_proto",
"@com_google_googletest//:gtest_main",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/can_client.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
* @brief Defines the CanFrame struct and CanClient interface.
*/
#pragma once
#include <cstdint>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
#include "cyber/common/log.h"
#include "modules/drivers/canbus/common/byte.h"
/**
* @namespace apollo::drivers::canbus
* @brief apollo::drivers::canbus
*/
namespace apollo {
namespace drivers {
namespace canbus {
/**
* @class CanFrame
* @brief The class which defines the information to send and receive.
*/
struct CanFrame {
/// Message id
uint32_t id;
/// Message length
uint8_t len;
/// Message content
uint8_t data[8];
/// Time stamp
struct timeval timestamp;
/**
* @brief Constructor
*/
CanFrame() : id(0), len(0), timestamp{0} {
std::memset(data, 0, sizeof(data));
}
/**
* @brief CanFrame string including essential information about the message.
* @return The info string.
*/
std::string CanFrameString() const {
std::stringstream output_stream("");
output_stream << "id:0x" << Byte::byte_to_hex(id)
<< ",len:" << static_cast<int>(len) << ",data:";
for (uint8_t i = 0; i < len; ++i) {
output_stream << Byte::byte_to_hex(data[i]);
}
output_stream << ",";
return output_stream.str();
}
};
const int CAN_RESULT_SUCC = 0;
const int CAN_ERROR_BASE = 2000;
const int CAN_ERROR_OPEN_DEVICE_FAILED = CAN_ERROR_BASE + 1;
const int CAN_ERROR_FRAME_NUM = CAN_ERROR_BASE + 2;
const int CAN_ERROR_SEND_FAILED = CAN_ERROR_BASE + 3;
const int CAN_ERROR_RECV_FAILED = CAN_ERROR_BASE + 4;
/**
* @class CanClient
* @brief The class which defines the CAN client to send and receive message.
*/
class CanClient {
public:
/**
* @brief Constructor
*/
CanClient() = default;
/**
* @brief Destructor
*/
virtual ~CanClient() = default;
/**
* @brief Initialize the CAN client by specified CAN card parameters.
* @param parameter CAN card parameters to initialize the CAN client.
* @return If the initialization is successful.
*/
virtual bool Init(const CANCardParameter ¶meter) = 0;
/**
* @brief Start the CAN client.
* @return The status of the start action which is defined by
* apollo::common::ErrorCode.
*/
virtual apollo::common::ErrorCode Start() = 0;
/**
* @brief Stop the CAN client.
*/
virtual void Stop() = 0;
/**
* @brief Send messages
* @param frames The messages to send.
* @param frame_num The amount of messages to send.
* @return The status of the sending action which is defined by
* apollo::common::ErrorCode.
*/
virtual apollo::common::ErrorCode Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num) = 0;
/**
* @brief Send a single message.
* @param frames A single-element vector containing only one message.
* @return The status of the sending single message action which is defined by
* apollo::common::ErrorCode.
*/
virtual apollo::common::ErrorCode SendSingleFrame(
const std::vector<CanFrame> &frames) {
CHECK_EQ(frames.size(), 1U)
<< "frames size not equal to 1, actual frame size :" << frames.size();
int32_t n = 1;
return Send(frames, &n);
}
/**
* @brief Receive messages
* @param frames The messages to receive.
* @param frame_num The amount of messages to receive.
* @return The status of the receiving action which is defined by
* apollo::common::ErrorCode.
*/
virtual apollo::common::ErrorCode Receive(std::vector<CanFrame> *const frames,
int32_t *const frame_num) = 0;
/**
* @brief Get the error string.
* @param status The status to get the error string.
*/
virtual std::string GetErrorString(const int32_t status) = 0;
protected:
/// The CAN client is started.
bool is_started_ = false;
};
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/can_client_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/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/can_client/fake/fake_can_client.h"
#if USE_ESD_CAN
#include "modules/drivers/canbus/can_client/esd/esd_can_client.h"
#endif
#include "modules/drivers/canbus/can_client/socket/socket_can_client_raw.h"
#include "modules/drivers/canbus/can_client/hermes_can/hermes_can_client.h"
#include "cyber/common/log.h"
#include "modules/common/util/util.h"
namespace apollo {
namespace drivers {
namespace canbus {
CanClientFactory::CanClientFactory() {}
void CanClientFactory::RegisterCanClients() {
AINFO << "CanClientFactory::RegisterCanClients";
Register(CANCardParameter::FAKE_CAN,
[]() -> CanClient* { return new can::FakeCanClient(); });
#if USE_ESD_CAN
AINFO << "register can: " << CANCardParameter::ESD_CAN;
Register(CANCardParameter::ESD_CAN,
[]() -> CanClient* { return new can::EsdCanClient(); });
#endif
Register(CANCardParameter::SOCKET_CAN_RAW,
[]() -> CanClient* { return new can::SocketCanClientRaw(); });
Register(CANCardParameter::HERMES_CAN,
[]() -> CanClient* { return new can::HermesCanClient(); });
}
std::unique_ptr<CanClient> CanClientFactory::CreateCANClient(
const CANCardParameter& parameter) {
auto factory = CreateObject(parameter.brand());
if (!factory) {
AERROR << "Failed to create CAN client with parameter: "
<< parameter.DebugString();
} else if (!factory->Init(parameter)) {
AERROR << "Failed to initialize CAN card with parameter: "
<< parameter.DebugString();
}
return factory;
}
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/can_client_tool.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 <cstdint>
#include <iostream>
#include <memory>
#include <thread>
#include "cyber/common/file.h"
#include "cyber/common/log.h"
#include "cyber/time/time.h"
#include "gflags/gflags.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/common/util/factory.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
DEFINE_bool(only_one_send, false, "only send test.");
DEFINE_string(can_client_conf_file_a,
"modules/canbus/conf/can_client_conf_a.pb.txt",
"can client conf for client a");
DEFINE_string(can_client_conf_file_b,
"modules/canbus/conf/can_client_conf_b.pb.txt",
"can client conf for client b");
DEFINE_int64(agent_mutual_send_frames, 1000, "Every agent send frame num");
const int32_t MAX_CAN_SEND_FRAME_LEN = 1;
const int32_t MAX_CAN_RECV_FRAME_LEN = 10;
using apollo::cyber::Time;
namespace apollo {
namespace drivers {
namespace canbus {
struct TestCanParam {
CANCardParameter conf;
bool is_first_agent = false;
int32_t recv_cnt = 0;
int32_t recv_err_cnt = 0;
int32_t send_cnt = 0;
int32_t send_err_cnt = 0;
int32_t send_lost_cnt = 0;
int32_t send_time = 0;
int32_t recv_time = 0;
CanClient *can_client = nullptr;
TestCanParam() = default;
void print() {
AINFO << "conf: " << conf.ShortDebugString()
<< ", total send: " << send_cnt + send_err_cnt << "/"
<< FLAGS_agent_mutual_send_frames << ", send_ok: " << send_cnt
<< " , send_err_cnt: " << send_err_cnt
<< ", send_lost_cnt: " << send_lost_cnt << ", recv_cnt: " << recv_cnt
<< ", send_time: " << send_time << ", recv_time: " << recv_time;
}
};
class CanAgent {
public:
explicit CanAgent(TestCanParam *param_ptr) : param_ptr_(param_ptr) {}
TestCanParam *param_ptr() { return param_ptr_; }
CanAgent *other_agent() { return other_agent_; }
bool Start() {
thread_recv_.reset(new std::thread([this] { RecvThreadFunc(); }));
if (thread_recv_ == nullptr) {
AERROR << "Unable to create recv thread.";
return false;
}
thread_send_.reset(new std::thread([this] { SendThreadFunc(); }));
if (thread_send_ == nullptr) {
AERROR << "Unable to create send thread.";
return false;
}
return true;
}
void SendThreadFunc() {
using common::ErrorCode;
AINFO << "Send thread starting...";
TestCanParam *param = param_ptr();
CanClient *client = param->can_client;
std::vector<CanFrame> frames;
frames.resize(MAX_CAN_SEND_FRAME_LEN);
int32_t count = 0;
int32_t start_id = 0;
int32_t end_id = 0;
int32_t id = 0;
if (param->is_first_agent) {
start_id = 1;
end_id = 128;
} else {
start_id = 129;
end_id = start_id + 127;
}
id = start_id;
int32_t send_id = id;
AINFO << "port:" << param->conf.ShortDebugString()
<< ", start_id:" << start_id << ", end_id:" << end_id;
// wait for other agent receiving is ok.
while (!other_agent()->is_receiving()) {
std::this_thread::yield();
}
int64_t start = Time::Now().ToMicrosecond();
while (true) {
// param->print();
if (count >= FLAGS_agent_mutual_send_frames) {
break;
}
for (int32_t i = 0; i < MAX_CAN_SEND_FRAME_LEN; ++i) {
// frames[i].id = id_count & 0x3FF;
send_id = id;
frames[i].id = id;
frames[i].len = 8;
frames[i].data[7] = static_cast<uint8_t>(count % 256);
for (uint8_t j = 0; j < 7; ++j) {
frames[i].data[j] = j;
}
++count;
++id;
if (id > end_id) {
id = start_id;
}
}
int32_t frame_num = MAX_CAN_SEND_FRAME_LEN;
if (client->Send(frames, &frame_num) != ErrorCode::OK) {
param->send_err_cnt += MAX_CAN_SEND_FRAME_LEN;
AERROR << "send_thread send msg failed!, id:" << send_id
<< ", conf:" << param->conf.ShortDebugString();
} else {
param->send_cnt += frame_num;
param->send_lost_cnt += MAX_CAN_SEND_FRAME_LEN - frame_num;
AINFO << "send_frames: " << frame_num << "send_frame#"
<< frames[0].CanFrameString()
<< " send lost:" << MAX_CAN_SEND_FRAME_LEN - frame_num
<< ", conf:" << param->conf.ShortDebugString();
}
}
int64_t end = Time::Now().ToMicrosecond();
param->send_time = static_cast<int32_t>(end - start);
// In case for finish too quick to receiver miss some msg
sleep(2);
AINFO << "Send thread stopping..." << param->conf.ShortDebugString();
is_sending_finish(true);
return;
}
void AddOtherAgent(CanAgent *agent) { other_agent_ = agent; }
bool is_receiving() const { return is_receiving_; }
void is_receiving(bool val) { is_receiving_ = val; }
bool is_sending_finish() const { return is_sending_finish_; }
void is_sending_finish(bool val) { is_sending_finish_ = val; }
void RecvThreadFunc() {
using common::ErrorCode;
AINFO << "Receive thread starting...";
TestCanParam *param = param_ptr();
CanClient *client = param->can_client;
int64_t start = 0;
std::vector<CanFrame> buf;
bool first = true;
while (!other_agent()->is_sending_finish()) {
is_receiving(true);
int32_t len = MAX_CAN_RECV_FRAME_LEN;
ErrorCode ret = client->Receive(&buf, &len);
if (len == 0) {
AINFO << "recv frame:0";
continue;
}
if (first) {
start = Time::Now().ToMicrosecond();
first = false;
}
if (ret != ErrorCode::OK || len == 0) {
// AINFO << "channel:" << param->conf.channel_id()
// << ", recv frame:failed, code:" << ret;
AINFO << "recv error:" << ret;
continue;
}
for (int32_t i = 0; i < len; ++i) {
param->recv_cnt = param->recv_cnt + 1;
AINFO << "recv_frame#" << buf[i].CanFrameString()
<< " conf:" << param->conf.ShortDebugString()
<< ",recv_cnt: " << param->recv_cnt;
}
}
int64_t end = Time::Now().ToMicrosecond();
param->recv_time = static_cast<int32_t>(end - start);
AINFO << "Recv thread stopping..., conf:" << param->conf.ShortDebugString();
return;
}
void WaitForFinish() {
if (thread_send_ != nullptr && thread_send_->joinable()) {
thread_send_->join();
thread_send_.reset();
AINFO << "Send thread stopped. conf:"
<< param_ptr_->conf.ShortDebugString();
}
if (thread_recv_ != nullptr && thread_recv_->joinable()) {
thread_recv_->join();
thread_recv_.reset();
AINFO << "Recv thread stopped. conf:"
<< param_ptr_->conf.ShortDebugString();
}
}
private:
bool is_receiving_ = false;
bool is_sending_finish_ = false;
CanAgent *other_agent_ = nullptr;
TestCanParam *param_ptr_ = nullptr;
std::unique_ptr<std::thread> thread_recv_;
std::unique_ptr<std::thread> thread_send_;
};
} // namespace canbus
} // namespace drivers
} // namespace apollo
int main(int32_t argc, char **argv) {
google::InitGoogleLogging(argv[0]);
google::ParseCommandLineFlags(&argc, &argv, true);
using apollo::common::ErrorCode;
using apollo::drivers::canbus::CanAgent;
using apollo::drivers::canbus::CANCardParameter;
using apollo::drivers::canbus::CanClient;
using apollo::drivers::canbus::CanClientFactory;
using apollo::drivers::canbus::TestCanParam;
CANCardParameter can_client_conf_a;
std::shared_ptr<TestCanParam> param_ptr_a(new TestCanParam());
std::shared_ptr<TestCanParam> param_ptr_b(new TestCanParam());
auto can_client_factory = CanClientFactory::Instance();
can_client_factory->RegisterCanClients();
if (!apollo::cyber::common::GetProtoFromFile(FLAGS_can_client_conf_file_a,
&can_client_conf_a)) {
AERROR << "Unable to load canbus conf file: "
<< FLAGS_can_client_conf_file_a;
return -1;
}
AINFO << "Conf file is loaded: " << FLAGS_can_client_conf_file_a;
AINFO << can_client_conf_a.ShortDebugString();
auto client_a = can_client_factory->CreateObject(can_client_conf_a.brand());
if (!client_a || !client_a->Init(can_client_conf_a) ||
client_a->Start() != ErrorCode::OK) {
AERROR << "Create can client a failed.";
return -1;
}
param_ptr_a->can_client = client_a.get();
param_ptr_a->is_first_agent = true;
param_ptr_a->conf = can_client_conf_a;
CANCardParameter can_client_conf_b;
std::unique_ptr<CanClient> client_b;
if (!FLAGS_only_one_send) {
if (!apollo::cyber::common::GetProtoFromFile(FLAGS_can_client_conf_file_b,
&can_client_conf_b)) {
AERROR << "Unable to load canbus conf file: "
<< FLAGS_can_client_conf_file_b;
return -1;
}
AINFO << "Conf file is loaded: " << FLAGS_can_client_conf_file_b;
AINFO << can_client_conf_b.ShortDebugString();
client_b = can_client_factory->CreateObject(can_client_conf_b.brand());
if (!client_b || !client_b->Init(can_client_conf_b) ||
client_b->Start() != ErrorCode::OK) {
AERROR << "Create can client b failed.";
return -1;
}
param_ptr_b->can_client = client_b.get();
param_ptr_b->conf = can_client_conf_b;
}
CanAgent agent_a(param_ptr_a.get());
CanAgent agent_b(param_ptr_b.get());
agent_a.AddOtherAgent(&agent_b);
agent_b.AddOtherAgent(&agent_a);
if (!agent_a.Start()) {
AERROR << "Agent a start failed.";
return -1;
}
if (FLAGS_only_one_send) {
agent_b.is_receiving(true);
agent_b.is_sending_finish(true);
} else {
if (!agent_b.Start()) {
AERROR << "Agent b start failed.";
return -1;
}
}
agent_a.WaitForFinish();
if (!FLAGS_only_one_send) {
agent_b.WaitForFinish();
}
param_ptr_a->print();
if (!FLAGS_only_one_send) {
param_ptr_b->print();
}
return 0;
}
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/esd/esd_can_client.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.
*****************************************************************************/
/**
* @file esd_can_client.cc
* @brief the encapsulate call the api of esd can card according to can_client.h
*interface
**/
#include "modules/drivers/canbus/can_client/esd/esd_can_client.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/sensor_gflags.h"
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
using apollo::common::ErrorCode;
bool EsdCanClient::Init(const CANCardParameter ¶meter) {
if (!parameter.has_channel_id()) {
AERROR << "Init CAN failed: parameter does not have channel id. The "
"parameter is "
<< parameter.DebugString();
return false;
}
port_ = parameter.channel_id();
int num_ports = parameter.num_ports();
if (port_ > num_ports || port_ < 0) {
AERROR << "Can port number [" << port_ << "] is out of range [0, "
<< num_ports << ") !";
return false;
}
return true;
}
EsdCanClient::~EsdCanClient() {
if (dev_handler_) {
Stop();
}
}
ErrorCode EsdCanClient::Start() {
if (is_started_) {
return ErrorCode::OK;
}
// open device
// guss net is the device minor number, if one card is 0,1
// if more than one card, when install driver u can specify the minior id
// int32_t ret = canOpen(net, pCtx->mode, txbufsize, rxbufsize, 0, 0,
// &dev_handler_);
uint32_t mode = 0;
if (FLAGS_esd_can_extended_frame) {
mode = NTCAN_MODE_NO_RTR;
}
// mode |= NTCAN_MODE_NO_RTR;
int32_t ret = canOpen(port_, mode, NTCAN_MAX_TX_QUEUESIZE,
NTCAN_MAX_RX_QUEUESIZE, 5, 5, &dev_handler_);
if (ret != NTCAN_SUCCESS) {
AERROR << "open device error code [" << ret << "]: " << GetErrorString(ret);
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
// init config and state
// After a CAN handle is created with canOpen() the CAN-ID filter is
// cleared
// (no CAN messages
// will pass the filter). To receive a CAN message with a certain CAN-ID
// or an
// NTCAN-Event with
// a certain Event-ID it is required to enable this ID in the handle
// filter as
// otherwise a
// received message or event is discarded by the driver for this handle.
// 1. set receive message_id filter, ie white list
int32_t id_count = 0x800;
ret = canIdRegionAdd(dev_handler_, 0, &id_count);
if (FLAGS_esd_can_extended_frame) {
id_count = 0x1FFFFFFE;
ret = canIdRegionAdd(dev_handler_, 0x20000000, &id_count);
}
if (ret != NTCAN_SUCCESS) {
AERROR << "add receive msg id filter error code: " << ret << ", "
<< GetErrorString(ret);
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
// 2. set baudrate to 500k
ret = canSetBaudrate(dev_handler_, NTCAN_BAUD_500);
if (ret != NTCAN_SUCCESS) {
AERROR << "set baudrate error code: " << ret << ", " << GetErrorString(ret);
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
is_started_ = true;
return ErrorCode::OK;
}
void EsdCanClient::Stop() {
if (is_started_) {
is_started_ = false;
int32_t ret = canClose(dev_handler_);
if (ret != NTCAN_SUCCESS) {
AERROR << "close error code:" << ret << ", " << GetErrorString(ret);
} else {
AINFO << "close esd can ok. port:" << port_;
}
}
}
// Synchronous transmission of CAN messages
ErrorCode EsdCanClient::Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num) {
CHECK_NOTNULL(frame_num);
CHECK_EQ(frames.size(), static_cast<size_t>(*frame_num));
if (!is_started_) {
AERROR << "Esd can client has not been initiated! Please init first!";
return ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED;
}
for (size_t i = 0; i < frames.size() && i < MAX_CAN_SEND_FRAME_LEN; ++i) {
send_frames_[i].id = frames[i].id;
send_frames_[i].len = frames[i].len;
std::memcpy(send_frames_[i].data, frames[i].data, frames[i].len);
}
// Synchronous transmission of CAN messages
int32_t ret = canWrite(dev_handler_, send_frames_, frame_num, nullptr);
if (ret != NTCAN_SUCCESS) {
AERROR << "send message failed, error code: " << ret << ", "
<< GetErrorString(ret);
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
return ErrorCode::OK;
}
// buf size must be 8 bytes, every time, we receive only one frame
ErrorCode EsdCanClient::Receive(std::vector<CanFrame> *const frames,
int32_t *const frame_num) {
if (!is_started_) {
AERROR << "Esd can client is not init! Please init first!";
return ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED;
}
if (*frame_num > MAX_CAN_RECV_FRAME_LEN || *frame_num < 0) {
AERROR << "recv can frame num not in range[0, " << MAX_CAN_RECV_FRAME_LEN
<< "], frame_num:" << *frame_num;
// TODO(Authors): check the difference of returning frame_num/error_code
return ErrorCode::CAN_CLIENT_ERROR_FRAME_NUM;
}
const int32_t ret = canRead(dev_handler_, recv_frames_, frame_num, nullptr);
// rx timeout not log
if (ret == NTCAN_RX_TIMEOUT) {
return ErrorCode::OK;
}
if (ret != NTCAN_SUCCESS) {
AERROR << "receive message failed, error code: " << ret << ", "
<< GetErrorString(ret);
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
for (int32_t i = 0; i < *frame_num && i < MAX_CAN_RECV_FRAME_LEN; ++i) {
CanFrame cf;
cf.id = recv_frames_[i].id;
cf.len = recv_frames_[i].len;
std::memcpy(cf.data, recv_frames_[i].data, recv_frames_[i].len);
frames->push_back(cf);
}
return ErrorCode::OK;
}
/************************************************************************/
/************************************************************************/
/* Function: GetErrorString() */
/* Return ASCII representation of NTCAN return code */
/************************************************************************/
/************************************************************************/
const int32_t ERROR_BUF_SIZE = 200;
std::string EsdCanClient::GetErrorString(const NTCAN_RESULT ntstatus) {
struct ERR2STR {
NTCAN_RESULT ntstatus;
const char *str;
};
int8_t str_buf[ERROR_BUF_SIZE];
static const struct ERR2STR err2str[] = {
{NTCAN_SUCCESS, "NTCAN_SUCCESS"},
{NTCAN_RX_TIMEOUT, "NTCAN_RX_TIMEOUT"},
{NTCAN_TX_TIMEOUT, "NTCAN_TX_TIMEOUT"},
{NTCAN_TX_ERROR, "NTCAN_TX_ERROR"},
{NTCAN_CONTR_OFF_BUS, "NTCAN_CONTR_OFF_BUS"},
{NTCAN_CONTR_BUSY, "NTCAN_CONTR_BUSY"},
{NTCAN_CONTR_WARN, "NTCAN_CONTR_WARN"},
{NTCAN_NO_ID_ENABLED, "NTCAN_NO_ID_ENABLED"},
{NTCAN_ID_ALREADY_ENABLED, "NTCAN_ID_ALREADY_ENABLED"},
{NTCAN_ID_NOT_ENABLED, "NTCAN_ID_NOT_ENABLED"},
{NTCAN_INVALID_FIRMWARE, "NTCAN_INVALID_FIRMWARE"},
{NTCAN_MESSAGE_LOST, "NTCAN_MESSAGE_LOST"},
{NTCAN_INVALID_PARAMETER, "NTCAN_INVALID_PARAMETER"},
{NTCAN_INVALID_HANDLE, "NTCAN_INVALID_HANDLE"},
{NTCAN_NET_NOT_FOUND, "NTCAN_NET_NOT_FOUND"},
#ifdef NTCAN_IO_INCOMPLETE
{NTCAN_IO_INCOMPLETE, "NTCAN_IO_INCOMPLETE"},
#endif
#ifdef NTCAN_IO_PENDING
{NTCAN_IO_PENDING, "NTCAN_IO_PENDING"},
#endif
#ifdef NTCAN_INVALID_HARDWARE
{NTCAN_INVALID_HARDWARE, "NTCAN_INVALID_HARDWARE"},
#endif
#ifdef NTCAN_PENDING_WRITE
{NTCAN_PENDING_WRITE, "NTCAN_PENDING_WRITE"},
#endif
#ifdef NTCAN_PENDING_READ
{NTCAN_PENDING_READ, "NTCAN_PENDING_READ"},
#endif
#ifdef NTCAN_INVALID_DRIVER
{NTCAN_INVALID_DRIVER, "NTCAN_INVALID_DRIVER"},
#endif
#ifdef NTCAN_OPERATION_ABORTED
{NTCAN_OPERATION_ABORTED, "NTCAN_OPERATION_ABORTED"},
#endif
#ifdef NTCAN_WRONG_DEVICE_STATE
{NTCAN_WRONG_DEVICE_STATE, "NTCAN_WRONG_DEVICE_STATE"},
#endif
{NTCAN_INSUFFICIENT_RESOURCES, "NTCAN_INSUFFICIENT_RESOURCES"},
#ifdef NTCAN_HANDLE_FORCED_CLOSE
{NTCAN_HANDLE_FORCED_CLOSE, "NTCAN_HANDLE_FORCED_CLOSE"},
#endif
#ifdef NTCAN_NOT_IMPLEMENTED
{NTCAN_NOT_IMPLEMENTED, "NTCAN_NOT_IMPLEMENTED"},
#endif
#ifdef NTCAN_NOT_SUPPORTED
{NTCAN_NOT_SUPPORTED, "NTCAN_NOT_SUPPORTED"},
#endif
#ifdef NTCAN_SOCK_CONN_TIMEOUT
{NTCAN_SOCK_CONN_TIMEOUT, "NTCAN_SOCK_CONN_TIMEOUT"},
#endif
#ifdef NTCAN_SOCK_CMD_TIMEOUT
{NTCAN_SOCK_CMD_TIMEOUT, "NTCAN_SOCK_CMD_TIMEOUT"},
#endif
#ifdef NTCAN_SOCK_HOST_NOT_FOUND
{NTCAN_SOCK_HOST_NOT_FOUND, "NTCAN_SOCK_HOST_NOT_FOUND"},
#endif
#ifdef NTCAN_CONTR_ERR_PASSIVE
{NTCAN_CONTR_ERR_PASSIVE, "NTCAN_CONTR_ERR_PASSIVE"},
#endif
#ifdef NTCAN_ERROR_NO_BAUDRATE
{NTCAN_ERROR_NO_BAUDRATE, "NTCAN_ERROR_NO_BAUDRATE"},
#endif
#ifdef NTCAN_ERROR_LOM
{NTCAN_ERROR_LOM, "NTCAN_ERROR_LOM"},
#endif
{(NTCAN_RESULT)0xffffffff, "NTCAN_UNKNOWN"} /* stop-mark */
};
const struct ERR2STR *es = err2str;
do {
if (es->ntstatus == ntstatus) {
break;
}
es++;
} while ((uint32_t)es->ntstatus != 0xffffffff);
#ifdef NTCAN_ERROR_FORMAT_LONG
{
NTCAN_RESULT res;
char sz_error_text[60];
res = canFormatError(ntstatus, NTCAN_ERROR_FORMAT_LONG, sz_error_text,
static_cast<uint32_t>(sizeof(sz_error_text) - 1));
if (NTCAN_SUCCESS == res) {
snprintf(reinterpret_cast<char *>(str_buf), ERROR_BUF_SIZE, "%s - %s",
es->str, sz_error_text);
} else {
snprintf(reinterpret_cast<char *>(str_buf), ERROR_BUF_SIZE, "%s(0x%08x)",
es->str, ntstatus);
}
}
#else
snprintf(reinterpret_cast<char *>(str_buf), ERROR_BUF_SIZE, "%s(0x%08x)",
es->str, ntstatus);
#endif /* of NTCAN_ERROR_FORMAT_LONG */
return std::string((const char *)(str_buf));
}
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/esd/esd_can_client_test.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/drivers/canbus/can_client/esd/esd_can_client.h"
#include <vector>
#include "gtest/gtest.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
using apollo::common::ErrorCode;
TEST(EsdCanClientTest, simple_test) {
CANCardParameter param;
param.set_brand(CANCardParameter::ESD_CAN);
param.set_channel_id(CANCardParameter::CHANNEL_ID_ZERO);
EsdCanClient esd_can_client;
EXPECT_TRUE(esd_can_client.Init(param));
EXPECT_EQ(esd_can_client.Start(), ErrorCode::CAN_CLIENT_ERROR_BASE);
std::vector<CanFrame> frames;
int32_t num = 0;
EXPECT_EQ(esd_can_client.Send(frames, &num),
ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED);
EXPECT_EQ(esd_can_client.Receive(&frames, &num),
ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED);
CanFrame can_frame;
frames.push_back(can_frame);
EXPECT_EQ(esd_can_client.SendSingleFrame(frames),
ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED);
esd_can_client.Stop();
}
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/esd/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools/platform:build_defs.bzl", "if_esd_can")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "esd_can_client",
srcs = if_esd_can(["esd_can_client.cc"]),
hdrs = if_esd_can(["esd_can_client.h"]),
deps = if_esd_can([
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/drivers/canbus:sensor_gflags",
"//modules/drivers/canbus/can_client",
"//third_party/can_card_library/esd_can",
]),
)
cc_test(
name = "esd_can_client_test",
size = "small",
srcs = if_esd_can(["esd_can_client_test.cc"]),
deps = if_esd_can([
":esd_can_client",
"//cyber",
"//modules/drivers/canbus/common:canbus_common",
]) + [
"@com_google_googletest//:gtest_main",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/esd/esd_can_client.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
* @brief Defines the EsdCanClient class which inherits CanClient.
*/
#pragma once
#include <string>
#include <vector>
#include "esd_can/include/ntcan.h"
#include "gflags/gflags.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
/**
* @namespace apollo::drivers::canbus::can
* @brief apollo::drivers::canbus::can
*/
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
/**
* @class EsdCanClient
* @brief The class which defines an ESD CAN client which inherits CanClient.
*/
class EsdCanClient : public CanClient {
public:
/**
* @brief Initialize the ESD CAN client by specified CAN card parameters.
* @param parameter CAN card parameters to initialize the CAN client.
* @return If the initialization is successful.
*/
bool Init(const CANCardParameter ¶meter) override;
/**
* @brief Destructor
*/
virtual ~EsdCanClient();
/**
* @brief Start the ESD CAN client.
* @return The status of the start action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Start() override;
/**
* @brief Stop the ESD CAN client.
*/
void Stop() override;
/**
* @brief Send messages
* @param frames The messages to send.
* @param frame_num The amount of messages to send.
* @return The status of the sending action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num) override;
/**
* @brief Receive messages
* @param frames The messages to receive.
* @param frame_num The amount of messages to receive.
* @return The status of the receiving action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Receive(std::vector<CanFrame> *const frames,
int32_t *const frame_num) override;
/**
* @brief Get the error string.
* @param status The status to get the error string.
*/
std::string GetErrorString(const int32_t status) override;
private:
NTCAN_HANDLE dev_handler_;
CANCardParameter::CANChannelId port_;
CMSG send_frames_[MAX_CAN_SEND_FRAME_LEN];
CMSG recv_frames_[MAX_CAN_RECV_FRAME_LEN];
};
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/hermes_can_client.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/drivers/canbus/can_client/hermes_can/hermes_can_client.h"
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
using apollo::common::ErrorCode;
HermesCanClient::~HermesCanClient() {
if (dev_handler_) {
Stop();
}
}
bool HermesCanClient::Init(const CANCardParameter ¶meter) {
if (!parameter.has_channel_id()) {
AERROR << "Init CAN failed: parameter does not have channel id. The "
"parameter is "
<< parameter.DebugString();
return false;
}
port_ = parameter.channel_id();
auto num_ports = parameter.num_ports();
if (port_ > static_cast<int32_t>(num_ports) || port_ < 0) {
AERROR << "Can port number [" << port_ << "] is out of bound [0,"
<< num_ports << ")";
return false;
}
return true;
}
ErrorCode HermesCanClient::Start() {
if (is_init_) {
return ErrorCode::OK;
}
// open device
int32_t ret = bcan_open(port_, 0,
5, // 5ms for rx timeout
5, // 5ms for tx timeout
&dev_handler_);
if (ret != ErrorCode::OK) {
AERROR << "Open device error code: " << ret << ", channel id: " << port_;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
AINFO << "Open device success, channel id: " << port_;
// 1. set baudrate to 500k
ret = bcan_set_baudrate(dev_handler_, BCAN_BAUDRATE_500K);
if (ret != ErrorCode::OK) {
AERROR << "Set baudrate error Code: " << ret;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
// 2. start receive
ret = bcan_start(dev_handler_);
if (ret != ErrorCode::OK) {
AERROR << "Start hermes can card failed: " << ret;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
is_init_ = true;
return ErrorCode::OK;
}
void HermesCanClient::Stop() {
if (is_init_) {
is_init_ = false;
int32_t ret = bcan_close(dev_handler_);
if (ret != ErrorCode::OK) {
AERROR << "close error code: " << ret;
}
}
}
// Synchronous transmission of CAN messages
apollo::common::ErrorCode HermesCanClient::Send(
const std::vector<CanFrame> &frames, int32_t *const frame_num) {
/*
typedef struct bcan_msg {
uint32_t bcan_msg_id; // source CAN node id
uint8_t bcan_msg_datalen; // message data length
uint8_t bcan_msg_rsv[3]; // reserved
uint8_t bcan_msg_data[8]; // message data
uint64_t bcan_msg_timestamp; // TBD
} bcan_msg_t;
*/
CHECK_NOTNULL(frame_num);
CHECK_EQ(frames.size(), static_cast<size_t>(*frame_num));
if (!is_init_) {
AERROR << "Hermes can client is not init! Please init first!";
return ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED;
}
// if (*frame_num > MAX_CAN_SEND_FRAME_LEN || *frame_num < 0) {
// AERROR << "send can frame num not in range[0, "
// << MAX_CAN_SEND_FRAME_LEN << "], frame_num:" << *frame_num;
// return ErrorCode::CAN_CLIENT_ERROR_FRAME_NUM;
// }
for (int i = 0; i < *frame_num; ++i) {
_send_frames[i].bcan_msg_id = frames[i].id;
_send_frames[i].bcan_msg_datalen = frames[i].len;
memcpy(_send_frames[i].bcan_msg_data, frames[i].data, frames[i].len);
}
// Synchronous transmission of CAN messages
int32_t send_num = *frame_num;
int32_t ret = bcan_send(dev_handler_, _send_frames, send_num);
if (ret < 0) {
int ret_send_error = bcan_get_status(dev_handler_);
AERROR << "send message failed, error code: " << ret
<< ", send error: " << ret_send_error;
return ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED;
}
*frame_num = ret;
return ErrorCode::OK;
}
// buf size must be 8 bytes, every time, we receive only one frame
const int RX_TIMEOUT = -7;
apollo::common::ErrorCode HermesCanClient::Receive(
std::vector<CanFrame> *const frames, int32_t *const frame_num) {
if (!is_init_) {
AERROR << "Hermes can client is not init! Please init first!";
return ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED;
}
if (*frame_num > MAX_CAN_RECV_FRAME_LEN || *frame_num < 0) {
AERROR << "recv can frame num not in range[0, " << MAX_CAN_RECV_FRAME_LEN
<< "], frame_num:" << *frame_num;
return ErrorCode::CAN_CLIENT_ERROR_FRAME_NUM;
}
int32_t ret = bcan_recv(dev_handler_, _recv_frames, *frame_num);
// don't log timeout
if (ret == RX_TIMEOUT) {
*frame_num = 0;
return ErrorCode::OK;
}
if (ret < 0) {
int ret_rece_error = bcan_get_status(dev_handler_);
AERROR << "receive message failed, error code:" << ret
<< "receive error:" << ret_rece_error;
return ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED;
}
*frame_num = ret;
// is ret num is equal *frame_num?
for (int i = 0; i < *frame_num; ++i) {
CanFrame cf;
cf.id = _recv_frames[i].bcan_msg_id;
cf.len = _recv_frames[i].bcan_msg_datalen;
cf.timestamp.tv_sec = _recv_frames[i].bcan_msg_timestamp.tv_sec;
cf.timestamp.tv_usec = _recv_frames[i].bcan_msg_timestamp.tv_usec;
memcpy(cf.data, _recv_frames[i].bcan_msg_data, cf.len);
frames->push_back(cf);
}
return ErrorCode::OK;
}
std::string HermesCanClient::GetErrorString(int32_t ntstatus) { return ""; }
void HermesCanClient::SetInited(bool init) { is_init_ = init; }
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/bcan_defs.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
#ifndef __KERNEL__
#include <sys/time.h>
#else
#include <linux/time.h>
#endif
/*
* Baidu CAN message definition
*/
typedef struct bcan_msg {
unsigned int bcan_msg_id; /* source CAN node id */
unsigned char bcan_msg_datalen; /* message data len */
unsigned char bcan_msg_rsv[3];
unsigned char bcan_msg_data[8]; /* message data */
struct timeval bcan_msg_timestamp;
} bcan_msg_t;
/*
* CAN error code
*/
enum bcan_err_code {
BCAN_PARAM_INVALID = -12,
BCAN_HDL_INVALID,
BCAN_DEV_INVALID,
BCAN_DEV_ERR,
BCAN_DEV_BUSY,
BCAN_TIMEOUT,
BCAN_FAIL,
BCAN_NOT_SUPPORTED,
BCAN_NOT_IMPLEMENTED,
BCAN_INVALID,
BCAN_NO_BUFFERS,
BCAN_ERR,
BCAN_OK, /* 0 */
BCAN_PARTIAL_OK
};
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/bcan.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 <sys/ioctl.h>
#include <sys/types.h>
#include <cstdint>
#include <cstdlib>
/* bcan_msg_t and bcan_err_code definitions. */
// #include "linux/bcan_defs.h"
#include "modules/drivers/canbus/can_client/hermes_can/bcan_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BCAN_MAX_TX_MSG 256
#define BCAN_MAX_RX_MSG 256
// Channel states
#define BCAN_DEV_UNINIT -1
#define BCAN_DEV_OPEN (1 << 0)
#define BCAN_DEV_CLOSE (1 << 1)
#define BCAN_DEV_BAUD_SET (1 << 2)
#define BCAN_DEV_NORMAL (1 << 3)
#define BCAN_DEV_LOOPBACK (1 << 4)
#define BCAN_DEV_CONFIG (1 << 5)
#define BCAN_DEV_START (1 << 6)
#define BCAN_DEV_STOP (1 << 7)
#define BCAN_DEV_ACTIVE (1 << 8)
#define BCAN_DEV_RECVD (1 << 9)
typedef uint64_t bcan_hdl_t;
enum bcan_baudrate_val {
BCAN_BAUDRATE_1M,
BCAN_BAUDRATE_500K,
BCAN_BAUDRATE_250K,
BCAN_BAUDRATE_150K,
BCAN_BAUDRATE_NUM
};
/* Returns bcan library version. */
const char *bcan_get_libversion(void);
/* Returns detailed bcan library build info. */
const char *bcan_bld_info(void);
/* Returns brief bcan library build info. */
const char *bcan_bld_info_short(void);
/* Returns error message corresponding to the given error code. */
const char *bcan_get_err_msg(int err_code);
int bcan_open(uint32_t dev_index, uint32_t flags, uint64_t tx_to,
uint64_t rx_to, bcan_hdl_t *hdl);
int bcan_close(bcan_hdl_t hdl);
int bcan_start(bcan_hdl_t hdl);
int bcan_stop(bcan_hdl_t hdl);
int bcan_set_loopback(bcan_hdl_t hdl);
int bcan_unset_loopback(bcan_hdl_t hdl);
int bcan_set_baudrate(bcan_hdl_t hdl, uint32_t rate);
int bcan_get_baudrate(bcan_hdl_t hdl, uint32_t *rate);
int bcan_recv(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg);
int bcan_send(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg);
int bcan_send_hi_pri(bcan_hdl_t hdl, bcan_msg_t *buf);
int bcan_get_status(bcan_hdl_t hdl);
int bcan_get_err_counter(bcan_hdl_t hdl, uint8_t *rx_err, uint8_t *tx_err);
/* The following APIs are not implemented yet. { */
int bcan_id_add(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end);
int bcan_id_add_all(bcan_hdl_t hdl);
int bcan_id_remove(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end);
int bcan_id_remove_all(bcan_hdl_t hdl);
/* } Not implemented. */
#ifdef __cplusplus
}
#endif
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/bcan_lib.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 <sys/ioctl.h>
#include <sys/types.h>
#include <cstdint>
#include <cstdlib>
#include "linux/zynq_api.h"
#ifdef DEBUG
#define BLOG_DBG0(s...) syslog(LOG_DEBUG, s);
#else
#define BLOG_DBG0(s...) \
do { \
} while (0);
#endif
#define BLOG_ERR(s...) syslog(LOG_ERR, s);
typedef uint64_t bcan_hdl_t;
#define BCAN_MAX_TX_MSG 256
#define BCAN_MAX_RX_MSG 256
typedef struct bcan_ihdl {
int dev_index;
int dev_state;
int fd;
uint32_t baudrate;
uint32_t tx_to;
uint32_t rx_to;
} bcan_ihdl_t;
// Channel states
#define BCAN_DEV_UNINIT -1
#define BCAN_DEV_OPEN (1 << 0)
#define BCAN_DEV_CLOSE (1 << 1)
#define BCAN_DEV_BAUD_SET (1 << 2)
#define BCAN_DEV_NORMAL (1 << 3)
#define BCAN_DEV_LOOPBACK (1 << 4)
#define BCAN_DEV_CONFIG (1 << 5)
#define BCAN_DEV_START (1 << 6)
#define BCAN_DEV_STOP (1 << 7)
#define BCAN_DEV_ACTIVE (1 << 8)
#define BCAN_DEV_RECVD (1 << 9)
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/hermes_can_client.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 <string>
#include <vector>
#include "gflags/gflags.h"
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_client/hermes_can/bcan.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
/**
* @namespace apollo::drivers::canbus::can
* @brief apollo::drivers::canbus::can
*/
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
/**
* @class HermesCanClient
* @brief The class which defines a BCAN client which inherits CanClient.
*/
class HermesCanClient : public CanClient {
public:
/**
* @brief Initialize the BCAN client by specified CAN card parameters.
* @param parameter CAN card parameters to initialize the CAN client.
*/
// explicit HermesCanClient(const CANCardParameter ¶meter);
/**
* @brief Destructor
*/
virtual ~HermesCanClient();
/**
* @brief Start the ESD CAN client.
* @return The status of the start action which is defined by
* apollo::common::ErrorCode.
*/
bool Init(const CANCardParameter ¶meter) override;
/**
* @brief Start the ESD CAN client.
* @return The status of the start action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Start() override;
/**
* @brief Stop the ESD CAN client.
*/
virtual void Stop();
/**
* @brief Send messages
* @param frames The messages to send.
* @param frame_num The amount of messages to send.
* @return The status of the sending action which is defined by
* apollo::common::ErrorCode.
*/
virtual apollo::common::ErrorCode Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num);
/**
* @brief Receive messages
* @param frames The messages to receive.
* @param frame_num The amount of messages to receive.
* @return The status of the receiving action which is defined by
* apollo::common::ErrorCode.
*/
virtual apollo::common::ErrorCode Receive(std::vector<CanFrame> *const frames,
int32_t *const frame_num);
/**
* @brief Get the error string.
* @param status The status to get the error string.
*/
virtual std::string GetErrorString(const int32_t status);
/**
* @brief Set inited status.
* @param if status is inited.
*/
void SetInited(bool init);
private:
bool is_init_ = false;
bcan_hdl_t dev_handler_;
CANCardParameter::CANChannelId port_;
bcan_msg_t _send_frames[MAX_CAN_SEND_FRAME_LEN];
bcan_msg_t _recv_frames[MAX_CAN_RECV_FRAME_LEN];
};
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
/* vim: set expandtab ts=4 sw=4 sts=4 tw=100: */
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "hermes_can_client",
srcs = ["hermes_can_client.cc"],
hdrs = [
"bcan.h",
"bcan_defs.h",
"hermes_can_client.h",
],
deps = [
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/drivers/canbus/can_client",
"//third_party/can_card_library/hermes_can",
],
)
cc_test(
name = "hermes_can_client_test",
size = "small",
srcs = ["hermes_can_client_test.cc"],
deps = [
"//cyber",
"//modules/drivers/canbus/can_client/hermes_can:hermes_can_client",
"//modules/drivers/canbus/common:canbus_common",
"@com_google_googletest//:gtest_main",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/zynq_api.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 "bcan_defs.h"
#define ZYNQ_MOD_VER "1.6.1.2"
#define ZYNQ_DRV_NAME "zynq"
#define ZYNQ_DEV_NAME_FW "zynq_fw"
#define ZYNQ_DEV_NAME_TRIGGER "zynq_trigger"
#define ZYNQ_DEV_NAME_GPS "zynq_gps"
#define ZYNQ_DEV_NAME_REG "zynq_reg"
#define ZYNQ_DEV_NAME_CAN "zynq_can"
/*
* ioctl argument definition for CAN send/recv
*/
typedef struct ioc_bcan_msg {
bcan_msg_t *ioc_msgs;
unsigned int ioc_msg_num;
unsigned int ioc_msg_num_done;
int ioc_msg_err;
int ioc_msg_rx_clear;
} ioc_bcan_msg_t;
/*
* CAN error and status
*/
typedef struct ioc_bcan_status_err {
unsigned int bcan_status;
unsigned int bcan_err_status;
unsigned int bcan_err_count;
int bcan_ioc_err;
} ioc_bcan_status_err_t;
/* ioctl command list */
#define ZYNQ_IOC_MAGIC ('z' << 12 | 'y' << 8 | 'n' << 4 | 'q')
enum ZYNQ_IOC_GPS_CMD { IOC_GPS_GET = 1, IOC_GPS_GPRMC_GET, IOC_GPS_CMD_MAX };
enum ZYNQ_IOC_TRIGGER_CMD {
IOC_TRIGGER_DISABLE = IOC_GPS_CMD_MAX,
IOC_TRIGGER_ENABLE_GPS,
IOC_TRIGGER_ENABLE_NOGPS,
IOC_TRIGGER_ENABLE_ONE_GPS,
IOC_TRIGGER_ENABLE_ONE_NOGPS,
IOC_TRIGGER_TIMESTAMP,
IOC_TRIGGER_STATUS,
IOC_TRIGGER_STATUS_GPS,
IOC_TRIGGER_STATUS_PPS,
IOC_TRIGGER_FPS_SET,
IOC_TRIGGER_FPS_GET,
IOC_TRIGGER_CMD_MAX
};
enum ZYNQ_IOC_FW_CMD {
IOC_FW_IMAGE_UPLOAD_START = IOC_TRIGGER_CMD_MAX,
IOC_FW_IMAGE_UPLOAD,
IOC_FW_PL_UPDATE, /* PL FPGA FW image update */
IOC_FW_PS_UPDATE, /* PS OS image update */
IOC_FW_GET_VER, /* get the image version */
IOC_FW_CMD_MAX
};
enum ZYNQ_IOC_CAN_CMD {
IOC_CAN_TX_TIMEOUT_SET = IOC_FW_CMD_MAX, /* in milli-seconds */
IOC_CAN_RX_TIMEOUT_SET, /* in milli-seconds */
IOC_CAN_DEV_START,
IOC_CAN_DEV_STOP,
IOC_CAN_DEV_RESET,
IOC_CAN_ID_ADD,
IOC_CAN_ID_DEL,
IOC_CAN_BAUDRATE_SET,
IOC_CAN_BAUDRATE_GET,
IOC_CAN_LOOPBACK_SET,
IOC_CAN_LOOPBACK_UNSET,
IOC_CAN_RECV,
IOC_CAN_SEND,
IOC_CAN_SEND_HIPRI,
IOC_CAN_GET_STATUS_ERR,
IOC_CAN_CMD_MAX
};
enum ZYNQ_IOC_REG_CMD {
IOC_REG_READ = IOC_CAN_CMD_MAX,
IOC_REG_WRITE,
IOC_REG_I2C_READ,
IOC_REG_I2C_WRITE,
IOC_REG_GPSPPS_EVENT_WAIT,
IOC_REG_CMD_MAX
};
enum zynq_baudrate_val {
ZYNQ_BAUDRATE_1M,
ZYNQ_BAUDRATE_500K,
ZYNQ_BAUDRATE_250K,
ZYNQ_BAUDRATE_150K,
ZYNQ_BAUDRATE_NUM
};
/* GPS update ioctl cmds */
#define ZYNQ_GPS_VAL_SZ 12
#define ZYNQ_IOC_GPS_GET _IOR(ZYNQ_IOC_MAGIC, IOC_GPS_GET, unsigned char *)
#define ZYNQ_GPS_GPRMC_VAL_SZ 68
#define ZYNQ_IOC_GPS_GPRMC_GET \
_IOR(ZYNQ_IOC_MAGIC, IOC_GPS_GPRMC_GET, unsigned char *)
/* Trigger ioctl cmds */
#define ZYNQ_IOC_TRIGGER_DISABLE \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_DISABLE, unsigned long)
#define ZYNQ_IOC_TRIGGER_ENABLE_GPS \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_GPS, unsigned long)
#define ZYNQ_IOC_TRIGGER_ENABLE_NOGPS \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_NOGPS, unsigned long)
#define ZYNQ_IOC_TRIGGER_ENABLE_ONE_GPS \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_ONE_GPS, unsigned long)
#define ZYNQ_IOC_TRIGGER_ENABLE_ONE_NOGPS \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_ENABLE_ONE_NOGPS, unsigned long)
#define ZYNQ_IOC_TRIGGER_TIMESTAMP \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_TIMESTAMP, unsigned long)
#define ZYNQ_IOC_TRIGGER_STATUS _IOR(ZYNQ_IOC_MAGIC, IOC_TRIGGER_STATUS, int *)
#define ZYNQ_IOC_TRIGGER_STATUS_GPS \
_IOR(ZYNQ_IOC_MAGIC, IOC_TRIGGER_STATUS_GPS, int *)
#define ZYNQ_IOC_TRIGGER_STATUS_PPS \
_IOR(ZYNQ_IOC_MAGIC, IOC_TRIGGER_STATUS_PPS, int *)
#define ZYNQ_IOC_TRIGGER_FPS_SET \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_FPS_SET, int *)
#define ZYNQ_IOC_TRIGGER_FPS_GET \
_IOW(ZYNQ_IOC_MAGIC, IOC_TRIGGER_FPS_GET, int *)
/* supported GrassHopper fps */
#define GH_FPS_30_DEFAULT 0 /* 30Hz */
#define GH_FPS_20 1 /* 20Hz */
#define GH_FPS_15 2 /* 15Hz */
#define GH_FPS_10 3 /* 10Hz */
/* supported Leopard Imaging fps */
#define LI_FPS_30_DEFAULT 0 /* 30Hz */
#define LI_FPS_20 1 /* 20Hz */
#define LI_FPS_15 2 /* 15Hz */
#define LI_FPS_10 3 /* 10Hz */
/* supported BumbleBee fps */
#define BB_FPS_15_DEFAULT 0 /* 15Hz */
#define BB_FPS_14 1 /* 14Hz */
#define BB_FPS_16 2 /* 16Hz */
/* supported LadyBug fps */
#define LD_FPS_5_DEFAULT 0 /* 5Hz */
#define LD_FPS_7 1 /* 7Hz */
#define LD_FPS_9 2 /* 9Hz */
/* adv_trigger specify fps in format of <GH><LI><BB><LD> */
#define ZYNQ_FPS_GH(fps) ((fps >> 12) & 0xf)
#define ZYNQ_FPS_LI(fps) ((fps >> 8) & 0xf)
#define ZYNQ_FPS_BB(fps) ((fps >> 4) & 0xf)
#define ZYNQ_FPS_LD(fps) (fps & 0xf)
#define ZYNQ_FPS_KEEP 0xf
#define ZYNQ_FPS_KEEP_ALL 0xffff
#define ZYNQ_FPS_ALL_DEFAULT 0
#define ZYNQ_FPS_LI_DEFAULT 0xf0ff
/* Set LI fps only and keep other fps unchanged: 0xf */
#define ZYNQ_FPS_SET_LI_ONLY(li_fps) (0xf0ff | (li_fps << 8))
#define ZYNQ_FPS_VALIDATE_FAIL(fps) \
((ZYNQ_FPS_GH(fps) > 3 && ZYNQ_FPS_GH(fps) != ZYNQ_FPS_KEEP) || \
(ZYNQ_FPS_LI(fps) > 3 && ZYNQ_FPS_LI(fps) != ZYNQ_FPS_KEEP) || \
(ZYNQ_FPS_BB(fps) > 2 && ZYNQ_FPS_BB(fps) != ZYNQ_FPS_KEEP) || \
(ZYNQ_FPS_LD(fps) > 2 && ZYNQ_FPS_LD(fps) != ZYNQ_FPS_KEEP))
/* FW update ioctl cmds */
#define ZYNQ_FW_PADDING 0x00000000
#define ZYNQ_FW_MSG_SZ 16
typedef struct ioc_zynq_fw_upload {
/*
* image data size must be multiple of 4 as each polling transfer is in
* 16-byte, so padding the data if needed.
*/
unsigned int *ioc_zynq_fw_data;
unsigned int ioc_zynq_fw_num;
unsigned int ioc_zynq_fw_done;
int ioc_zynq_fw_err;
} ioc_zynq_fw_upload_t;
#define ZYNQ_IOC_FW_IMAGE_UPLOAD_START \
_IOW(ZYNQ_IOC_MAGIC, IOC_FW_IMAGE_UPLOAD_START, unsigned long)
#define ZYNQ_IOC_FW_IMAGE_UPLOAD \
_IOW(ZYNQ_IOC_MAGIC, IOC_FW_IMAGE_UPLOAD, ioc_zynq_fw_upload_t *)
#define ZYNQ_IOC_FW_PL_UPDATE \
_IOW(ZYNQ_IOC_MAGIC, IOC_FW_PL_UPDATE, unsigned long)
#define ZYNQ_IOC_FW_PS_UPDATE \
_IOW(ZYNQ_IOC_MAGIC, IOC_FW_PS_UPDATE, unsigned long)
#define ZYNQ_IOC_FW_GET_VER _IOW(ZYNQ_IOC_MAGIC, IOC_FW_GET_VER, unsigned int *)
/* CAN channel ioctl cmds */
#define ZYNQ_IOC_CAN_TX_TIMEOUT_SET \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_TX_TIMEOUT_SET, unsigned long)
#define ZYNQ_IOC_CAN_RX_TIMEOUT_SET \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_RX_TIMEOUT_SET, unsigned long)
#define ZYNQ_IOC_CAN_DEV_START \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_DEV_START, unsigned long)
#define ZYNQ_IOC_CAN_DEV_STOP \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_DEV_STOP, unsigned long)
#define ZYNQ_IOC_CAN_DEV_RESET \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_DEV_RESET, unsigned long)
#define ZYNQ_IOC_CAN_ID_ADD _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_ID_ADD, unsigned long)
#define ZYNQ_IOC_CAN_ID_DEL _IOW(ZYNQ_IOC_MAGIC, IOC_CAN_ID_DEL, unsigned long)
#define ZYNQ_IOC_CAN_BAUDRATE_SET \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_BAUDRATE_SET, unsigned long)
#define ZYNQ_IOC_CAN_BAUDRATE_GET \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_BAUDRATE_GET, unsigned long)
#define ZYNQ_IOC_CAN_LOOPBACK_SET \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_LOOPBACK_SET, unsigned long)
#define ZYNQ_IOC_CAN_LOOPBACK_UNSET \
_IOW(ZYNQ_IOC_MAGIC, IOC_CAN_LOOPBACK_UNSET, unsigned long)
#define ZYNQ_IOC_CAN_RECV _IOWR(ZYNQ_IOC_MAGIC, IOC_CAN_RECV, ioc_bcan_msg_t *)
#define ZYNQ_IOC_CAN_SEND _IOWR(ZYNQ_IOC_MAGIC, IOC_CAN_SEND, ioc_bcan_msg_t *)
#define ZYNQ_IOC_CAN_SEND_HIPRI \
_IOWR(ZYNQ_IOC_MAGIC, IOC_CAN_SEND_HIPRI, ioc_bcan_msg_t *)
#define ZYNQ_IOC_CAN_GET_STATUS_ERR \
_IOR(ZYNQ_IOC_MAGIC, IOC_CAN_GET_STATUS_ERR, ioc_bcan_status_err_t *)
/* register read/write ioctl cmds */
typedef struct ioc_zynq_reg_acc {
unsigned int reg_bar;
unsigned int reg_offset;
unsigned int reg_data;
} ioc_zynq_reg_acc_t;
/* I2C ID definitions */
#define ZYNQ_I2C_ID_JANUS 0x5c
#define ZYNQ_I2C_ID_MAX 0x7f /* 7-bit */
typedef struct ioc_zynq_i2c_acc {
unsigned char i2c_id; /* 7-bit */
unsigned char i2c_addr;
unsigned char i2c_data;
} ioc_zynq_i2c_acc_t;
#define ZYNQ_IOC_REG_READ \
_IOR(ZYNQ_IOC_MAGIC, IOC_REG_READ, ioc_zynq_reg_acc_t *)
#define ZYNQ_IOC_REG_WRITE \
_IOW(ZYNQ_IOC_MAGIC, IOC_REG_WRITE, ioc_zynq_reg_acc_t *)
#define ZYNQ_IOC_REG_I2C_READ \
_IOR(ZYNQ_IOC_MAGIC, IOC_REG_I2C_READ, ioc_zynq_i2c_acc_t *)
#define ZYNQ_IOC_REG_I2C_WRITE \
_IOW(ZYNQ_IOC_MAGIC, IOC_REG_I2C_WRITE, ioc_zynq_i2c_acc_t *)
/* wait for GPS/PPS status change event notification */
#define ZYNQ_IOC_REG_GPSPPS_EVENT_WAIT \
_IOW(ZYNQ_IOC_MAGIC, IOC_REG_GPSPPS_EVENT_WAIT, unsigned long)
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/hermes_can/hermes_can_client_test.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/drivers/canbus/can_client/hermes_can/hermes_can_client.h"
#include "gtest/gtest.h"
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
using apollo::common::ErrorCode;
TEST(HermesCanClient, init) {
CANCardParameter param;
param.set_brand(CANCardParameter::HERMES_CAN);
param.set_channel_id(CANCardParameter::CHANNEL_ID_ZERO);
HermesCanClient hermes_can;
EXPECT_TRUE(hermes_can.Init(param));
EXPECT_EQ(hermes_can.Start(), ErrorCode::CAN_CLIENT_ERROR_BASE);
// EXPECT_EQ(hermes_can.Start(), ErrorCode::OK);
hermes_can.Stop();
}
TEST(HermesCanClient, send) {
CANCardParameter param;
param.set_brand(CANCardParameter::HERMES_CAN);
param.set_channel_id(CANCardParameter::CHANNEL_ID_ONE);
std::unique_ptr<HermesCanClient> hermes_can =
std::unique_ptr<HermesCanClient>(new HermesCanClient());
EXPECT_TRUE(hermes_can.get()->Init(param));
// CanFrame can_frame[1];
std::vector<CanFrame> frames;
int32_t num = 0;
// CanFrame frame;
// frame.id = 0x60;
// frame.len = 8;
// frame.data[0] = 0;
EXPECT_EQ(hermes_can.get()->Send(frames, &num),
ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED);
// frames.push_back(frame);
// num = 1;
// EXPECT_EQ(hermes_can.get()->Start(), ErrorCode::OK);
// EXPECT_EQ(hermes_can.get()->Send(frames, &num), ErrorCode::OK);
frames.clear();
}
/*
TEST(HermesCanClient, receiver) {
CANCardParameter param;
param.set_brand(CANCardParameter::HERMES_CAN);
param.set_channel_id(CANCardParameter::CHANNEL_ID_ZERO);
HermesCanClient hermes_can;
EXPECT_TRUE(hermes_can.Init(param));
std::vector<CanFrame> frames;
int32_t num = 0;
CanFrame frame;
// frame.id = 0x60;
// frame.len = 8;
// frame.data[0] = 0;
// frames.push_back(frame);
// num = 1;
EXPECT_EQ(hermes_can.Start(), ErrorCode::OK);
EXPECT_EQ(hermes_can.Receive(&frames, &num), ErrorCode::OK);
}
*/
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
// int main(int argc, char **argv) {
// ::testing::InitGoogleTest(&argc, argv);
// int ret = RUN_ALL_TESTS();
// return ret;
// }
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/fake/fake_can_client_test.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/drivers/canbus/can_client/fake/fake_can_client.h"
#include <memory>
#include <sstream>
#include <string>
#include <thread>
#include "gtest/gtest.h"
#include "cyber/common/log.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
using apollo::common::ErrorCode;
class FakeCanClientTest : public ::testing::Test {
public:
static const int32_t FRAME_LEN = 10;
virtual void SetUp() {
send_time_ = 0;
recv_time_ = 0;
send_succ_count_ = 0;
recv_succ_count_ = 0;
send_err_count_ = 0;
recv_err_count_ = 0;
param_.set_brand(CANCardParameter::ESD_CAN);
param_.set_channel_id(CANCardParameter::CHANNEL_ID_ZERO);
send_client_ = std::unique_ptr<FakeCanClient>(new FakeCanClient());
send_client_->Init(param_);
send_client_->Start();
recv_client_ = std::unique_ptr<FakeCanClient>(new FakeCanClient());
recv_client_->Init(param_);
recv_client_->Start();
}
protected:
std::unique_ptr<FakeCanClient> send_client_;
std::unique_ptr<FakeCanClient> recv_client_;
int64_t send_time_ = 0;
int64_t recv_time_ = 0;
int32_t send_succ_count_ = 0;
int32_t recv_succ_count_ = 0;
int32_t send_err_count_ = 0;
int32_t recv_err_count_ = 0;
std::stringstream recv_ss_;
CANCardParameter param_;
};
TEST_F(FakeCanClientTest, SendMessage) {
std::vector<CanFrame> frames;
frames.resize(FRAME_LEN);
for (int32_t i = 0; i < FRAME_LEN; ++i) {
frames[i].id = 1 & 0x3FF;
frames[i].len = 8;
frames[i].data[7] = 1 % 256;
for (uint8_t j = 0; j < 7; ++j) {
frames[i].data[j] = j;
}
}
int32_t frame_num = FRAME_LEN;
auto ret = send_client_->Send(frames, &frame_num);
EXPECT_EQ(ret, ErrorCode::OK);
EXPECT_EQ(send_client_->GetErrorString(0), "");
send_client_->Stop();
}
TEST_F(FakeCanClientTest, ReceiveMessage) {
std::vector<CanFrame> buf;
int32_t frame_num = FRAME_LEN;
auto ret = recv_client_->Receive(&buf, &frame_num);
EXPECT_EQ(ret, ErrorCode::OK);
recv_client_->Stop();
}
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/fake/fake_can_client.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/drivers/canbus/can_client/fake/fake_can_client.h"
#include <cstring>
#include <thread>
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
using apollo::common::ErrorCode;
bool FakeCanClient::Init(const CANCardParameter ¶m) { return true; }
ErrorCode FakeCanClient::Start() { return ErrorCode::OK; }
void FakeCanClient::Stop() {}
ErrorCode FakeCanClient::Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num) {
if (frame_num == nullptr) {
AERROR << "frame_num pointer is null";
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
if (static_cast<size_t>(*frame_num) != frames.size()) {
AERROR << "frame num is incorrect.";
return ErrorCode::CAN_CLIENT_ERROR_FRAME_NUM;
}
for (size_t i = 0; i < frames.size(); ++i) {
ADEBUG << "send frame i:" << i;
ADEBUG << frames[i].CanFrameString();
frame_info_ << frames[i].CanFrameString();
}
++send_counter_;
return ErrorCode::OK;
}
ErrorCode FakeCanClient::Receive(std::vector<CanFrame> *const frames,
int32_t *const frame_num) {
if (frame_num == nullptr || frames == nullptr) {
AERROR << "frames or frame_num pointer is null";
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
frames->resize(*frame_num);
const int MOCK_LEN = 8;
for (size_t i = 0; i < frames->size(); ++i) {
for (int j = 0; j < MOCK_LEN; ++j) {
(*frames)[i].data[j] = static_cast<uint8_t>(j);
}
(*frames)[i].id = static_cast<uint32_t>(i);
(*frames)[i].len = MOCK_LEN;
ADEBUG << (*frames)[i].CanFrameString() << "frame_num[" << i << "]";
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
++recv_counter_;
return ErrorCode::OK;
}
std::string FakeCanClient::GetErrorString(const int32_t /*status*/) {
return "";
}
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/fake/fake_can_client.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
* @brief Defines the FakeCanClient class which inherites CanClient.
*/
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/drivers/canbus/can_client/can_client.h"
/**
* @namespace apollo::drivers::canbus::can
* @brief apollo::drivers::canbus::can
*/
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
/**
* @class FakeCanClient
* @brief The class which defines a fake CAN client which inherits CanClient.
* This fake CAN client is used for testing.
*/
class FakeCanClient : public CanClient {
public:
/**
* @brief Initialize the fake CAN client by specified CAN card parameters.
* @param parameter CAN card parameters to initialize the CAN client.
* @return If the initialization is successful.
*/
bool Init(const CANCardParameter ¶m) override;
/**
* @brief Destructor
*/
virtual ~FakeCanClient() = default;
/**
* @brief Start the fake CAN client.
* @return The status of the start action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Start() override;
/**
* @brief Stop the fake CAN client.
*/
void Stop() override;
/**
* @brief Send messages
* @param frames The messages to send.
* @param frame_num The amount of messages to send.
* @return The status of the sending action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num) override;
/**
* @brief Receive messages
* @param frames The messages to receive.
* @param frame_num The amount of messages to receive.
* @return The status of the receiving action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Receive(std::vector<CanFrame> *frames,
int32_t *const frame_num) override;
/**
* @brief Get the error string.
* @param status The status to get the error string.
*/
std::string GetErrorString(const int32_t status) override;
private:
int32_t send_counter_ = 0;
int32_t recv_counter_ = 0;
std::stringstream frame_info_;
};
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/fake/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "fake_can_client",
srcs = ["fake_can_client.cc"],
hdrs = ["fake_can_client.h"],
deps = [
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/drivers/canbus/can_client",
],
)
cc_test(
name = "fake_can_client_test",
size = "small",
srcs = ["fake_can_client_test.cc"],
deps = [
"//cyber",
"//modules/drivers/canbus/can_client/fake:fake_can_client",
"//modules/drivers/canbus/common:canbus_common",
"@com_google_googletest//:gtest_main",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/socket/socket_can_client_raw_test.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/drivers/canbus/can_client/socket/socket_can_client_raw.h"
#include <vector>
#include "gtest/gtest.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
using apollo::common::ErrorCode;
TEST(SocketCanClientRawTest, simple_test) {
CANCardParameter param;
param.set_brand(CANCardParameter::SOCKET_CAN_RAW);
param.set_channel_id(CANCardParameter::CHANNEL_ID_ZERO);
SocketCanClientRaw socket_can_client;
EXPECT_TRUE(socket_can_client.Init(param));
EXPECT_EQ(socket_can_client.Start(), ErrorCode::CAN_CLIENT_ERROR_BASE);
std::vector<CanFrame> frames;
int32_t num = 0;
EXPECT_EQ(socket_can_client.Send(frames, &num),
ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED);
EXPECT_EQ(socket_can_client.Receive(&frames, &num),
ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED);
CanFrame can_frame;
frames.push_back(can_frame);
EXPECT_EQ(socket_can_client.SendSingleFrame(frames),
ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED);
socket_can_client.Stop();
}
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/socket/socket_can_client_raw.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
* @brief Defines the SocketCanClientRaw class which inherits CanClient.
*/
#pragma once
#include <unistd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <linux/can.h>
#include <linux/can/raw.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include "modules/common_msgs/basic_msgs/error_code.pb.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
#include "gflags/gflags.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
/**
* @namespace apollo::canbus::can
* @brief apollo::canbus::can
*/
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
/**
* @class SocketCanClientRaw
* @brief The class which defines an ESD CAN client which inherites CanClient.
*/
class SocketCanClientRaw : public CanClient {
public:
/**
* @brief Initialize the ESD CAN client by specified CAN card parameters.
* @param parameter CAN card parameters to initialize the CAN client.
* @return If the initialization is successful.
*/
bool Init(const CANCardParameter ¶meter) override;
/**
* @brief Destructor
*/
virtual ~SocketCanClientRaw();
/**
* @brief Start the ESD CAN client.
* @return The status of the start action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Start() override;
/**
* @brief Stop the ESD CAN client.
*/
void Stop() override;
/**
* @brief Send messages
* @param frames The messages to send.
* @param frame_num The amount of messages to send.
* @return The status of the sending action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num) override;
/**
* @brief Receive messages
* @param frames The messages to receive.
* @param frame_num The amount of messages to receive.
* @return The status of the receiving action which is defined by
* apollo::common::ErrorCode.
*/
apollo::common::ErrorCode Receive(std::vector<CanFrame> *const frames,
int32_t *const frame_num) override;
/**
* @brief Get the error string.
* @param status The status to get the error string.
*/
std::string GetErrorString(const int32_t status) override;
private:
int dev_handler_ = 0;
CANCardParameter::CANChannelId port_;
CANCardParameter::CANInterface interface_;
can_frame send_frames_[MAX_CAN_SEND_FRAME_LEN];
can_frame recv_frames_[MAX_CAN_RECV_FRAME_LEN];
};
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/socket/socket_can_client_raw.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.
*****************************************************************************/
/**
* @file socket_can_client.cc
* @brief the encapsulate call the api of socket can card according to
*can_client.h interface
**/
#include "modules/drivers/canbus/can_client/socket/socket_can_client_raw.h"
#include "absl/strings/str_cat.h"
namespace apollo {
namespace drivers {
namespace canbus {
namespace can {
#define CAN_ID_MASK 0x1FFFF800U // can_filter mask
using apollo::common::ErrorCode;
bool SocketCanClientRaw::Init(const CANCardParameter ¶meter) {
if (!parameter.has_channel_id()) {
AERROR << "Init CAN failed: parameter does not have channel id. The "
"parameter is "
<< parameter.DebugString();
return false;
}
port_ = parameter.channel_id();
interface_ = parameter.interface();
auto num_ports = parameter.num_ports();
if (port_ > static_cast<int32_t>(num_ports) || port_ < 0) {
AERROR << "Can port number [" << port_ << "] is out of range [0, "
<< num_ports << ") !";
return false;
}
return true;
}
SocketCanClientRaw::~SocketCanClientRaw() {
if (dev_handler_) {
Stop();
}
}
ErrorCode SocketCanClientRaw::Start() {
if (is_started_) {
return ErrorCode::OK;
}
struct sockaddr_can addr;
struct ifreq ifr;
// open device
// guss net is the device minor number, if one card is 0,1
// if more than one card, when install driver u can specify the minior id
// int32_t ret = canOpen(net, pCtx->mode, txbufsize, rxbufsize, 0, 0,
// &dev_handler_);
dev_handler_ = socket(PF_CAN, SOCK_RAW, CAN_RAW);
if (dev_handler_ < 0) {
AERROR << "open device error code [" << dev_handler_ << "]: ";
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
// init config and state
int ret;
// 1. for non virtual busses, set receive message_id filter, ie white list
if (interface_ != CANCardParameter::VIRTUAL) {
// set a scope for each EID instead of a single filter rule for each EID
struct can_filter filter[1];
filter[0].can_id = 0x000;
filter[0].can_mask = CAN_ID_MASK;
ret = setsockopt(dev_handler_, SOL_CAN_RAW, CAN_RAW_FILTER, &filter,
sizeof(filter));
if (ret < 0) {
AERROR << "add receive msg id filter error code: " << ret;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
}
// 2. enable reception of can frames.
int enable = 1;
ret = ::setsockopt(dev_handler_, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &enable,
sizeof(enable));
if (ret < 0) {
AERROR << "enable reception of can frame error code: " << ret;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
std::string interface_prefix;
if (interface_ == CANCardParameter::VIRTUAL) {
interface_prefix = "vcan";
} else if (interface_ == CANCardParameter::SLCAN) {
interface_prefix = "slcan";
} else { // default: CANCardParameter::NATIVE
interface_prefix = "can";
}
const std::string can_name = absl::StrCat(interface_prefix, port_);
std::strncpy(ifr.ifr_name, can_name.c_str(), IFNAMSIZ);
if (ioctl(dev_handler_, SIOCGIFINDEX, &ifr) < 0) {
AERROR << "ioctl error";
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
// bind socket to network interface
addr.can_family = AF_CAN;
addr.can_ifindex = ifr.ifr_ifindex;
ret = ::bind(dev_handler_, reinterpret_cast<struct sockaddr *>(&addr),
sizeof(addr));
if (ret < 0) {
AERROR << "bind socket to network interface error code: " << ret;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
is_started_ = true;
return ErrorCode::OK;
}
void SocketCanClientRaw::Stop() {
if (is_started_) {
is_started_ = false;
int ret = close(dev_handler_);
if (ret < 0) {
AERROR << "close error code:" << ret << ", " << GetErrorString(ret);
} else {
AINFO << "close socket can ok. port:" << port_;
}
}
}
// Synchronous transmission of CAN messages
ErrorCode SocketCanClientRaw::Send(const std::vector<CanFrame> &frames,
int32_t *const frame_num) {
CHECK_NOTNULL(frame_num);
CHECK_EQ(frames.size(), static_cast<size_t>(*frame_num));
if (!is_started_) {
AERROR << "Nvidia can client has not been initiated! Please init first!";
return ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED;
}
for (size_t i = 0; i < frames.size() && i < MAX_CAN_SEND_FRAME_LEN; ++i) {
if (frames[i].len > CANBUS_MESSAGE_LENGTH || frames[i].len < 0) {
AERROR << "frames[" << i << "].len = " << frames[i].len
<< ", which is not equal to can message data length ("
<< CANBUS_MESSAGE_LENGTH << ").";
return ErrorCode::CAN_CLIENT_ERROR_SEND_FAILED;
}
send_frames_[i].can_id = frames[i].id;
send_frames_[i].can_dlc = frames[i].len;
std::memcpy(send_frames_[i].data, frames[i].data, frames[i].len);
// Synchronous transmission of CAN messages
int ret = static_cast<int>(
write(dev_handler_, &send_frames_[i], sizeof(send_frames_[i])));
if (ret <= 0) {
AERROR << "send message failed, error code: " << ret;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
}
return ErrorCode::OK;
}
// buf size must be 8 bytes, every time, we receive only one frame
ErrorCode SocketCanClientRaw::Receive(std::vector<CanFrame> *const frames,
int32_t *const frame_num) {
if (!is_started_) {
AERROR << "Nvidia can client is not init! Please init first!";
return ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED;
}
if (*frame_num > MAX_CAN_RECV_FRAME_LEN || *frame_num < 0) {
AERROR << "recv can frame num not in range[0, " << MAX_CAN_RECV_FRAME_LEN
<< "], frame_num:" << *frame_num;
// TODO(Authors): check the difference of returning frame_num/error_code
return ErrorCode::CAN_CLIENT_ERROR_FRAME_NUM;
}
for (int32_t i = 0; i < *frame_num && i < MAX_CAN_RECV_FRAME_LEN; ++i) {
CanFrame cf;
auto ret = read(dev_handler_, &recv_frames_[i], sizeof(recv_frames_[i]));
if (ret < 0) {
AERROR << "receive message failed, error code: " << ret;
return ErrorCode::CAN_CLIENT_ERROR_BASE;
}
if (recv_frames_[i].can_dlc > CANBUS_MESSAGE_LENGTH ||
recv_frames_[i].can_dlc < 0) {
AERROR << "recv_frames_[" << i
<< "].can_dlc = " << recv_frames_[i].can_dlc
<< ", which is not equal to can message data length ("
<< CANBUS_MESSAGE_LENGTH << ").";
return ErrorCode::CAN_CLIENT_ERROR_RECV_FAILED;
}
cf.id = recv_frames_[i].can_id;
cf.len = recv_frames_[i].can_dlc;
std::memcpy(cf.data, recv_frames_[i].data, recv_frames_[i].can_dlc);
frames->push_back(cf);
}
return ErrorCode::OK;
}
std::string SocketCanClientRaw::GetErrorString(const int32_t /*status*/) {
return "";
}
} // namespace can
} // namespace canbus
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client
|
apollo_public_repos/apollo/modules/drivers/canbus/can_client/socket/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "socket_can_client_raw",
srcs = ["socket_can_client_raw.cc"],
hdrs = ["socket_can_client_raw.h"],
deps = [
"//modules/common_msgs/basic_msgs:error_code_cc_proto",
"//modules/drivers/canbus/can_client",
],
)
cc_test(
name = "socket_can_client_raw_test",
size = "small",
srcs = ["socket_can_client_raw_test.cc"],
deps = [
"//cyber",
"//modules/drivers/canbus/can_client/socket:socket_can_client_raw",
"//modules/drivers/canbus/common:canbus_common",
"@com_google_googletest//:gtest_main",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers
|
apollo_public_repos/apollo/modules/drivers/radar/BUILD
|
load("//tools/install:install.bzl", "install")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
deps = [
"//modules/drivers/radar/conti_radar:install",
"//modules/drivers/radar/racobit_radar:install",
"//modules/drivers/radar/ultrasonic_radar:install",
],
)
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_canbus_component.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/drivers/radar/ultrasonic_radar/ultrasonic_radar_canbus_component.h"
#include "modules/common/adapters/adapter_gflags.h"
namespace apollo {
namespace drivers {
namespace ultrasonic_radar {
UltrasonicRadarCanbusComponent::UltrasonicRadarCanbusComponent() {
writer_ = node_->CreateWriter<Ultrasonic>(FLAGS_ultrasonic_radar_topic);
}
bool UltrasonicRadarCanbusComponent::Init() {
return utralsonic_radar_canbus_.Init(ConfigFilePath(), writer_).ok() &&
utralsonic_radar_canbus_.Start().ok();
}
} // namespace ultrasonic_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_canbus.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/drivers/radar/ultrasonic_radar/ultrasonic_radar_canbus.h"
#include "cyber/common/file.h"
#include "modules/common/util/util.h"
#include "modules/common_msgs/sensor_msgs/ultrasonic_radar.pb.h"
#include "modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_message_manager.h"
/**
* @namespace apollo::drivers::ultrasonic_radar
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
namespace ultrasonic_radar {
UltrasonicRadarCanbus::UltrasonicRadarCanbus()
: monitor_logger_buffer_(
common::monitor::MonitorMessageItem::ULTRASONIC_RADAR) {}
UltrasonicRadarCanbus::~UltrasonicRadarCanbus() {
can_receiver_.Stop();
can_client_->Stop();
}
std::string UltrasonicRadarCanbus::Name() const { return "ultrasonic_radar"; }
apollo::common::Status UltrasonicRadarCanbus::Init(
const std::string& config_path,
const std::shared_ptr<::apollo::cyber::Writer<Ultrasonic>>& writer) {
if (!cyber::common::GetProtoFromFile(config_path, &ultrasonic_radar_conf_)) {
return OnError("Unable to load canbus conf file: " + config_path);
}
AINFO << "The canbus conf file is loaded: " << config_path;
ADEBUG << "Canbus_conf:" << ultrasonic_radar_conf_.ShortDebugString();
// Init can client
auto can_factory = CanClientFactory::Instance();
can_factory->RegisterCanClients();
can_client_ = can_factory->CreateCANClient(
ultrasonic_radar_conf_.can_conf().can_card_parameter());
if (!can_client_) {
return OnError("Failed to create can client.");
}
AINFO << "Can client is successfully created.";
sensor_message_manager_ = std::unique_ptr<UltrasonicRadarMessageManager>(
new UltrasonicRadarMessageManager(ultrasonic_radar_conf_.entrance_num(),
writer));
if (sensor_message_manager_ == nullptr) {
return OnError("Failed to create message manager.");
}
sensor_message_manager_->set_can_client(can_client_);
AINFO << "Sensor message manager is successfully created.";
bool enable_receiver_log =
ultrasonic_radar_conf_.can_conf().enable_receiver_log();
if (can_receiver_.Init(can_client_.get(), sensor_message_manager_.get(),
enable_receiver_log) != ErrorCode::OK) {
return OnError("Failed to init can receiver.");
}
AINFO << "The can receiver is successfully initialized.";
return Status::OK();
}
apollo::common::Status UltrasonicRadarCanbus::Start() {
// 1. init and start the can card hardware
if (can_client_->Start() != ErrorCode::OK) {
return OnError("Failed to start can client");
}
AINFO << "Can client is started.";
// 2. start receive first then send
if (can_receiver_.Start() != ErrorCode::OK) {
return OnError("Failed to start can receiver.");
}
AINFO << "Can receiver is started.";
// last step: publish monitor messages
monitor_logger_buffer_.INFO("Canbus is started.");
return Status::OK();
}
// Send the error to monitor and return it
Status UltrasonicRadarCanbus::OnError(const std::string& error_msg) {
monitor_logger_buffer_.ERROR(error_msg);
return Status(ErrorCode::CANBUS_ERROR, error_msg);
}
} // namespace ultrasonic_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_canbus_component.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 <memory>
#include "modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_canbus.h"
/**
* @namespace apollo::drivers
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
namespace ultrasonic_radar {
class UltrasonicRadarCanbusComponent : public apollo::cyber::Component<> {
public:
UltrasonicRadarCanbusComponent();
~UltrasonicRadarCanbusComponent() = default;
bool Init() override;
private:
UltrasonicRadarCanbus utralsonic_radar_canbus_;
std::shared_ptr<::apollo::cyber::Writer<Ultrasonic>> writer_;
};
CYBER_REGISTER_COMPONENT(UltrasonicRadarCanbusComponent)
} // namespace ultrasonic_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/README_cn.md
|
## ultrasonic_radar
该驱动基于Apollo cyber开发,支持ultrasonic ARS。
### 运行
该驱动需要在apollo docker环境中运行。
```bash
# in docker
cd /apollo
source scripts/apollo_base.sh
# 启动
./scripts/ultrasonic_radar.sh start
# 停止
./scripts/ultrasonic_radar.sh stop
```
### Topic
**topic name**: /apollo/sensor/ultrasonic_radar
**data type**: apollo::drivers::Ultrasonic
**channel ID**: CHANNEL_ID_THREE
**proto file**: [modules/drivers/proto/ultrasonic_radar.proto](https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/proto/ultrasonic_radar.proto)
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_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.
*****************************************************************************/
/**
* @file ultrasonic_radar_message_manager.h
* @brief The class of UltrasonicRadarMessageManager
*/
#pragma once
#include <memory>
#include "cyber/cyber.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
#include "modules/common_msgs/sensor_msgs/ultrasonic_radar.pb.h"
#include "modules/drivers/canbus/sensor_gflags.h"
namespace apollo {
namespace drivers {
namespace ultrasonic_radar {
using ::apollo::drivers::canbus::MessageManager;
using ::apollo::drivers::canbus::ProtocolData;
using Time = ::apollo::cyber::Time;
using micros = std::chrono::microseconds;
using ::apollo::common::ErrorCode;
using apollo::drivers::canbus::CanClient;
using apollo::drivers::canbus::SenderMessage;
class UltrasonicRadarMessageManager : public MessageManager<Ultrasonic> {
public:
UltrasonicRadarMessageManager(
const int entrance_num,
const std::shared_ptr<::apollo::cyber::Writer<Ultrasonic>> &writer);
virtual ~UltrasonicRadarMessageManager() = default;
void Parse(const uint32_t message_id, const uint8_t *data, int32_t length);
void set_can_client(std::shared_ptr<CanClient> can_client);
private:
int entrance_num_ = 0;
std::shared_ptr<cyber::Writer<Ultrasonic>> ultrasonic_radar_writer_;
std::shared_ptr<CanClient> can_client_;
};
} // namespace ultrasonic_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_canbus.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.
*****************************************************************************/
/**
* @file
*/
#pragma once
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "cyber/common/macros.h"
#include "cyber/time/time.h"
#include "modules/common/monitor_log/monitor_log_buffer.h"
#include "modules/common/status/status.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_client/can_client_factory.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"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
#include "modules/drivers/canbus/proto/sensor_canbus_conf.pb.h"
#include "modules/drivers/canbus/sensor_gflags.h"
#include "modules/common_msgs/sensor_msgs/ultrasonic_radar.pb.h"
#include "modules/drivers/radar/ultrasonic_radar/proto/ultrasonic_radar_conf.pb.h"
#include "modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_message_manager.h"
/**
* @namespace apollo::drivers
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
namespace ultrasonic_radar {
/**
* @class UltrasonicRadarCanbus
*
* @brief template of canbus-based sensor module main class (e.g.,
* ultrasonic_radar).
*/
using apollo::common::ErrorCode;
using apollo::common::Status;
using apollo::common::monitor::MonitorMessageItem;
using apollo::cyber::Time;
using apollo::drivers::canbus::CanClient;
using apollo::drivers::canbus::CanClientFactory;
using apollo::drivers::canbus::CanReceiver;
using apollo::drivers::canbus::SenderMessage;
using apollo::drivers::canbus::SensorCanbusConf;
class UltrasonicRadarCanbus {
public:
UltrasonicRadarCanbus();
~UltrasonicRadarCanbus();
/**
* @brief obtain module name
* @return module name
*/
std::string Name() const;
/**
* @brief module initialization function
* @return initialization status
*/
apollo::common::Status Init(
const std::string& config_path,
const std::shared_ptr<::apollo::cyber::Writer<Ultrasonic>>& writer);
/**
* @brief module start function
* @return start status
*/
apollo::common::Status Start();
private:
Status OnError(const std::string& error_msg);
void RegisterCanClients();
UltrasonicRadarConf ultrasonic_radar_conf_;
std::shared_ptr<CanClient> can_client_;
CanReceiver<Ultrasonic> can_receiver_;
std::unique_ptr<UltrasonicRadarMessageManager> sensor_message_manager_;
int64_t last_timestamp_ = 0;
apollo::common::monitor::MonitorLogBuffer monitor_logger_buffer_;
};
} // namespace ultrasonic_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//tools/install:install.bzl", "install")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
data_dest = "drivers/addition_data/ultrasonic_radar",
library_dest = "drivers/lib/racobit_radar",
data = [
":runtime_data",
],
targets = [
":libultrasonic_radar_canbus_component.so",
],
)
filegroup(
name = "runtime_data",
srcs = glob([
"conf/*.txt",
"conf/*.conf",
"dag/*.dag",
"launch/*.launch",
]),
)
cc_library(
name = "ultrasonic_radar_message_manager",
srcs = ["ultrasonic_radar_message_manager.cc"],
hdrs = ["ultrasonic_radar_message_manager.h"],
deps = [
"//modules/common_msgs/basic_msgs:header_cc_proto",
"//modules/common/util:util_tool",
"//modules/drivers/canbus:sensor_gflags",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_sender",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/common_msgs/sensor_msgs:ultrasonic_radar_cc_proto",
],
)
# cc_test(
# name = "ultrasonic_radar_message_manager_test",
# size = "small",
# srcs = ["ultrasonic_radar_message_manager_test.cc"],
# deps = [
# "ultrasonic_radar_message_manager",
# "@com_google_googletest//:gtest_main",
# ],
# )
cc_library(
name = "ultrasonic_radar_canbus_lib",
srcs = ["ultrasonic_radar_canbus.cc"],
hdrs = ["ultrasonic_radar_canbus.h"],
deps = [
":ultrasonic_radar_message_manager",
"//modules/common/monitor_log",
"//modules/common/status",
"//modules/drivers/canbus:sensor_gflags",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_receiver",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/proto:sensor_canbus_conf_cc_proto",
"//modules/drivers/radar/ultrasonic_radar/proto:ultrasonic_radar_conf_cc_proto",
],
)
# cc_test(
# name = "ultrasonic_radar_canbus_test",
# size = "small",
# srcs = ["ultrasonic_radar_canbus_test.cc"],
# deps = [
# ":ultrasonic_radar_canbus_lib",
# ":ultrasonic_radar_message_manager",
# "@com_google_googletest//:gtest_main",
# ],
# )
cc_library(
name = "ultrasonic_radar_canbus_component_lib",
srcs = ["ultrasonic_radar_canbus_component.cc"],
hdrs = ["ultrasonic_radar_canbus_component.h"],
copts = ['-DMODULE_NAME=\\"ultrasonic_radar_canbus\\"'],
alwayslink = True,
deps = [
":ultrasonic_radar_canbus_lib",
"//modules/common/adapters:adapter_gflags",
"//modules/common_msgs/sensor_msgs:ultrasonic_radar_cc_proto",
],
)
cc_binary(
name = "libultrasonic_radar_canbus_component.so",
linkshared = True,
linkstatic = True,
deps = [":ultrasonic_radar_canbus_component_lib"],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_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.
*****************************************************************************/
/**
* @file ultrasonic_radar_message_manager.h
* @brief The class of UltrasonicRadarMessageManager
*/
#include "modules/drivers/radar/ultrasonic_radar/ultrasonic_radar_message_manager.h"
#include "modules/common/util/message_util.h"
namespace apollo {
namespace drivers {
namespace ultrasonic_radar {
UltrasonicRadarMessageManager::UltrasonicRadarMessageManager(
const int entrance_num,
const std::shared_ptr<::apollo::cyber::Writer<Ultrasonic>> &writer)
: entrance_num_(entrance_num), ultrasonic_radar_writer_(writer) {
sensor_data_.mutable_ranges()->Resize(entrance_num_, 0.0);
}
void UltrasonicRadarMessageManager::set_can_client(
std::shared_ptr<CanClient> can_client) {
can_client_ = can_client;
}
void UltrasonicRadarMessageManager::Parse(const uint32_t message_id,
const uint8_t *data, int32_t length) {
if (message_id == 0x301) {
sensor_data_.set_ranges(0, data[1]);
sensor_data_.set_ranges(1, data[2]);
sensor_data_.set_ranges(2, data[3]);
sensor_data_.set_ranges(3, data[4]);
} else if (message_id == 0x302) {
sensor_data_.set_ranges(4, data[1]);
sensor_data_.set_ranges(5, data[2]);
sensor_data_.set_ranges(6, data[3]);
sensor_data_.set_ranges(7, data[4]);
} else if (message_id == 0x303) {
sensor_data_.set_ranges(8, data[1]);
sensor_data_.set_ranges(9, data[2]);
} else if (message_id == 0x304) {
sensor_data_.set_ranges(10, data[1]);
sensor_data_.set_ranges(11, data[2]);
common::util::FillHeader("ultrasonic_radar", &sensor_data_);
ultrasonic_radar_writer_->Write(sensor_data_);
}
received_ids_.insert(message_id);
// check if need to check period
const auto it = check_ids_.find(message_id);
if (it != check_ids_.end()) {
const int64_t time = Time::Now().ToMicrosecond();
it->second.real_period = time - it->second.last_time;
// if period 1.5 large than base period, inc error_count
const double period_multiplier = 1.5;
if (it->second.real_period >
(static_cast<double>(it->second.period) * period_multiplier)) {
it->second.error_count += 1;
} else {
it->second.error_count = 0;
}
it->second.last_time = time;
}
}
} // namespace ultrasonic_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/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 = "ultrasonic_radar_conf_cc_proto",
deps = [
":ultrasonic_radar_conf_proto",
],
)
proto_library(
name = "ultrasonic_radar_conf_proto",
srcs = ["ultrasonic_radar_conf.proto"],
deps = [
"//modules/common_msgs/drivers_msgs:can_card_parameter_proto",
],
)
py_proto_library(
name = "ultrasonic_radar_conf_py_pb2",
deps = [
":ultrasonic_radar_conf_proto",
"//modules/common_msgs/drivers_msgs:can_card_parameter_py_pb2",
],
)
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/proto/ultrasonic_radar_conf.proto
|
syntax = "proto2";
package apollo.drivers.ultrasonic_radar;
import "modules/common_msgs/drivers_msgs/can_card_parameter.proto";
message CanConf {
optional apollo.drivers.canbus.CANCardParameter can_card_parameter = 1;
optional bool enable_debug_mode = 2 [default = false];
optional bool enable_receiver_log = 3 [default = false];
optional bool enable_sender_log = 4 [default = false];
}
message UltrasonicRadarConf {
optional CanConf can_conf = 1;
optional int32 entrance_num = 2;
}
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/launch/ultrasonic_radar.launch
|
<cyber>
<module>
<name>ultrasonic_radar</name>
<dag_conf>/apollo/modules/drivers/radar/ultrasonic_radar/dag/ultrasonic_radar.dag</dag_conf>
<process_name></process_name>
</module>
</cyber>
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/dag/ultrasonic_radar.dag
|
module_config {
module_library: "/apollo/bazel-bin/modules/drivers/radar/ultrasonic_radar/libultrasonic_radar_canbus_component.so"
components {
class_name: "UltrasonicRadarCanbusComponent"
config {
name: "ultrasonic_radar"
config_file_path: "/apollo/modules/drivers/radar/ultrasonic_radar/conf/ultrasonic_radar_conf.pb.txt"
}
}
}
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/conf/ultrasonic_radar.conf
|
--flagfile=modules/common/data/global_flagfile.txt
--alsologtostderr=1
--sensor_conf_file=modules/drivers/radar/ultrasonic_radar/conf/ultrasonic_radar_conf.pb.txt
--node_namespace=/apollo/drivers/ultrasonic_radar
--sensor_node_name=ultrasonic_radar
--canbus_driver_name=ultrasonic_radar
--entrance_num=12
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar
|
apollo_public_repos/apollo/modules/drivers/radar/ultrasonic_radar/conf/ultrasonic_radar_conf.pb.txt
|
can_conf {
can_card_parameter {
brand:ESD_CAN
type: PCI_CARD
channel_id: CHANNEL_ID_THREE
}
enable_debug_mode: false
enable_receiver_log: false
}
entrance_num: 12
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/racobit_radar_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.
*****************************************************************************/
/**
* @file racobit_radar_message_manager.h
* @brief The class of RacobitRadarMessageManager
*/
#pragma once
#include <memory>
#include "cyber/cyber.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
#include "modules/drivers/radar/racobit_radar/protocol/radar_config_200.h"
#include "modules/drivers/canbus/sensor_gflags.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using ::apollo::drivers::canbus::MessageManager;
using ::apollo::drivers::canbus::ProtocolData;
using Time = ::apollo::cyber::Time;
using micros = std::chrono::microseconds;
using ::apollo::common::ErrorCode;
using apollo::drivers::canbus::CanClient;
using apollo::drivers::canbus::SenderMessage;
using apollo::drivers::racobit_radar::RadarConfig200;
class RacobitRadarMessageManager : public MessageManager<RacobitRadar> {
public:
RacobitRadarMessageManager(
std::shared_ptr<cyber::Writer<RacobitRadar>> writer);
virtual ~RacobitRadarMessageManager() {}
void set_radar_conf(RadarConf radar_conf);
ProtocolData<RacobitRadar> *GetMutableProtocolDataById(
const uint32_t message_id);
void Parse(const uint32_t message_id, const uint8_t *data, int32_t length);
void set_can_client(std::shared_ptr<CanClient> can_client);
private:
bool is_configured_ = false;
RadarConfig200 radar_config_;
std::shared_ptr<CanClient> can_client_;
std::shared_ptr<cyber::Writer<RacobitRadar>> writer_;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/racobit_radar_canbus_component.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.
*****************************************************************************/
/**
* @file
*/
#include "modules/drivers/radar/racobit_radar/racobit_radar_canbus_component.h"
#include "cyber/common/file.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
#include "modules/drivers/radar/racobit_radar/racobit_radar_message_manager.h"
/**
* @namespace apollo::drivers::racobit_radar
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
namespace racobit_radar {
RacobitRadarCanbusComponent::RacobitRadarCanbusComponent()
: monitor_logger_buffer_(
common::monitor::MonitorMessageItem::RACOBIT_RADAR) {}
bool RacobitRadarCanbusComponent::Init() {
if (!GetProtoConfig(&racobit_radar_conf_)) {
return OnError("Unable to load canbus conf file: " + ConfigFilePath()).ok();
}
AINFO << "The canbus conf file is loaded: " << ConfigFilePath();
ADEBUG << "Canbus_conf:" << racobit_radar_conf_.ShortDebugString();
racobit_radar_writer_ =
node_->CreateWriter<RacobitRadar>(FLAGS_racobit_radar_topic);
if (!cyber::common::GetProtoFromFile(ConfigFilePath(),
&racobit_radar_conf_)) {
return OnError("Unable to load canbus conf file: " + ConfigFilePath()).ok();
}
AINFO << "The canbus conf file is loaded: " << ConfigFilePath();
ADEBUG << "Canbus_conf:" << racobit_radar_conf_.ShortDebugString();
auto can_factory = CanClientFactory::Instance();
can_factory->RegisterCanClients();
can_client_ = can_factory->CreateCANClient(
racobit_radar_conf_.can_conf().can_card_parameter());
if (!can_client_) {
return OnError("Failed to create can client.").ok();
}
AINFO << "Can client is successfully created.";
sensor_message_manager_ = std::unique_ptr<RacobitRadarMessageManager>(
new RacobitRadarMessageManager(racobit_radar_writer_));
if (sensor_message_manager_ == nullptr) {
return OnError("Failed to create message manager.").ok();
}
sensor_message_manager_->set_radar_conf(racobit_radar_conf_.radar_conf());
sensor_message_manager_->set_can_client(can_client_);
AINFO << "Sensor message manager is successfully created.";
if (can_receiver_.Init(
can_client_.get(), sensor_message_manager_.get(),
racobit_radar_conf_.can_conf().enable_receiver_log()) !=
ErrorCode::OK) {
return OnError("Failed to init can receiver.").ok();
}
AINFO << "The can receiver is successfully initialized.";
if (can_client_->Start() != ErrorCode::OK) {
return OnError("Failed to start can client").ok();
}
AINFO << "Can client is started.";
if (ConfigureRadar() != ErrorCode::OK) {
return OnError("Failed to configure radar.").ok();
}
AINFO << "The radar is successfully configured.";
if (can_receiver_.Start() != ErrorCode::OK) {
return OnError("Failed to start can receiver.").ok();
}
AINFO << "Can receiver is started.";
monitor_logger_buffer_.INFO("Canbus is started.");
return true;
}
apollo::common::ErrorCode RacobitRadarCanbusComponent::ConfigureRadar() {
RadarConfig200 radar_config;
radar_config.set_radar_conf(racobit_radar_conf_.radar_conf());
SenderMessage<RacobitRadar> sender_message(RadarConfig200::ID, &radar_config);
sender_message.Update();
return can_client_->SendSingleFrame({sender_message.CanFrame()});
}
RacobitRadarCanbusComponent::~RacobitRadarCanbusComponent() {
if (start_success_) {
can_receiver_.Stop();
can_client_->Stop();
}
}
Status RacobitRadarCanbusComponent::OnError(const std::string &error_msg) {
monitor_logger_buffer_.ERROR(error_msg);
return Status(ErrorCode::CANBUS_ERROR, error_msg);
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/racobit_radar_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.
*****************************************************************************/
/**
* @file racobit_radar_message_manager.h
* @brief The class of RacobitRadarMessageManager
*/
#include "modules/drivers/radar/racobit_radar/racobit_radar_message_manager.h"
#include <utility>
#include "modules/common/util/message_util.h"
#include "modules/drivers/radar/racobit_radar/protocol/cluster_general_info_701.h"
#include "modules/drivers/radar/racobit_radar/protocol/cluster_list_status_600.h"
#include "modules/drivers/radar/racobit_radar/protocol/cluster_quality_info_702.h"
#include "modules/drivers/radar/racobit_radar/protocol/object_extended_info_60d.h"
#include "modules/drivers/radar/racobit_radar/protocol/object_general_info_60b.h"
#include "modules/drivers/radar/racobit_radar/protocol/object_list_status_60a.h"
#include "modules/drivers/radar/racobit_radar/protocol/object_quality_info_60c.h"
#include "modules/drivers/radar/racobit_radar/protocol/radar_state_201.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
RacobitRadarMessageManager::RacobitRadarMessageManager(
std::shared_ptr<cyber::Writer<RacobitRadar>> writer)
: writer_(std::move(writer)) {
AddRecvProtocolData<RadarState201, true>();
AddRecvProtocolData<ClusterListStatus600, true>();
AddRecvProtocolData<ClusterGeneralInfo701, true>();
AddRecvProtocolData<ClusterQualityInfo702, true>();
AddRecvProtocolData<ObjectExtendedInfo60D, true>();
AddRecvProtocolData<ObjectGeneralInfo60B, true>();
AddRecvProtocolData<ObjectListStatus60A, true>();
AddRecvProtocolData<ObjectQualityInfo60C, true>();
}
void RacobitRadarMessageManager::set_radar_conf(RadarConf radar_conf) {
radar_config_.set_radar_conf(radar_conf);
}
void RacobitRadarMessageManager::set_can_client(
std::shared_ptr<CanClient> can_client) {
can_client_ = can_client;
}
ProtocolData<RacobitRadar>
*RacobitRadarMessageManager::GetMutableProtocolDataById(
const uint32_t message_id) {
uint32_t converted_message_id = message_id;
if (protocol_data_map_.find(converted_message_id) ==
protocol_data_map_.end()) {
ADEBUG << "Unable to get protocol data because of invalid message_id:"
<< message_id;
return nullptr;
}
return protocol_data_map_[converted_message_id];
}
void RacobitRadarMessageManager::Parse(const uint32_t message_id,
const uint8_t *data, int32_t length) {
ProtocolData<RacobitRadar> *sensor_protocol_data =
GetMutableProtocolDataById(message_id);
if (sensor_protocol_data == nullptr) {
return;
}
std::lock_guard<std::mutex> lock(sensor_data_mutex_);
if (!is_configured_ && message_id != RadarState201::ID) {
// read radar state message first
return;
}
common::util::FillHeader(FLAGS_sensor_node_name, &sensor_data_);
// trigger publishment
if (message_id == ClusterListStatus600::ID ||
message_id == ObjectListStatus60A::ID) {
ADEBUG << sensor_data_.ShortDebugString();
if (sensor_data_.contiobs_size() <=
sensor_data_.object_list_status().nof_objects()) {
// maybe lost an object_list_status msg
common::util::FillHeader("racobit_radar", &sensor_data_);
writer_->Write(sensor_data_);
}
sensor_data_.Clear();
// fill header when receive the general info message
}
sensor_protocol_data->Parse(data, length, &sensor_data_);
if (message_id == RadarState201::ID) {
ADEBUG << sensor_data_.ShortDebugString();
if (sensor_data_.radar_state().send_quality() ==
radar_config_.radar_conf().send_quality() &&
sensor_data_.radar_state().send_ext_info() ==
radar_config_.radar_conf().send_ext_info() &&
sensor_data_.radar_state().max_distance() ==
radar_config_.radar_conf().max_distance() &&
sensor_data_.radar_state().output_type() ==
radar_config_.radar_conf().output_type() &&
sensor_data_.radar_state().rcs_threshold() ==
radar_config_.radar_conf().rcs_threshold() &&
sensor_data_.radar_state().radar_power() ==
radar_config_.radar_conf().radar_power()) {
is_configured_ = true;
} else {
AINFO << "configure radar again";
SenderMessage<RacobitRadar> sender_message(RadarConfig200::ID,
&radar_config_);
sender_message.Update();
can_client_->SendSingleFrame({sender_message.CanFrame()});
}
}
received_ids_.insert(message_id);
// check if need to check period
const auto it = check_ids_.find(message_id);
if (it != check_ids_.end()) {
const int64_t time = Time::Now().ToMicrosecond();
it->second.real_period = time - it->second.last_time;
// if period 1.5 large than base period, inc error_count
const double period_multiplier = 1.5;
if (it->second.real_period >
(static_cast<double>(it->second.period) * period_multiplier)) {
it->second.error_count += 1;
} else {
it->second.error_count = 0;
}
it->second.last_time = time;
}
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/README_cn.md
|
## racobit_radar
该驱动基于Apollo cyber开发,支持racobit B0CH11。
### 配置
radar的默认配置: [conf/racobit_radar_conf.pb.txt](https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/radar/racobit_radar/conf/racobit_radar_conf.pb.txt)
radar启动时,会先根据上述配置文件,向can卡发送指令,对radar进行配置。当接收到的radar状态信息与用户配置信息一致时,才开始解析数据并发送消息。
### 运行
该驱动需要在apollo dock环境中运行。
```bash
# in docker
cd /apollo
source scripts/apollo_base.sh
# 启动
./scripts/racobit_radar.sh start
# 停止
./scripts/racobit_radar.sh stop
```
### Topic
**topic name**: /apollo/sensor/racobit_radar
**data type**: apollo::drivers::RacobitRadar
**channel ID**: CHANNEL_ID_ONE
**proto file**: [modules/drivers/proto/racobit_radar.proto](https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/proto/racobit_radar.proto)
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//tools/install:install.bzl", "install")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
data_dest = "drivers/addition_data/racobit_radar",
library_dest = "drivers/lib/racobit_radar",
data = [
":runtime_data",
],
targets = [
":libracobit_radar_canbus_component.so",
],
)
filegroup(
name = "runtime_data",
srcs = glob([
"conf/*.txt",
"conf/*.conf",
"dag/*.dag",
"launch/*.launch",
]),
)
cc_library(
name = "racobit_radar_message_manager",
srcs = ["racobit_radar_message_manager.cc"],
hdrs = ["racobit_radar_message_manager.h"],
deps = [
"//modules/common/util:util_tool",
"//modules/drivers/canbus:sensor_gflags",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_sender",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/common_msgs/sensor_msgs:racobit_radar_cc_proto",
"//modules/drivers/radar/racobit_radar/protocol:drivers_racobit_radar_protocol",
],
)
# cc_test(
# name = "racobit_radar_message_manager_test",
# size = "small",
# srcs = ["racobit_radar_message_manager_test.cc"],
# deps = [
# "racobit_radar_message_manager",
# "@com_google_googletest//:gtest_main",
# ],
# )
cc_library(
name = "racobit_radar_canbus_lib",
srcs = ["racobit_radar_canbus_component.cc"],
hdrs = ["racobit_radar_canbus_component.h"],
copts = ['-DMODULE_NAME=\\"racobit_radar_canbus\\"'],
alwayslink = True,
deps = [
":racobit_radar_message_manager",
"//cyber",
"//modules/common/adapters:adapter_gflags",
"//modules/common/monitor_log",
"//modules/common/status",
"//modules/drivers/canbus:sensor_gflags",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_receiver",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/proto:sensor_canbus_conf_cc_proto",
"//modules/drivers/radar/racobit_radar/protocol:drivers_racobit_radar_protocol",
],
)
cc_binary(
name = "libracobit_radar_canbus_component.so",
linkshared = True,
linkstatic = True,
deps = [":racobit_radar_canbus_lib"],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/racobit_radar_canbus_component.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.
*****************************************************************************/
/**
* @file
*/
#pragma once
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "cyber/cyber.h"
#include "cyber/time/time.h"
#include "modules/common/monitor_log/monitor_log_buffer.h"
#include "modules/common/status/status.h"
#include "modules/common/util/util.h"
#include "modules/drivers/canbus/can_client/can_client.h"
#include "modules/drivers/canbus/can_client/can_client_factory.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"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
#include "modules/drivers/canbus/proto/sensor_canbus_conf.pb.h"
#include "modules/drivers/canbus/sensor_gflags.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
#include "modules/drivers/radar/racobit_radar/protocol/radar_config_200.h"
#include "modules/drivers/radar/racobit_radar/racobit_radar_message_manager.h"
/**
* @namespace apollo::drivers
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
namespace racobit_radar {
/**
* @class RacobitRadarCanbus
*
* @brief template of canbus-based sensor module main class (e.g.,
* racobit_radar).
*/
using apollo::common::ErrorCode;
using apollo::common::Status;
using apollo::common::monitor::MonitorMessageItem;
using apollo::cyber::Time;
using apollo::drivers::canbus::CanClient;
using apollo::drivers::canbus::CanClientFactory;
using apollo::drivers::canbus::CanReceiver;
using apollo::drivers::canbus::SenderMessage;
using apollo::drivers::canbus::SensorCanbusConf;
class RacobitRadarCanbusComponent : public apollo::cyber::Component<> {
public:
// TODO(lizh): check whether we need a new msg item, say
// MonitorMessageItem::SENSORCANBUS
RacobitRadarCanbusComponent();
~RacobitRadarCanbusComponent();
/**
* @brief module initialization function
* @return initialization success(true) or not(false).
*/
bool Init() override;
private:
void RegisterCanClients();
apollo::common::ErrorCode ConfigureRadar();
Status OnError(const std::string &error_msg);
std::shared_ptr<CanClient> can_client_;
CanReceiver<RacobitRadar> can_receiver_;
std::unique_ptr<RacobitRadarMessageManager> sensor_message_manager_;
int64_t last_timestamp_ = 0;
apollo::common::monitor::MonitorLogBuffer monitor_logger_buffer_;
bool start_success_ = false;
// cyber
RacobitRadarConf racobit_radar_conf_;
std::shared_ptr<cyber::Writer<RacobitRadar>> racobit_radar_writer_;
};
CYBER_REGISTER_COMPONENT(RacobitRadarCanbusComponent)
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/proto/racobit_radar_conf.proto
|
syntax = "proto2";
package apollo.drivers.racobit_radar;
import "modules/common_msgs/sensor_msgs/racobit_radar.proto";
import "modules/common_msgs/drivers_msgs/can_card_parameter.proto";
message CanConf {
optional apollo.drivers.canbus.CANCardParameter can_card_parameter = 1;
optional bool enable_debug_mode = 2 [default = false];
optional bool enable_receiver_log = 3 [default = false];
optional bool enable_sender_log = 4 [default = false];
}
message RadarConf {
optional bool max_distance_valid = 1 [default = false];
optional bool sensor_id_valid = 2 [default = false];
optional bool radar_power_valid = 3 [default = false];
optional bool output_type_valid = 4 [default = true];
optional bool send_quality_valid = 5 [default = true];
optional bool send_ext_info_valid = 6 [default = true];
optional bool sort_index_valid = 7 [default = false];
optional bool store_in_nvm_valid = 8 [default = true];
optional bool ctrl_relay_valid = 9 [default = false];
optional bool rcs_threshold_valid = 10 [default = true];
optional uint32 max_distance = 11 [default = 248];
optional uint32 sensor_id = 12 [default = 0];
optional RacobitRadarState_201.OutputType output_type = 13 [default = OUTPUT_TYPE_OBJECTS];
optional uint32 radar_power = 14 [default = 0];
optional uint32 ctrl_relay = 15 [default = 0];
optional bool send_ext_info = 16 [default = true];
optional bool send_quality = 17 [default = true];
optional uint32 sort_index = 18 [default = 0];
optional uint32 store_in_nvm = 19 [default = 1];
optional RacobitRadarState_201.RcsThreshold rcs_threshold = 20 [default = RCS_THRESHOLD_STANDARD];
}
message RacobitRadarConf {
optional CanConf can_conf = 1;
optional RadarConf radar_conf = 2;
}
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/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 = "racobit_radar_conf_cc_proto",
deps = [
":racobit_radar_conf_proto",
],
)
proto_library(
name = "racobit_radar_conf_proto",
srcs = ["racobit_radar_conf.proto"],
deps = [
"//modules/common_msgs/sensor_msgs:racobit_radar_proto",
"//modules/common_msgs/drivers_msgs:can_card_parameter_proto",
],
)
py_proto_library(
name = "racobit_radar_conf_py_pb2",
deps = [
":racobit_radar_conf_proto",
"//modules/common_msgs/sensor_msgs:racobit_radar_py_pb2",
"//modules/common_msgs/drivers_msgs:can_card_parameter_py_pb2",
],
)
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/launch/racobit_radar.launch
|
<cyber>
<module>
<name>racobit_radar</name>
<dag_conf>/apollo/modules/drivers/radar/racobit_radar/dag/racobit_radar.dag</dag_conf>
<process_name></process_name>
</module>
</cyber>
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/dag/racobit_radar.dag
|
module_config {
module_library : "/apollo/bazel-bin/modules/drivers/radar/racobit_radar/libracobit_radar_canbus_component.so"
components {
class_name : "RacobitRadarCanbusComponent"
config {
name: "racobit_radar"
config_file_path: "/apollo/modules/drivers/radar/racobit_radar/conf/racobit_radar_conf.pb.txt"
}
}
}
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/radar_config_200.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/common_msgs/sensor_msgs/racobit_radar.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/drivers/radar/racobit_radar/proto/racobit_radar_conf.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
using apollo::drivers::racobit_radar::RadarConf;
class RadarConfig200
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
RadarConfig200();
~RadarConfig200();
/**
* @brief get the data period
* @return the value of data period
*/
uint32_t GetPeriod() const override;
/**
* @brief update the data
* @param data a pointer to the data to be updated
*/
void UpdateData(uint8_t* data) override;
/**
* @brief reset the private variables
*/
void Reset() override;
RadarConfig200* set_max_distance_valid(bool valid);
RadarConfig200* set_sensor_id_valid(bool valid);
RadarConfig200* set_radar_power_valid(bool valid);
RadarConfig200* set_output_type_valid(bool valid);
RadarConfig200* set_send_quality_valid(bool valid);
RadarConfig200* set_send_ext_info_valid(bool valid);
RadarConfig200* set_sort_index_valid(bool valid);
RadarConfig200* set_store_in_nvm_valid(bool valid);
RadarConfig200* set_ctrl_relay_valid(bool valid);
RadarConfig200* set_rcs_threshold_valid(bool valid);
RadarConfig200* set_max_distance(uint16_t data);
RadarConfig200* set_sensor_id(uint8_t data);
RadarConfig200* set_output_type(RacobitRadarState_201::OutputType type);
RadarConfig200* set_radar_power(uint8_t data);
RadarConfig200* set_ctrl_relay(uint8_t data);
RadarConfig200* set_send_ext_info(uint8_t data);
RadarConfig200* set_send_quality(uint8_t data);
RadarConfig200* set_sort_index(uint8_t data);
RadarConfig200* set_store_in_nvm(uint8_t data);
RadarConfig200* set_rcs_threshold(
RacobitRadarState_201::RcsThreshold rcs_theshold);
RadarConfig200* set_radar_conf(RadarConf radar_conf);
RadarConf radar_conf();
void set_max_distance_valid_p(uint8_t* data, bool valid);
void set_sensor_id_valid_p(uint8_t* data, bool valid);
void set_radar_power_valid_p(uint8_t* data, bool valid);
void set_output_type_valid_p(uint8_t* data, bool valid);
void set_send_quality_valid_p(uint8_t* data, bool valid);
void set_send_ext_info_valid_p(uint8_t* data, bool valid);
void set_sort_index_valid_p(uint8_t* data, bool valid);
void set_store_in_nvm_valid_p(uint8_t* data, bool valid);
void set_ctrl_relay_valid_p(uint8_t* data, bool valid);
void set_rcs_threshold_valid_p(uint8_t* data, bool valid);
void set_max_distance_p(uint8_t* data, uint16_t value);
void set_sensor_id_p(uint8_t* data, uint8_t value);
void set_output_type_p(
uint8_t* data, RacobitRadarState_201::OutputType type);
void set_radar_power_p(uint8_t* data, uint8_t value);
void set_ctrl_relay_p(uint8_t* data, uint8_t value);
void set_send_ext_info_p(uint8_t* data, uint8_t value);
void set_send_quality_p(uint8_t* data, uint8_t value);
void set_sort_index_p(uint8_t* data, uint8_t value);
void set_store_in_nvm_p(uint8_t* data, uint8_t value);
void set_rcs_threshold_p(
uint8_t* data, RacobitRadarState_201::RcsThreshold rcs_theshold);
private:
RadarConf radar_conf_;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/radar_state_201.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class RadarState201
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
RadarState201();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int max_dist(const std::uint8_t* bytes, int32_t length) const;
int radar_power(const std::uint8_t* bytes, int32_t length) const;
RacobitRadarState_201::OutputType output_type(
const std::uint8_t* bytes, int32_t length) const;
RacobitRadarState_201::RcsThreshold rcs_threshold(
const std::uint8_t* bytes, int32_t length) const;
bool send_quality(const std::uint8_t* bytes, int32_t length) const;
bool send_ext_info(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_general_info_60b.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class ObjectGeneralInfo60B
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
ObjectGeneralInfo60B();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int object_id(const std::uint8_t* bytes, int32_t length) const;
double longitude_dist(const std::uint8_t* bytes, int32_t length) const;
double lateral_dist(const std::uint8_t* bytes, int32_t length) const;
double longitude_vel(const std::uint8_t* bytes, int32_t length) const;
double lateral_vel(const std::uint8_t* bytes, int32_t length) const;
double rcs(const std::uint8_t* bytes, int32_t length) const;
int dynprop(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_extended_info_60d.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class ObjectExtendedInfo60D
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
ObjectExtendedInfo60D();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int object_id(const std::uint8_t* bytes, int32_t length) const;
double longitude_accel(const std::uint8_t* bytes, int32_t length) const;
double lateral_accel(const std::uint8_t* bytes, int32_t length) const;
int obstacle_class(const std::uint8_t* bytes, int32_t length) const;
double oritation_angle(const std::uint8_t* bytes, int32_t length) const;
double object_length(const std::uint8_t* bytes, int32_t length) const;
double object_width(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/radar_state_201.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/drivers/radar/racobit_radar/protocol/radar_state_201.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::canbus::Byte;
RadarState201::RadarState201() {}
const uint32_t RadarState201::ID = 0x201;
void RadarState201::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
auto state = racobit_radar->mutable_radar_state();
state->set_max_distance(max_dist(bytes, length));
state->set_output_type(output_type(bytes, length));
state->set_rcs_threshold(rcs_threshold(bytes, length));
state->set_radar_power(radar_power(bytes, length));
state->set_send_quality(send_quality(bytes, length));
state->set_send_ext_info(send_ext_info(bytes, length));
}
int RadarState201::max_dist(const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 1);
uint32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
uint32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
int ret = x * 2;
return ret;
}
int RadarState201::radar_power(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
uint32_t x = t0.get_byte(0, 2);
Byte t1(bytes + 4);
uint32_t t = t1.get_byte(7, 1);
x <<= 1;
x |= t;
int ret = x;
return ret;
}
RacobitRadarState_201::OutputType RadarState201::output_type(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(2, 2);
switch (x) {
case 0x0:
return RacobitRadarState_201::OUTPUT_TYPE_NONE;
case 0x1:
return RacobitRadarState_201::OUTPUT_TYPE_OBJECTS;
case 0x2:
return RacobitRadarState_201::OUTPUT_TYPE_CLUSTERS;
default:
return RacobitRadarState_201::OUTPUT_TYPE_ERROR;
}
}
RacobitRadarState_201::RcsThreshold RadarState201::rcs_threshold(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
uint32_t x = t0.get_byte(2, 3);
switch (x) {
case 0x0:
return RacobitRadarState_201::RCS_THRESHOLD_STANDARD;
case 0x1:
return RacobitRadarState_201::RCS_THRESHOLD_HIGH_SENSITIVITY;
default:
return RacobitRadarState_201::RCS_THRESHOLD_ERROR;
}
}
bool RadarState201::send_quality(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(4, 1);
bool ret = (x == 0x1);
return ret;
}
bool RadarState201::send_ext_info(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(5, 1);
bool ret = (x == 0x1);
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/radar_config_200.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/drivers/radar/racobit_radar/protocol/radar_config_200.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
using apollo::drivers::canbus::Byte;
const uint32_t RadarConfig200::ID = 0x200;
RadarConfig200::RadarConfig200() {}
RadarConfig200::~RadarConfig200() {}
uint32_t RadarConfig200::GetPeriod() const {
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
/**
* @brief update the data
* @param data a pointer to the data to be updated
*/
void RadarConfig200::UpdateData(uint8_t* data) {
set_max_distance_valid_p(data, radar_conf_.max_distance_valid());
set_sensor_id_valid_p(data, radar_conf_.sensor_id_valid());
set_radar_power_valid_p(data, radar_conf_.radar_power_valid());
set_output_type_valid_p(data, radar_conf_.output_type_valid());
set_send_quality_valid_p(data, radar_conf_.send_quality_valid());
set_send_ext_info_valid_p(data, radar_conf_.send_ext_info_valid());
set_sort_index_valid_p(data, radar_conf_.sort_index_valid());
set_store_in_nvm_valid_p(data, radar_conf_.store_in_nvm_valid());
set_ctrl_relay_valid_p(data, radar_conf_.ctrl_relay_valid());
set_rcs_threshold_valid_p(data, radar_conf_.rcs_threshold_valid());
set_max_distance_p(data, static_cast<uint16_t>(radar_conf_.max_distance()));
set_sensor_id_p(data, static_cast<uint8_t>(radar_conf_.sensor_id()));
set_output_type_p(data, radar_conf_.output_type());
set_radar_power_p(data, static_cast<uint8_t>(radar_conf_.radar_power()));
set_ctrl_relay_p(data, static_cast<uint8_t>(radar_conf_.ctrl_relay()));
set_send_ext_info_p(data, radar_conf_.send_ext_info());
set_send_quality_p(data, radar_conf_.send_quality());
set_sort_index_p(data, static_cast<uint8_t>(radar_conf_.sort_index()));
set_store_in_nvm_p(data, static_cast<uint8_t>(radar_conf_.store_in_nvm()));
set_rcs_threshold_p(data, radar_conf_.rcs_threshold());
}
/**
* @brief reset the private variables
*/
void RadarConfig200::Reset() {
radar_conf_.set_max_distance_valid(false);
radar_conf_.set_sensor_id_valid(false);
radar_conf_.set_radar_power_valid(false);
radar_conf_.set_output_type_valid(true);
radar_conf_.set_send_quality_valid(true);
radar_conf_.set_send_ext_info_valid(true);
radar_conf_.set_sort_index_valid(false);
radar_conf_.set_store_in_nvm_valid(true);
radar_conf_.set_ctrl_relay_valid(false);
radar_conf_.set_rcs_threshold_valid(true);
radar_conf_.set_max_distance(125);
radar_conf_.set_sensor_id(0);
radar_conf_.set_output_type(RacobitRadarState_201::OUTPUT_TYPE_NONE);
radar_conf_.set_radar_power(0);
radar_conf_.set_ctrl_relay(0);
radar_conf_.set_send_ext_info(1);
radar_conf_.set_send_quality(1);
radar_conf_.set_sort_index(0);
radar_conf_.set_store_in_nvm(1);
radar_conf_.set_rcs_threshold(RacobitRadarState_201::RCS_THRESHOLD_STANDARD);
}
RadarConf RadarConfig200::radar_conf() { return radar_conf_; }
RadarConfig200* RadarConfig200::set_radar_conf(RadarConf radar_conf) {
radar_conf_.CopyFrom(radar_conf);
return this;
}
RadarConfig200* RadarConfig200::set_max_distance_valid(bool valid) {
radar_conf_.set_max_distance_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_sensor_id_valid(bool valid) {
radar_conf_.set_sensor_id_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_radar_power_valid(bool valid) {
radar_conf_.set_radar_power_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_output_type_valid(bool valid) {
radar_conf_.set_output_type_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_send_quality_valid(bool valid) {
radar_conf_.set_send_quality_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_send_ext_info_valid(bool valid) {
radar_conf_.set_send_ext_info_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_sort_index_valid(bool valid) {
radar_conf_.set_sort_index_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_store_in_nvm_valid(bool valid) {
radar_conf_.set_store_in_nvm_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_ctrl_relay_valid(bool valid) {
radar_conf_.set_ctrl_relay_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_rcs_threshold_valid(bool valid) {
radar_conf_.set_rcs_threshold_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_max_distance(uint16_t data) {
radar_conf_.set_max_distance(data);
return this;
}
RadarConfig200* RadarConfig200::set_sensor_id(uint8_t data) {
radar_conf_.set_sensor_id(data);
return this;
}
RadarConfig200* RadarConfig200::set_output_type(
RacobitRadarState_201::OutputType type) {
radar_conf_.set_output_type(type);
return this;
}
RadarConfig200* RadarConfig200::set_radar_power(uint8_t data) {
radar_conf_.set_radar_power(data);
return this;
}
RadarConfig200* RadarConfig200::set_ctrl_relay(uint8_t data) {
radar_conf_.set_ctrl_relay(data);
return this;
}
RadarConfig200* RadarConfig200::set_send_ext_info(uint8_t data) {
radar_conf_.set_send_ext_info(data);
return this;
}
RadarConfig200* RadarConfig200::set_send_quality(uint8_t data) {
radar_conf_.set_send_quality(data);
return this;
}
RadarConfig200* RadarConfig200::set_sort_index(uint8_t data) {
radar_conf_.set_sort_index(data);
return this;
}
RadarConfig200* RadarConfig200::set_store_in_nvm(uint8_t data) {
radar_conf_.set_store_in_nvm(data);
return this;
}
RadarConfig200* RadarConfig200::set_rcs_threshold(
RacobitRadarState_201::RcsThreshold rcs_theshold) {
radar_conf_.set_rcs_threshold(rcs_theshold);
return this;
}
void RadarConfig200::set_max_distance_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_bit_1(0);
} else {
frame.set_bit_0(0);
}
}
void RadarConfig200::set_sensor_id_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_bit_1(1);
} else {
frame.set_bit_0(1);
}
}
void RadarConfig200::set_radar_power_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 2, 1);
} else {
frame.set_value(0, 2, 1);
}
}
void RadarConfig200::set_output_type_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 3, 1);
} else {
frame.set_value(0, 3, 1);
}
}
void RadarConfig200::set_send_quality_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 4, 1);
} else {
frame.set_value(0, 4, 1);
}
}
void RadarConfig200::set_send_ext_info_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 5, 1);
} else {
frame.set_value(0, 5, 1);
}
}
void RadarConfig200::set_sort_index_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 6, 1);
} else {
frame.set_value(0, 6, 1);
}
}
void RadarConfig200::set_store_in_nvm_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 7, 1);
} else {
frame.set_value(0, 7, 1);
}
}
void RadarConfig200::set_ctrl_relay_valid_p(uint8_t* data, bool valid) {
Byte frame(data + 5);
if (valid) {
frame.set_bit_1(0);
} else {
frame.set_bit_0(0);
}
}
void RadarConfig200::set_rcs_threshold_valid_p(uint8_t* data, bool valid) {
Byte frame(data + 6);
if (valid) {
frame.set_bit_1(0);
} else {
frame.set_bit_0(0);
}
}
void RadarConfig200::set_max_distance_p(uint8_t* data, uint16_t value) {
value /= 2;
uint8_t low = static_cast<uint8_t>(value >> 2);
Byte frame_low(data + 1);
frame_low.set_value(low, 0, 8);
uint8_t high = static_cast<uint8_t>(value << 6);
high &= 0xc0;
Byte frame_high(data + 2);
frame_high.set_value(high, 0, 8);
}
void RadarConfig200::set_sensor_id_p(uint8_t* data, uint8_t value) {
Byte frame(data + 4);
frame.set_value(value, 0, 3);
}
void RadarConfig200::set_output_type_p(
uint8_t* data, RacobitRadarState_201::OutputType type) {
Byte frame(data + 4);
uint8_t value = static_cast<uint8_t>(type);
frame.set_value(value, 3, 2);
}
void RadarConfig200::set_radar_power_p(uint8_t* data, uint8_t value) {
Byte frame(data + 4);
frame.set_value(value, 5, 3);
}
void RadarConfig200::set_ctrl_relay_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 1, 1);
}
void RadarConfig200::set_send_ext_info_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 3, 1);
}
void RadarConfig200::set_send_quality_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 2, 1);
}
void RadarConfig200::set_sort_index_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 4, 3);
}
void RadarConfig200::set_store_in_nvm_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 7, 1);
}
void RadarConfig200::set_rcs_threshold_p(
uint8_t* data, RacobitRadarState_201::RcsThreshold rcs_threshold) {
Byte frame(data + 6);
uint8_t value = static_cast<uint8_t>(rcs_threshold);
frame.set_value(value, 1, 3);
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_list_status_60a.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class ObjectListStatus60A
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
ObjectListStatus60A();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int num_of_objects(const std::uint8_t* bytes, int32_t length) const;
int meas_counter(const std::uint8_t* bytes, int32_t length) const;
int interface_version(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/const_vars.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
namespace apollo {
namespace drivers {
namespace racobit_radar {
const int CONTIID_START = 0x600;
const int CONTIID_END = 0x702;
const int WAIT_TIME = 4000;
// Try this many times when receiving using bcan, by default.
const int BCAN_RECV_TRIES = 4;
const int RADAR_CONFIG = 0x200;
const int RADAR_STATE = 0x201;
const int CAN_BUFFER_NUM = 20;
const int CANBYTE = 13;
const int ETHER_WAIT = 5000000;
const int DISCONNECT_WAIT = 5;
// cluster quality
const double LINEAR_RMS[32] = {0.005, 0.006, 0.008, 0.011, 0.014, 0.018, 0.023,
0.029, 0.038, 0.049, 0.063, 0.081, 0.105, 0.135,
0.174, 0.224, 0.288, 0.371, 0.478, 0.616, 0.794,
1.023, 1.317, 1.697, 2.187, 2.817, 3.630, 4.676,
6.025, 7.762, 10.000, 100.00};
const double ANGLE_RMS[32] = {
0.005, 0.007, 0.010, 0.014, 0.020, 0.029, 0.041, 0.058,
0.082, 0.116, 0.165, 0.234, 0.332, 0.471, 0.669, 0.949,
1.346, 1.909, 2.709, 3.843, 5.451, 7.734, 10.971, 15.565,
22.061, 31.325, 44.439, 63.044, 69.437, 126.881, 180.000, 360.00};
const double PROBOFEXIST[8] = {0.00, 0.25, 0.5, 0.75, 0.90, 0.99, 0.999, 1.0};
const double CLUSTER_DIST_RES = 0.2;
const double CLUSTER_DIST_LONG_MIN = -500;
const double CLUSTER_DIST_LAT_MIN = -102.3;
const double CLUSTER_VREL_RES = 0.25;
const double CLUSTER_VREL_LONG_MIN = -128.0;
const double CLUSTER_VREL_LAT_MIN = -64.0;
const double CLUSTER_RCS_RES = 0.5;
const double CLUSTER_RCS = -64.0;
// Object general information
const double OBJECT_DIST_RES = 0.2;
const double OBJECT_DIST_LONG_MIN = -500;
const double OBJECT_DIST_LAT_MIN = -204.6;
const double OBJECT_VREL_RES = 0.25;
const double OBJECT_VREL_LONG_MIN = -128.0;
const double OBJECT_VREL_LAT_MIN = -64.0;
const double OBJECT_RCS_RES = 0.5;
const double OBJECT_RCS_MIN = -64.0;
// Object extended information
const double OBJECT_AREL_RES = 0.01;
const double OBJECT_AREL_LONG_MIN = -10.0;
const double OBJECT_AREL_LAT_MIN = -2.5;
const double OBJECT_ORIENTATION_ANGEL_MIN = -180.0;
const double OBJECT_ORIENTATION_ANGEL_RES = 0.4;
const double OBJECT_WIDTH_RES = 0.2;
const double OBJECT_LENGTH_RES = 0.2;
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_quality_info_60c.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/drivers/radar/racobit_radar/protocol/object_quality_info_60c.h"
#include "modules/drivers/radar/racobit_radar/protocol/const_vars.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::canbus::Byte;
ObjectQualityInfo60C::ObjectQualityInfo60C() {}
const uint32_t ObjectQualityInfo60C::ID = 0x60C;
void ObjectQualityInfo60C::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
int obj_id = object_id(bytes, length);
for (int i = 0; i < racobit_radar->contiobs_size(); ++i) {
if (racobit_radar->contiobs(i).obstacle_id() == obj_id) {
auto obs = racobit_radar->mutable_contiobs(i);
obs->set_longitude_dist_rms(
LINEAR_RMS[longitude_dist_rms(bytes, length)]);
obs->set_lateral_dist_rms(LINEAR_RMS[lateral_dist_rms(bytes, length)]);
obs->set_longitude_vel_rms(LINEAR_RMS[longitude_vel_rms(bytes, length)]);
obs->set_lateral_vel_rms(LINEAR_RMS[lateral_vel_rms(bytes, length)]);
obs->set_longitude_accel_rms(
LINEAR_RMS[longitude_accel_rms(bytes, length)]);
obs->set_lateral_accel_rms(LINEAR_RMS[lateral_accel_rms(bytes, length)]);
obs->set_oritation_angle_rms(
ANGLE_RMS[oritation_angle_rms(bytes, length)]);
obs->set_probexist(PROBOFEXIST[probexist(bytes, length)]);
obs->set_meas_state(meas_state(bytes, length));
break;
}
}
}
int ObjectQualityInfo60C::object_id(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::longitude_dist_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(3, 5);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::lateral_dist_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 3);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::longitude_vel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(1, 5);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::lateral_vel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 1);
Byte t1(bytes + 3);
int32_t t = t1.get_byte(4, 4);
x <<= 4;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::longitude_accel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 4);
Byte t1(bytes + 4);
int32_t t = t1.get_byte(7, 1);
x <<= 1;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::lateral_accel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(2, 5);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::oritation_angle_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 2);
Byte t1(bytes + 5);
int32_t t = t1.get_byte(5, 3);
x <<= 3;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::probexist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(5, 3);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::meas_state(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(2, 3);
int ret = x;
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/cluster_quality_info_702.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class ClusterQualityInfo702
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
ClusterQualityInfo702();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int target_id(const std::uint8_t* bytes, int32_t length) const;
int longitude_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int longitude_vel_rms(const std::uint8_t* bytes, int32_t length) const;
int pdh0(const std::uint8_t* bytes, int32_t length) const;
int ambig_state(const std::uint8_t* bytes, int32_t length) const;
int invalid_state(const std::uint8_t* bytes, int32_t length) const;
int lateral_vel_rms(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/cluster_general_info_701.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/drivers/radar/racobit_radar/protocol/cluster_general_info_701.h"
#include "glog/logging.h"
#include "cyber/time/time.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
#include "modules/drivers/radar/racobit_radar/protocol/const_vars.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::canbus::Byte;
ClusterGeneralInfo701::ClusterGeneralInfo701() {}
const uint32_t ClusterGeneralInfo701::ID = 0x701;
void ClusterGeneralInfo701::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
auto obs = racobit_radar->add_contiobs();
obs->set_clusterortrack(true);
obs->set_obstacle_id(obstacle_id(bytes, length));
obs->set_longitude_dist(longitude_dist(bytes, length));
obs->set_lateral_dist(lateral_dist(bytes, length));
obs->set_longitude_vel(longitude_vel(bytes, length));
obs->set_lateral_vel(lateral_vel(bytes, length));
obs->set_rcs(rcs(bytes, length));
obs->set_dynprop(dynprop(bytes, length));
double timestamp = apollo::cyber::Time::Now().ToSecond();
auto header = obs->mutable_header();
header->CopyFrom(racobit_radar->header());
header->set_timestamp_sec(timestamp);
}
int ClusterGeneralInfo701::obstacle_id(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
uint32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
double ClusterGeneralInfo701::longitude_dist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
uint32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
uint32_t t = t1.get_byte(3, 5);
x <<= 5;
x |= t;
double ret = x * CLUSTER_DIST_RES + CLUSTER_DIST_LONG_MIN;
return ret;
}
double ClusterGeneralInfo701::lateral_dist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
uint32_t x = t0.get_byte(0, 2);
Byte t1(bytes + 3);
uint32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
double ret = x * CLUSTER_DIST_RES + CLUSTER_DIST_LAT_MIN;
return ret;
}
double ClusterGeneralInfo701::longitude_vel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
uint32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 5);
uint32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
double ret = x * CLUSTER_VREL_RES + CLUSTER_VREL_LONG_MIN;
return ret;
}
double ClusterGeneralInfo701::lateral_vel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(0, 6);
Byte t1(bytes + 6);
uint32_t t = t1.get_byte(5, 3);
x <<= 3;
x |= t;
double ret = x * CLUSTER_VREL_RES + CLUSTER_VREL_LAT_MIN;
return ret;
}
double ClusterGeneralInfo701::rcs(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
uint32_t x = t0.get_byte(0, 8);
double ret = x * CLUSTER_RCS_RES + CLUSTER_RCS;
return ret;
}
int ClusterGeneralInfo701::dynprop(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
uint32_t x = t0.get_byte(0, 3);
int ret = x;
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/cluster_general_info_701.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class ClusterGeneralInfo701
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
ClusterGeneralInfo701();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int obstacle_id(const std::uint8_t* bytes, int32_t length) const;
double longitude_dist(const std::uint8_t* bytes, int32_t length) const;
double lateral_dist(const std::uint8_t* bytes, int32_t length) const;
double longitude_vel(const std::uint8_t* bytes, int32_t length) const;
double lateral_vel(const std::uint8_t* bytes, int32_t length) const;
double rcs(const std::uint8_t* bytes, int32_t length) const;
int dynprop(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_quality_info_60c.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class ObjectQualityInfo60C
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
ObjectQualityInfo60C();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int object_id(const std::uint8_t* bytes, int32_t length) const;
int longitude_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int longitude_vel_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_vel_rms(const std::uint8_t* bytes, int32_t length) const;
int longitude_accel_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_accel_rms(const std::uint8_t* bytes, int32_t length) const;
int oritation_angle_rms(const std::uint8_t* bytes, int32_t length) const;
int probexist(const std::uint8_t* bytes, int32_t length) const;
int meas_state(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_extended_info_60d.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/drivers/radar/racobit_radar/protocol/object_extended_info_60d.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
#include "modules/drivers/radar/racobit_radar/protocol/const_vars.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::canbus::Byte;
ObjectExtendedInfo60D::ObjectExtendedInfo60D() {}
const uint32_t ObjectExtendedInfo60D::ID = 0x60D;
void ObjectExtendedInfo60D::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
int obj_id = object_id(bytes, length);
for (int i = 0; i < racobit_radar->contiobs_size(); ++i) {
if (racobit_radar->contiobs(i).obstacle_id() == obj_id) {
auto obs = racobit_radar->mutable_contiobs(i);
obs->set_longitude_accel(longitude_accel(bytes, length));
obs->set_lateral_accel(lateral_accel(bytes, length));
obs->set_oritation_angle(oritation_angle(bytes, length));
obs->set_length(object_length(bytes, length));
obs->set_width(object_width(bytes, length));
obs->set_obstacle_class(obstacle_class(bytes, length));
break;
}
}
// auto conti_obs = racobit_radar->mutable_contiobs(object_id(bytes, length));
}
int ObjectExtendedInfo60D::object_id(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
double ObjectExtendedInfo60D::longitude_accel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(5, 3);
x <<= 3;
x |= t;
double ret = x * OBJECT_AREL_RES + OBJECT_AREL_LONG_MIN;
return ret;
}
double ObjectExtendedInfo60D::lateral_accel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 5);
Byte t1(bytes + 3);
int32_t t = t1.get_byte(4, 4);
x <<= 4;
x |= t;
double ret = x * OBJECT_AREL_RES + OBJECT_AREL_LAT_MIN;
return ret;
}
int ObjectExtendedInfo60D::obstacle_class(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 3);
int ret = x;
return ret;
}
double ObjectExtendedInfo60D::oritation_angle(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 5);
int32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
double ret = x * OBJECT_ORIENTATION_ANGEL_RES + OBJECT_ORIENTATION_ANGEL_MIN;
return ret;
}
double ObjectExtendedInfo60D::object_length(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 8);
double ret = x * OBJECT_LENGTH_RES;
return ret;
}
double ObjectExtendedInfo60D::object_width(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
double ret = x * OBJECT_WIDTH_RES;
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/cluster_list_status_600.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/drivers/radar/racobit_radar/protocol/cluster_list_status_600.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadarObs;
using apollo::drivers::canbus::Byte;
ClusterListStatus600::ClusterListStatus600() {}
const uint32_t ClusterListStatus600::ID = 0x600;
void ClusterListStatus600::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
auto status = racobit_radar->mutable_cluster_list_status();
status->set_near(near(bytes, length));
status->set_far(far(bytes, length));
status->set_meas_counter(meas_counter(bytes, length));
status->set_interface_version(interface_version(bytes, length));
auto counter = status->near() + status->far();
racobit_radar->mutable_contiobs()->Reserve(counter);
}
int ClusterListStatus600::near(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
int ClusterListStatus600::far(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;
}
int ClusterListStatus600::meas_counter(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 3);
uint32_t t = t0.get_byte(0, 8);
x <<= 8;
x |= t;
int ret = x;
return ret;
}
int ClusterListStatus600::interface_version(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(4, 4);
int ret = x;
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_list_status_60a.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/drivers/radar/racobit_radar/protocol/object_list_status_60a.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadarObs;
using apollo::drivers::canbus::Byte;
ObjectListStatus60A::ObjectListStatus60A() {}
const uint32_t ObjectListStatus60A::ID = 0x60A;
void ObjectListStatus60A::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
auto status = racobit_radar->mutable_object_list_status();
auto num_of_obj = num_of_objects(bytes, length);
status->set_nof_objects(num_of_obj);
status->set_meas_counter(meas_counter(bytes, length));
status->set_interface_version(interface_version(bytes, length));
racobit_radar->mutable_contiobs()->Reserve(num_of_obj);
}
int ObjectListStatus60A::num_of_objects(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
int ObjectListStatus60A::meas_counter(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
uint32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 3);
uint32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
int ret = x;
return ret;
}
int ObjectListStatus60A::interface_version(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(4, 4);
int ret = x;
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
cc_library(
name = "drivers_racobit_radar_protocol",
srcs = glob([
"*.cc",
]),
hdrs = glob([
"*.h",
]),
deps = [
"//modules/common_msgs/basic_msgs:header_cc_proto",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/common_msgs/drivers_msgs:can_card_parameter_cc_proto",
"//modules/common_msgs/sensor_msgs:racobit_radar_cc_proto",
"//modules/drivers/radar/racobit_radar/proto:racobit_radar_conf_cc_proto",
],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/cluster_list_status_600.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/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/racobit_radar.pb.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::RacobitRadar;
class ClusterListStatus600
: public apollo::drivers::canbus::ProtocolData<RacobitRadar> {
public:
static const uint32_t ID;
ClusterListStatus600();
void Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const override;
private:
int near(const std::uint8_t* bytes, int32_t length) const;
int far(const std::uint8_t* bytes, int32_t length) const;
int meas_counter(const std::uint8_t* bytes, int32_t length) const;
int interface_version(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/cluster_quality_info_702.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/drivers/radar/racobit_radar/protocol/cluster_quality_info_702.h"
#include "modules/drivers/radar/racobit_radar/protocol/const_vars.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::canbus::Byte;
ClusterQualityInfo702::ClusterQualityInfo702() {}
const uint32_t ClusterQualityInfo702::ID = 0x702;
void ClusterQualityInfo702::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
int id = target_id(bytes, length);
for (int i = 0; i < racobit_radar->contiobs_size(); ++i) {
if (racobit_radar->contiobs(i).obstacle_id() == id) {
auto racobit_obs = racobit_radar->mutable_contiobs(i);
racobit_obs->set_longitude_dist_rms(
LINEAR_RMS[longitude_dist_rms(bytes, length)]);
racobit_obs->set_lateral_dist_rms(
LINEAR_RMS[lateral_dist_rms(bytes, length)]);
racobit_obs->set_longitude_vel_rms(
LINEAR_RMS[longitude_vel_rms(bytes, length)]);
racobit_obs->set_lateral_vel_rms(
LINEAR_RMS[lateral_vel_rms(bytes, length)]);
racobit_obs->set_probexist(PROBOFEXIST[pdh0(bytes, length)]);
switch (invalid_state(bytes, length)) {
case 0x01:
case 0x02:
case 0x03:
case 0x06:
case 0x07:
case 0x0E:
racobit_obs->set_probexist(PROBOFEXIST[0]);
default:
break;
}
switch (ambig_state(bytes, length)) {
case 0x00:
case 0x01:
case 0x02:
racobit_obs->set_probexist(PROBOFEXIST[0]);
default:
break;
}
}
}
}
int ClusterQualityInfo702::target_id(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
int ClusterQualityInfo702::longitude_dist_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(3, 5);
int ret = x;
return ret;
}
int ClusterQualityInfo702::lateral_dist_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 3);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
int ret = x;
return ret;
}
int ClusterQualityInfo702::longitude_vel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(1, 5);
int ret = x;
return ret;
}
int ClusterQualityInfo702::pdh0(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 3);
int ret = x;
return ret;
}
int ClusterQualityInfo702::ambig_state(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 3);
int ret = x;
return ret;
}
int ClusterQualityInfo702::invalid_state(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(3, 5);
int ret = x;
return ret;
}
int ClusterQualityInfo702::lateral_vel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 1);
Byte t1(bytes + 3);
int32_t t = t1.get_byte(4, 4);
x <<= 4;
x |= t;
int ret = x;
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/protocol/object_general_info_60b.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/drivers/radar/racobit_radar/protocol/object_general_info_60b.h"
#include "glog/logging.h"
#include "cyber/time/time.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
#include "modules/drivers/radar/racobit_radar/protocol/const_vars.h"
namespace apollo {
namespace drivers {
namespace racobit_radar {
using apollo::drivers::canbus::Byte;
ObjectGeneralInfo60B::ObjectGeneralInfo60B() {}
const uint32_t ObjectGeneralInfo60B::ID = 0x60B;
void ObjectGeneralInfo60B::Parse(const std::uint8_t* bytes, int32_t length,
RacobitRadar* racobit_radar) const {
int obj_id = object_id(bytes, length);
auto racobit_obs = racobit_radar->add_contiobs();
racobit_obs->set_clusterortrack(false);
racobit_obs->set_obstacle_id(obj_id);
racobit_obs->set_longitude_dist(longitude_dist(bytes, length));
racobit_obs->set_lateral_dist(lateral_dist(bytes, length));
racobit_obs->set_longitude_vel(longitude_vel(bytes, length));
racobit_obs->set_lateral_vel(lateral_vel(bytes, length));
racobit_obs->set_rcs(rcs(bytes, length));
racobit_obs->set_dynprop(dynprop(bytes, length));
double timestamp = apollo::cyber::Time::Now().ToSecond();
auto header = racobit_obs->mutable_header();
header->CopyFrom(racobit_radar->header());
header->set_timestamp_sec(timestamp);
}
int ObjectGeneralInfo60B::object_id(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
double ObjectGeneralInfo60B::longitude_dist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(3, 5);
x <<= 5;
x |= t;
double ret = x * OBJECT_DIST_RES + OBJECT_DIST_LONG_MIN;
return ret;
}
double ObjectGeneralInfo60B::lateral_dist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 3);
Byte t1(bytes + 3);
int32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
double ret = x * OBJECT_DIST_RES + OBJECT_DIST_LAT_MIN;
return ret;
}
double ObjectGeneralInfo60B::longitude_vel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 5);
int32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
double ret = x * OBJECT_VREL_RES + OBJECT_VREL_LONG_MIN;
return ret;
}
double ObjectGeneralInfo60B::lateral_vel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
int32_t x = t0.get_byte(0, 6);
Byte t1(bytes + 6);
int32_t t = t1.get_byte(5, 3);
x <<= 3;
x |= t;
double ret = x * OBJECT_VREL_RES + OBJECT_VREL_LAT_MIN;
return ret;
}
double ObjectGeneralInfo60B::rcs(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
int32_t x = t0.get_byte(0, 8);
double ret = x * OBJECT_RCS_RES + OBJECT_RCS_MIN;
return ret;
}
int ObjectGeneralInfo60B::dynprop(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(0, 3);
int ret = x;
return ret;
}
} // namespace racobit_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/conf/racobit_radar.conf
|
--flagfile=modules/common/data/global_flagfile.txt
--alsologtostderr=1
--sensor_conf_file=modules/drivers/radar/racobit_radar/conf/racobit_radar_conf.pb.txt
--node_namespace=/apollo/drivers/racobit_radar
--sensor_node_name=racobit_radar
--canbus_driver_name=racobit_radar
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar
|
apollo_public_repos/apollo/modules/drivers/radar/racobit_radar/conf/racobit_radar_conf.pb.txt
|
can_conf {
can_card_parameter {
brand:ESD_CAN
type: PCI_CARD
channel_id: CHANNEL_ID_ONE
}
enable_debug_mode: false
enable_receiver_log: false
}
radar_conf {
max_distance_valid: true
sensor_id_valid: false
radar_power_valid: false
output_type_valid: true
send_quality_valid: true
send_ext_info_valid: true
sort_index_valid: false
store_in_nvm_valid: true
ctrl_relay_valid: false
rcs_threshold_valid: true
max_distance: 250
sensor_id: 0
output_type: OUTPUT_TYPE_OBJECTS
radar_power: 0
ctrl_relay: 0
send_ext_info: true
send_quality: true
sort_index: 0
store_in_nvm: 1
rcs_threshold: RCS_THRESHOLD_STANDARD
}
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/conti_radar_message_manager.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.
*****************************************************************************/
/**
* @file conti_radar_message_manager.h
* @brief The class of ContiRadarMessageManager
*/
#include "modules/drivers/radar/conti_radar/conti_radar_message_manager.h"
#include "modules/common/util/message_util.h"
#include "modules/drivers/radar/conti_radar/protocol/cluster_general_info_701.h"
#include "modules/drivers/radar/conti_radar/protocol/cluster_list_status_600.h"
#include "modules/drivers/radar/conti_radar/protocol/cluster_quality_info_702.h"
#include "modules/drivers/radar/conti_radar/protocol/object_extended_info_60d.h"
#include "modules/drivers/radar/conti_radar/protocol/object_general_info_60b.h"
#include "modules/drivers/radar/conti_radar/protocol/object_list_status_60a.h"
#include "modules/drivers/radar/conti_radar/protocol/object_quality_info_60c.h"
#include "modules/drivers/radar/conti_radar/protocol/radar_state_201.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using Time = apollo::cyber::Time;
using micros = std::chrono::microseconds;
using apollo::cyber::Writer;
using apollo::drivers::canbus::CanClient;
using apollo::drivers::canbus::ProtocolData;
using apollo::drivers::canbus::SenderMessage;
ContiRadarMessageManager::ContiRadarMessageManager(
const std::shared_ptr<Writer<ContiRadar>> &writer)
: conti_radar_writer_(writer) {
AddRecvProtocolData<RadarState201, true>();
AddRecvProtocolData<ClusterListStatus600, true>();
AddRecvProtocolData<ClusterGeneralInfo701, true>();
AddRecvProtocolData<ClusterQualityInfo702, true>();
AddRecvProtocolData<ObjectExtendedInfo60D, true>();
AddRecvProtocolData<ObjectGeneralInfo60B, true>();
AddRecvProtocolData<ObjectListStatus60A, true>();
AddRecvProtocolData<ObjectQualityInfo60C, true>();
}
void ContiRadarMessageManager::set_radar_conf(RadarConf radar_conf) {
radar_config_.set_radar_conf(radar_conf);
}
void ContiRadarMessageManager::set_can_client(
std::shared_ptr<CanClient> can_client) {
can_client_ = can_client;
}
ProtocolData<ContiRadar> *ContiRadarMessageManager::GetMutableProtocolDataById(
const uint32_t message_id) {
uint32_t converted_message_id = message_id;
if (protocol_data_map_.find(converted_message_id) ==
protocol_data_map_.end()) {
ADEBUG << "Unable to get protocol data because of invalid message_id:"
<< message_id;
return nullptr;
}
return protocol_data_map_[converted_message_id];
}
void ContiRadarMessageManager::Parse(const uint32_t message_id,
const uint8_t *data, int32_t length) {
ProtocolData<ContiRadar> *sensor_protocol_data =
GetMutableProtocolDataById(message_id);
if (sensor_protocol_data == nullptr) {
return;
}
std::lock_guard<std::mutex> lock(sensor_data_mutex_);
if (!is_configured_ && message_id != RadarState201::ID) {
// read radar state message first
return;
}
// trigger publishment
if (message_id == ClusterListStatus600::ID ||
message_id == ObjectListStatus60A::ID) {
ADEBUG << sensor_data_.ShortDebugString();
if (sensor_data_.contiobs_size() <=
sensor_data_.object_list_status().nof_objects()) {
// maybe lost an object_list_status msg
conti_radar_writer_->Write(sensor_data_);
}
sensor_data_.Clear();
// fill header when receive the general info message
common::util::FillHeader("conti_radar", &sensor_data_);
}
sensor_protocol_data->Parse(data, length, &sensor_data_);
if (message_id == RadarState201::ID) {
ADEBUG << sensor_data_.ShortDebugString();
if (sensor_data_.radar_state().send_quality() ==
radar_config_.radar_conf().send_quality() &&
sensor_data_.radar_state().send_ext_info() ==
radar_config_.radar_conf().send_ext_info() &&
sensor_data_.radar_state().max_distance() ==
radar_config_.radar_conf().max_distance() &&
sensor_data_.radar_state().output_type() ==
radar_config_.radar_conf().output_type() &&
sensor_data_.radar_state().rcs_threshold() ==
radar_config_.radar_conf().rcs_threshold() &&
sensor_data_.radar_state().radar_power() ==
radar_config_.radar_conf().radar_power()) {
is_configured_ = true;
} else {
AINFO << "configure radar again";
SenderMessage<ContiRadar> sender_message(RadarConfig200::ID,
&radar_config_);
sender_message.Update();
can_client_->SendSingleFrame({sender_message.CanFrame()});
}
}
received_ids_.insert(message_id);
// check if need to check period
const auto it = check_ids_.find(message_id);
if (it != check_ids_.end()) {
const int64_t time = Time::Now().ToMicrosecond();
it->second.real_period = time - it->second.last_time;
// if period 1.5 large than base period, inc error_count
const double period_multiplier = 1.5;
if (it->second.real_period >
(static_cast<double>(it->second.period) * period_multiplier)) {
it->second.error_count += 1;
} else {
it->second.error_count = 0;
}
it->second.last_time = time;
}
}
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/README_cn.md
|
## conti_radar
该驱动基于Apollo cyber开发,支持continental ARS。
### 配置
radar的默认配置: [conf/conti_radar_conf.pb.txt](https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/radar/conti_radar/conf/conti_radar_conf.pb.txt)
radar启动时,会先根据上述配置文件,向can卡发送指令,对radar进行配置。当接收到的radar状态信息与用户配置信息一致时,才开始解析数据并发送消息。
### 运行
该驱动需要在apollo docker环境中运行。
```bash
# in docker
cd /apollo
source scripts/apollo_base.sh
# 启动
./scripts/conti_radar.sh start
# 停止
./scripts/conti_radar.sh stop
```
### Topic
**topic name**: /apollo/sensor/conti_radar
**data type**: apollo::drivers::ContiRadar
**channel ID**: CHANNEL_ID_ONE
**proto file**: [modules/drivers/proto/conti_radar.proto](https://github.com/ApolloAuto/apollo/blob/master/modules/drivers/proto/conti_radar.proto)
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/conti_radar_canbus_component.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
*/
#pragma once
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "cyber/cyber.h"
#include "modules/common/monitor_log/monitor_log_buffer.h"
#include "modules/common/util/util.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/message_manager.h"
#include "modules/common_msgs/drivers_msgs/can_card_parameter.pb.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
#include "modules/drivers/radar/conti_radar/conti_radar_message_manager.h"
#include "modules/drivers/radar/conti_radar/protocol/motion_input_speed_300.h"
#include "modules/drivers/radar/conti_radar/protocol/motion_input_yawrate_301.h"
#include "modules/drivers/radar/conti_radar/protocol/radar_config_200.h"
#include "modules/common_msgs/localization_msgs/localization.pb.h"
/**
* @namespace apollo::drivers
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
namespace conti_radar {
/**
* @class ContiRadarCanbus
*
* @brief template of canbus-based sensor module main class (e.g., conti_radar).
*/
class ContiRadarCanbusComponent : public apollo::cyber::Component<> {
public:
ContiRadarCanbusComponent();
~ContiRadarCanbusComponent();
bool Init() override;
private:
bool OnError(const std::string& error_msg);
void RegisterCanClients();
apollo::common::ErrorCode ConfigureRadar();
bool Start();
void Stop();
ContiRadarConf conti_radar_conf_;
std::shared_ptr<apollo::drivers::canbus::CanClient> can_client_;
apollo::drivers::canbus::CanReceiver<ContiRadar> can_receiver_;
std::unique_ptr<ContiRadarMessageManager> sensor_message_manager_;
std::shared_ptr<apollo::cyber::Writer<ContiRadar>> conti_radar_writer_;
std::shared_ptr<
apollo::cyber::Reader<apollo::localization::LocalizationEstimate>>
pose_reader_;
void PoseCallback(
const std::shared_ptr<apollo::localization::LocalizationEstimate>& pose);
uint64_t last_nsec_ = 0;
int64_t last_timestamp_ = 0;
bool start_success_ = false;
apollo::common::monitor::MonitorLogBuffer monitor_logger_buffer_;
};
CYBER_REGISTER_COMPONENT(ContiRadarCanbusComponent)
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/conti_radar_message_manager.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 conti_radar_message_manager.h
* @brief The class of ContiRadarMessageManager
*/
#pragma once
#include <memory>
#include "cyber/cyber.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/can_comm/message_manager.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
#include "modules/drivers/radar/conti_radar/protocol/radar_config_200.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
class ContiRadarMessageManager
: public apollo::drivers::canbus::MessageManager<ContiRadar> {
public:
explicit ContiRadarMessageManager(
const std::shared_ptr<apollo::cyber::Writer<ContiRadar>> &writer);
virtual ~ContiRadarMessageManager() {}
void set_radar_conf(RadarConf radar_conf);
apollo::drivers::canbus::ProtocolData<ContiRadar> *GetMutableProtocolDataById(
const uint32_t message_id);
void Parse(const uint32_t message_id, const uint8_t *data, int32_t length);
void set_can_client(
std::shared_ptr<apollo::drivers::canbus::CanClient> can_client);
private:
bool is_configured_ = false;
RadarConfig200 radar_config_;
std::shared_ptr<apollo::drivers::canbus::CanClient> can_client_;
std::shared_ptr<apollo::cyber::Writer<ContiRadar>> conti_radar_writer_;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/conti_radar_canbus_component.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.
*****************************************************************************/
/**
* @file
*/
#include "Eigen/Geometry"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/drivers/canbus/can_client/can_client_factory.h"
#include "modules/drivers/canbus/can_comm/can_sender.h"
#include "modules/drivers/canbus/proto/sensor_canbus_conf.pb.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
#include "modules/drivers/radar/conti_radar/conti_radar_canbus_component.h"
#include "modules/drivers/radar/conti_radar/conti_radar_message_manager.h"
/**
* @namespace apollo::drivers::conti_radar
* @brief apollo::drivers
*/
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::common::ErrorCode;
using apollo::drivers::canbus::CanClientFactory;
using apollo::drivers::canbus::SenderMessage;
using apollo::drivers::canbus::SensorCanbusConf;
using apollo::localization::LocalizationEstimate;
ContiRadarCanbusComponent::ContiRadarCanbusComponent()
: monitor_logger_buffer_(
apollo::common::monitor::MonitorMessageItem::CONTI_RADAR) {}
ContiRadarCanbusComponent::~ContiRadarCanbusComponent() { Stop(); }
bool ContiRadarCanbusComponent::Init() {
if (!GetProtoConfig(&conti_radar_conf_)) {
return OnError("Unable to load canbus conf file: " + ConfigFilePath());
}
AINFO << "The canbus conf file is loaded: " << ConfigFilePath();
ADEBUG << "Canbus_conf:" << conti_radar_conf_.ShortDebugString();
// Init can client
auto can_factory = CanClientFactory::Instance();
can_factory->RegisterCanClients();
can_client_ = can_factory->CreateCANClient(
conti_radar_conf_.can_conf().can_card_parameter());
if (!can_client_) {
return OnError("Failed to create can client.");
}
AINFO << "Can client is successfully created.";
conti_radar_writer_ =
node_->CreateWriter<ContiRadar>(conti_radar_conf_.radar_channel());
pose_reader_ = node_->CreateReader<LocalizationEstimate>(
FLAGS_localization_topic,
[&](const std::shared_ptr<LocalizationEstimate>& pose) {
PoseCallback(pose);
});
sensor_message_manager_ = std::unique_ptr<ContiRadarMessageManager>(
new ContiRadarMessageManager(conti_radar_writer_));
if (sensor_message_manager_ == nullptr) {
return OnError("Failed to create message manager.");
}
sensor_message_manager_->set_radar_conf(conti_radar_conf_.radar_conf());
sensor_message_manager_->set_can_client(can_client_);
AINFO << "Sensor message manager is successfully created.";
if (can_receiver_.Init(can_client_.get(), sensor_message_manager_.get(),
conti_radar_conf_.can_conf().enable_receiver_log()) !=
ErrorCode::OK) {
return OnError("Failed to init can receiver.");
}
AINFO << "The can receiver is successfully initialized.";
start_success_ = Start();
return start_success_;
}
apollo::common::ErrorCode ContiRadarCanbusComponent::ConfigureRadar() {
RadarConfig200 radar_config;
radar_config.set_radar_conf(conti_radar_conf_.radar_conf());
SenderMessage<ContiRadar> sender_message(RadarConfig200::ID, &radar_config);
sender_message.Update();
return can_client_->SendSingleFrame({sender_message.CanFrame()});
}
bool ContiRadarCanbusComponent::Start() {
// 1. init and start the can card hardware
if (can_client_->Start() != ErrorCode::OK) {
return OnError("Failed to start can client");
}
AINFO << "Can client is started.";
if (ConfigureRadar() != ErrorCode::OK) {
return OnError("Failed to configure radar.");
}
AINFO << "The radar is successfully configured.";
// 2. start receive first then send
if (can_receiver_.Start() != ErrorCode::OK) {
return OnError("Failed to start can receiver.");
}
AINFO << "Can receiver is started.";
// last step: publish monitor messages
monitor_logger_buffer_.INFO("Canbus is started.");
return true;
}
void ContiRadarCanbusComponent::Stop() {
if (start_success_) {
can_receiver_.Stop();
can_client_->Stop();
}
}
// Send the error to monitor and return it
bool ContiRadarCanbusComponent::OnError(const std::string& error_msg) {
monitor_logger_buffer_.ERROR(error_msg);
AERROR << error_msg;
return false;
}
void ContiRadarCanbusComponent::PoseCallback(
const std::shared_ptr<LocalizationEstimate>& pose_msg) {
auto send_interval = conti_radar_conf_.radar_conf().input_send_interval();
uint64_t now_nsec = cyber::Time().Now().ToNanosecond();
if (last_nsec_ != 0 && (now_nsec - last_nsec_) < send_interval) {
return;
}
last_nsec_ = now_nsec;
Eigen::Quaterniond orientation_vehicle_world(
pose_msg->pose().orientation().qw(), pose_msg->pose().orientation().qx(),
pose_msg->pose().orientation().qy(), pose_msg->pose().orientation().qz());
Eigen::Matrix3d rotation_matrix =
orientation_vehicle_world.toRotationMatrix().inverse();
Eigen::Vector3d speed_v(pose_msg->pose().linear_velocity().x(),
pose_msg->pose().linear_velocity().y(),
pose_msg->pose().linear_velocity().z());
float speed = static_cast<float>((rotation_matrix * speed_v).y());
float yaw_rate = static_cast<float>(pose_msg->pose().angular_velocity().z() *
180.0f / M_PI);
AINFO << "radar speed:" << speed << ";yaw rate:" << yaw_rate;
MotionInputSpeed300 input_speed;
input_speed.SetSpeed(speed);
SenderMessage<ContiRadar> sender_message_speed(MotionInputSpeed300::ID,
&input_speed);
sender_message_speed.Update();
can_client_->SendSingleFrame({sender_message_speed.CanFrame()});
MotionInputYawRate301 input_yawrate;
input_yawrate.SetYawRate(yaw_rate);
SenderMessage<ContiRadar> sender_message_yawrate(MotionInputYawRate301::ID,
&input_yawrate);
sender_message_yawrate.Update();
can_client_->SendSingleFrame({sender_message_yawrate.CanFrame()});
}
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/BUILD
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("//tools/install:install.bzl", "install")
load("//tools:cpplint.bzl", "cpplint")
package(default_visibility = ["//visibility:public"])
install(
name = "install",
data_dest = "drivers/addition_data/conti_radar",
library_dest = "drivers/lib/conti_radar",
data = [
":runtime_data",
],
targets = [
":libconti_radar.so",
],
)
filegroup(
name = "runtime_data",
srcs = glob([
"conf/*.txt",
"conf/*.conf",
"dag/*.dag",
"launch/*.launch",
]),
)
cc_library(
name = "conti_radar_message_manager",
srcs = ["conti_radar_message_manager.cc"],
hdrs = ["conti_radar_message_manager.h"],
deps = [
"//modules/common/util:util_tool",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_sender",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/radar/conti_radar/protocol:drivers_conti_radar_protocol",
],
)
cc_library(
name = "conti_radar_canbus_lib",
srcs = ["conti_radar_canbus_component.cc"],
hdrs = ["conti_radar_canbus_component.h"],
copts = ['-DMODULE_NAME=\\"conti_radar\\"'],
alwayslink = True,
deps = [
":conti_radar_message_manager",
"//cyber",
"//modules/common/adapters:adapter_gflags",
"//modules/common/monitor_log",
"//modules/drivers/canbus/can_client:can_client_factory",
"//modules/drivers/canbus/can_comm:can_receiver",
"//modules/drivers/canbus/can_comm:message_manager_base",
"//modules/drivers/canbus/proto:sensor_canbus_conf_cc_proto",
"//modules/drivers/radar/conti_radar/protocol:drivers_conti_radar_protocol",
"//modules/common_msgs/localization_msgs:localization_cc_proto",
"//modules/common_msgs/localization_msgs:pose_cc_proto",
"@eigen",
],
)
cc_binary(
name = "libconti_radar.so",
linkshared = True,
linkstatic = True,
deps = [":conti_radar_canbus_lib"],
)
cpplint()
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/proto/conti_radar_conf.proto
|
syntax = "proto2";
package apollo.drivers.conti_radar;
import "modules/common_msgs/sensor_msgs/conti_radar.proto";
import "modules/common_msgs/drivers_msgs/can_card_parameter.proto";
message CanConf {
optional apollo.drivers.canbus.CANCardParameter can_card_parameter = 1;
optional bool enable_debug_mode = 2 [default = false];
optional bool enable_receiver_log = 3 [default = false];
optional bool enable_sender_log = 4 [default = false];
}
message RadarConf {
optional bool max_distance_valid = 1 [default = false];
optional bool sensor_id_valid = 2 [default = false];
optional bool radar_power_valid = 3 [default = false];
optional bool output_type_valid = 4 [default = true];
optional bool send_quality_valid = 5 [default = true];
optional bool send_ext_info_valid = 6 [default = true];
optional bool sort_index_valid = 7 [default = false];
optional bool store_in_nvm_valid = 8 [default = true];
optional bool ctrl_relay_valid = 9 [default = false];
optional bool rcs_threshold_valid = 10 [default = true];
optional uint32 max_distance = 11 [default = 248];
optional uint32 sensor_id = 12 [default = 0];
optional RadarState_201.OutputType output_type = 13 [default = OUTPUT_TYPE_OBJECTS];
optional uint32 radar_power = 14 [default = 0];
optional uint32 ctrl_relay = 15 [default = 0];
optional bool send_ext_info = 16 [default = true];
optional bool send_quality = 17 [default = true];
optional uint32 sort_index = 18 [default = 0];
optional uint32 store_in_nvm = 19 [default = 1];
optional RadarState_201.RcsThreshold rcs_threshold = 20 [default = RCS_THRESHOLD_STANDARD];
optional uint64 input_send_interval = 21;
}
message ContiRadarConf {
optional CanConf can_conf = 1;
optional RadarConf radar_conf = 2;
optional string radar_channel = 3;
}
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/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 = "conti_radar_conf_cc_proto",
deps = [
":conti_radar_conf_proto",
],
)
proto_library(
name = "conti_radar_conf_proto",
srcs = ["conti_radar_conf.proto"],
deps = [
"//modules/common_msgs/sensor_msgs:conti_radar_proto",
"//modules/common_msgs/drivers_msgs:can_card_parameter_proto",
],
)
py_proto_library(
name = "conti_radar_conf_py_pb2",
deps = [
":conti_radar_conf_proto",
"//modules/common_msgs/sensor_msgs:conti_radar_py_pb2",
"//modules/common_msgs/drivers_msgs:can_card_parameter_py_pb2",
],
)
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/launch/conti_radar.launch
|
<cyber>
<module>
<name>conti_radar</name>
<dag_conf>/apollo/modules/drivers/radar/conti_radar/dag/conti_radar.dag</dag_conf>
<process_name>conti_radar</process_name>
</module>
</cyber>
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/dag/conti_radar.dag
|
module_config {
module_library : "/apollo/bazel-bin/modules/drivers/radar/conti_radar/libconti_radar.so"
components {
class_name : "ContiRadarCanbusComponent"
config {
name: "conti_radar_front"
config_file_path: "/apollo/modules/drivers/radar/conti_radar/conf/radar_front_conf.pb.txt"
}
}
components {
class_name : "ContiRadarCanbusComponent"
config {
name: "conti_radar_rear"
config_file_path: "/apollo/modules/drivers/radar/conti_radar/conf/radar_rear_conf.pb.txt"
}
}
}
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/radar_config_200.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 "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/drivers/radar/conti_radar/proto/conti_radar_conf.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
using apollo::drivers::conti_radar::RadarConf;
class RadarConfig200
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
RadarConfig200();
~RadarConfig200();
/**
* @brief get the data period
* @return the value of data period
*/
uint32_t GetPeriod() const override;
/**
* @brief update the data
* @param data a pointer to the data to be updated
*/
void UpdateData(uint8_t* data) override;
/**
* @brief reset the private variables
*/
void Reset() override;
RadarConfig200* set_max_distance_valid(bool valid);
RadarConfig200* set_sensor_id_valid(bool valid);
RadarConfig200* set_radar_power_valid(bool valid);
RadarConfig200* set_output_type_valid(bool valid);
RadarConfig200* set_send_quality_valid(bool valid);
RadarConfig200* set_send_ext_info_valid(bool valid);
RadarConfig200* set_sort_index_valid(bool valid);
RadarConfig200* set_store_in_nvm_valid(bool valid);
RadarConfig200* set_ctrl_relay_valid(bool valid);
RadarConfig200* set_rcs_threshold_valid(bool valid);
RadarConfig200* set_max_distance(uint16_t data);
RadarConfig200* set_sensor_id(uint8_t data);
RadarConfig200* set_output_type(RadarState_201::OutputType type);
RadarConfig200* set_radar_power(uint8_t data);
RadarConfig200* set_ctrl_relay(uint8_t data);
RadarConfig200* set_send_ext_info(uint8_t data);
RadarConfig200* set_send_quality(uint8_t data);
RadarConfig200* set_sort_index(uint8_t data);
RadarConfig200* set_store_in_nvm(uint8_t data);
RadarConfig200* set_rcs_threshold(RadarState_201::RcsThreshold rcs_theshold);
RadarConfig200* set_radar_conf(RadarConf radar_conf);
RadarConf radar_conf();
void set_max_distance_valid_p(uint8_t* data, bool valid);
void set_sensor_id_valid_p(uint8_t* data, bool valid);
void set_radar_power_valid_p(uint8_t* data, bool valid);
void set_output_type_valid_p(uint8_t* data, bool valid);
void set_send_quality_valid_p(uint8_t* data, bool valid);
void set_send_ext_info_valid_p(uint8_t* data, bool valid);
void set_sort_index_valid_p(uint8_t* data, bool valid);
void set_store_in_nvm_valid_p(uint8_t* data, bool valid);
void set_ctrl_relay_valid_p(uint8_t* data, bool valid);
void set_rcs_threshold_valid_p(uint8_t* data, bool valid);
void set_max_distance_p(uint8_t* data, uint16_t value);
void set_sensor_id_p(uint8_t* data, uint8_t value);
void set_output_type_p(uint8_t* data, RadarState_201::OutputType type);
void set_radar_power_p(uint8_t* data, uint8_t value);
void set_ctrl_relay_p(uint8_t* data, uint8_t value);
void set_send_ext_info_p(uint8_t* data, uint8_t value);
void set_send_quality_p(uint8_t* data, uint8_t value);
void set_sort_index_p(uint8_t* data, uint8_t value);
void set_store_in_nvm_p(uint8_t* data, uint8_t value);
void set_rcs_threshold_p(
uint8_t* data, RadarState_201::RcsThreshold rcs_theshold);
private:
RadarConf radar_conf_;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/radar_state_201.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 "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
class RadarState201 : public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
RadarState201();
void Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const override;
private:
int max_dist(const std::uint8_t* bytes, int32_t length) const;
int radar_power(const std::uint8_t* bytes, int32_t length) const;
RadarState_201::OutputType output_type(
const std::uint8_t* bytes, int32_t length) const;
RadarState_201::RcsThreshold rcs_threshold(
const std::uint8_t* bytes, int32_t length) const;
bool send_quality(const std::uint8_t* bytes, int32_t length) const;
bool send_ext_info(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/object_general_info_60b.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 "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
class ObjectGeneralInfo60B
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
ObjectGeneralInfo60B();
void Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const override;
private:
int object_id(const std::uint8_t* bytes, int32_t length) const;
double longitude_dist(const std::uint8_t* bytes, int32_t length) const;
double lateral_dist(const std::uint8_t* bytes, int32_t length) const;
double longitude_vel(const std::uint8_t* bytes, int32_t length) const;
double lateral_vel(const std::uint8_t* bytes, int32_t length) const;
double rcs(const std::uint8_t* bytes, int32_t length) const;
int dynprop(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/object_extended_info_60d.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 "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
class ObjectExtendedInfo60D
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
ObjectExtendedInfo60D();
void Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const override;
private:
int object_id(const std::uint8_t* bytes, int32_t length) const;
double longitude_accel(const std::uint8_t* bytes, int32_t length) const;
double lateral_accel(const std::uint8_t* bytes, int32_t length) const;
int obstacle_class(const std::uint8_t* bytes, int32_t length) const;
double oritation_angle(const std::uint8_t* bytes, int32_t length) const;
double object_length(const std::uint8_t* bytes, int32_t length) const;
double object_width(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/motion_input_speed_300.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 <cmath>
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
#include "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/drivers/radar/conti_radar/proto/conti_radar_conf.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
using apollo::drivers::conti_radar::RadarConf;
class MotionInputSpeed300
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
MotionInputSpeed300();
~MotionInputSpeed300();
/**
* @brief get the data period
* @return the value of data period
*/
uint32_t GetPeriod() const override;
/**
* @brief update the data
* @param data a pointer to the data to be updated
*/
void UpdateData(uint8_t* data) override;
/**
* @brief reset the private variables
*/
void Reset() override;
void SetSpeed(const float& speed);
private:
float speed_ = NAN;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/motion_input_yawrate_301.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/drivers/radar/conti_radar/protocol/motion_input_yawrate_301.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
using apollo::drivers::canbus::Byte;
const uint32_t MotionInputYawRate301::ID = 0x301;
MotionInputYawRate301::MotionInputYawRate301() {}
MotionInputYawRate301::~MotionInputYawRate301() {}
uint32_t MotionInputYawRate301::GetPeriod() const {
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
/**
* @brief update the data
* @param data a pointer to the data to be updated
*/
void MotionInputYawRate301::UpdateData(uint8_t* data) {
if (std::isnan(yaw_rate_)) {
AWARN << "yaw_rate is nan";
return;
}
// Due to radar 408 manual: max 327.68, res 0.01, unit:deg/s
uint32_t yaw_rate_value = static_cast<uint32_t>((yaw_rate_ + 327.68) * 100);
Byte yaw_rate_low(data);
yaw_rate_low.set_value(
static_cast<unsigned char>((yaw_rate_value & 0xFF00) >> 8), 0, 8);
Byte yaw_rate_high(data + 1);
yaw_rate_high.set_value(static_cast<unsigned char>(yaw_rate_value & 0x00FF),
0, 8);
}
/**
* @brief reset the private variables
*/
void MotionInputYawRate301::Reset() { yaw_rate_ = NAN; }
void MotionInputYawRate301::SetYawRate(const float& yaw_rate) {
yaw_rate_ = yaw_rate;
}
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/radar_state_201.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/drivers/radar/conti_radar/protocol/radar_state_201.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::canbus::Byte;
RadarState201::RadarState201() {}
const uint32_t RadarState201::ID = 0x201;
void RadarState201::Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const {
auto state = conti_radar->mutable_radar_state();
state->set_max_distance(max_dist(bytes, length));
state->set_output_type(output_type(bytes, length));
state->set_rcs_threshold(rcs_threshold(bytes, length));
state->set_radar_power(radar_power(bytes, length));
state->set_send_quality(send_quality(bytes, length));
state->set_send_ext_info(send_ext_info(bytes, length));
}
int RadarState201::max_dist(const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 1);
uint32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
uint32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
int ret = x * 2;
return ret;
}
int RadarState201::radar_power(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
uint32_t x = t0.get_byte(0, 2);
Byte t1(bytes + 4);
uint32_t t = t1.get_byte(7, 1);
x <<= 1;
x |= t;
int ret = x;
return ret;
}
RadarState_201::OutputType RadarState201::output_type(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(2, 2);
switch (x) {
case 0x0:
return RadarState_201::OUTPUT_TYPE_NONE;
case 0x1:
return RadarState_201::OUTPUT_TYPE_OBJECTS;
case 0x2:
return RadarState_201::OUTPUT_TYPE_CLUSTERS;
default:
return RadarState_201::OUTPUT_TYPE_ERROR;
}
}
RadarState_201::RcsThreshold RadarState201::rcs_threshold(
const std::uint8_t* bytes, int32_t length) const {
Byte t0(bytes + 7);
uint32_t x = t0.get_byte(2, 3);
switch (x) {
case 0x0:
return RadarState_201::RCS_THRESHOLD_STANDARD;
case 0x1:
return RadarState_201::RCS_THRESHOLD_HIGH_SENSITIVITY;
default:
return RadarState_201::RCS_THRESHOLD_ERROR;
}
}
bool RadarState201::send_quality(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(4, 1);
bool ret = (x == 0x1);
return ret;
}
bool RadarState201::send_ext_info(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(5, 1);
bool ret = (x == 0x1);
return ret;
}
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/radar_config_200.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/drivers/radar/conti_radar/protocol/radar_config_200.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
using apollo::drivers::canbus::Byte;
const uint32_t RadarConfig200::ID = 0x200;
RadarConfig200::RadarConfig200() {}
RadarConfig200::~RadarConfig200() {}
uint32_t RadarConfig200::GetPeriod() const {
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
/**
* @brief update the data
* @param data a pointer to the data to be updated
*/
void RadarConfig200::UpdateData(uint8_t* data) {
set_max_distance_valid_p(data, radar_conf_.max_distance_valid());
set_sensor_id_valid_p(data, radar_conf_.sensor_id_valid());
set_radar_power_valid_p(data, radar_conf_.radar_power_valid());
set_output_type_valid_p(data, radar_conf_.output_type_valid());
set_send_quality_valid_p(data, radar_conf_.send_quality_valid());
set_send_ext_info_valid_p(data, radar_conf_.send_ext_info_valid());
set_sort_index_valid_p(data, radar_conf_.sort_index_valid());
set_store_in_nvm_valid_p(data, radar_conf_.store_in_nvm_valid());
set_ctrl_relay_valid_p(data, radar_conf_.ctrl_relay_valid());
set_rcs_threshold_valid_p(data, radar_conf_.rcs_threshold_valid());
set_max_distance_p(data, static_cast<uint16_t>(radar_conf_.max_distance()));
set_sensor_id_p(data, static_cast<uint8_t>(radar_conf_.sensor_id()));
set_output_type_p(data, radar_conf_.output_type());
set_radar_power_p(data, static_cast<uint8_t>(radar_conf_.radar_power()));
set_ctrl_relay_p(data, static_cast<uint8_t>(radar_conf_.ctrl_relay()));
set_send_ext_info_p(data, radar_conf_.send_ext_info());
set_send_quality_p(data, radar_conf_.send_quality());
set_sort_index_p(data, static_cast<uint8_t>(radar_conf_.sort_index()));
set_store_in_nvm_p(data, static_cast<uint8_t>(radar_conf_.store_in_nvm()));
set_rcs_threshold_p(data, radar_conf_.rcs_threshold());
}
/**
* @brief reset the private variables
*/
void RadarConfig200::Reset() {
radar_conf_.set_max_distance_valid(false);
radar_conf_.set_sensor_id_valid(false);
radar_conf_.set_radar_power_valid(false);
radar_conf_.set_output_type_valid(true);
radar_conf_.set_send_quality_valid(true);
radar_conf_.set_send_ext_info_valid(true);
radar_conf_.set_sort_index_valid(false);
radar_conf_.set_store_in_nvm_valid(true);
radar_conf_.set_ctrl_relay_valid(false);
radar_conf_.set_rcs_threshold_valid(true);
radar_conf_.set_max_distance(125);
radar_conf_.set_sensor_id(0);
radar_conf_.set_output_type(RadarState_201::OUTPUT_TYPE_NONE);
radar_conf_.set_radar_power(0);
radar_conf_.set_ctrl_relay(0);
radar_conf_.set_send_ext_info(1);
radar_conf_.set_send_quality(1);
radar_conf_.set_sort_index(0);
radar_conf_.set_store_in_nvm(1);
radar_conf_.set_rcs_threshold(RadarState_201::RCS_THRESHOLD_STANDARD);
}
RadarConf RadarConfig200::radar_conf() { return radar_conf_; }
RadarConfig200* RadarConfig200::set_radar_conf(RadarConf radar_conf) {
radar_conf_.CopyFrom(radar_conf);
return this;
}
RadarConfig200* RadarConfig200::set_max_distance_valid(bool valid) {
radar_conf_.set_max_distance_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_sensor_id_valid(bool valid) {
radar_conf_.set_sensor_id_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_radar_power_valid(bool valid) {
radar_conf_.set_radar_power_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_output_type_valid(bool valid) {
radar_conf_.set_output_type_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_send_quality_valid(bool valid) {
radar_conf_.set_send_quality_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_send_ext_info_valid(bool valid) {
radar_conf_.set_send_ext_info_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_sort_index_valid(bool valid) {
radar_conf_.set_sort_index_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_store_in_nvm_valid(bool valid) {
radar_conf_.set_store_in_nvm_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_ctrl_relay_valid(bool valid) {
radar_conf_.set_ctrl_relay_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_rcs_threshold_valid(bool valid) {
radar_conf_.set_rcs_threshold_valid(valid);
return this;
}
RadarConfig200* RadarConfig200::set_max_distance(uint16_t data) {
radar_conf_.set_max_distance(data);
return this;
}
RadarConfig200* RadarConfig200::set_sensor_id(uint8_t data) {
radar_conf_.set_sensor_id(data);
return this;
}
RadarConfig200* RadarConfig200::set_output_type(
RadarState_201::OutputType type) {
radar_conf_.set_output_type(type);
return this;
}
RadarConfig200* RadarConfig200::set_radar_power(uint8_t data) {
radar_conf_.set_radar_power(data);
return this;
}
RadarConfig200* RadarConfig200::set_ctrl_relay(uint8_t data) {
radar_conf_.set_ctrl_relay(data);
return this;
}
RadarConfig200* RadarConfig200::set_send_ext_info(uint8_t data) {
radar_conf_.set_send_ext_info(data);
return this;
}
RadarConfig200* RadarConfig200::set_send_quality(uint8_t data) {
radar_conf_.set_send_quality(data);
return this;
}
RadarConfig200* RadarConfig200::set_sort_index(uint8_t data) {
radar_conf_.set_sort_index(data);
return this;
}
RadarConfig200* RadarConfig200::set_store_in_nvm(uint8_t data) {
radar_conf_.set_store_in_nvm(data);
return this;
}
RadarConfig200* RadarConfig200::set_rcs_threshold(
RadarState_201::RcsThreshold rcs_theshold) {
radar_conf_.set_rcs_threshold(rcs_theshold);
return this;
}
void RadarConfig200::set_max_distance_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_bit_1(0);
} else {
frame.set_bit_0(0);
}
}
void RadarConfig200::set_sensor_id_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_bit_1(1);
} else {
frame.set_bit_0(1);
}
}
void RadarConfig200::set_radar_power_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 2, 1);
} else {
frame.set_value(0, 2, 1);
}
}
void RadarConfig200::set_output_type_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 3, 1);
} else {
frame.set_value(0, 3, 1);
}
}
void RadarConfig200::set_send_quality_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 4, 1);
} else {
frame.set_value(0, 4, 1);
}
}
void RadarConfig200::set_send_ext_info_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 5, 1);
} else {
frame.set_value(0, 5, 1);
}
}
void RadarConfig200::set_sort_index_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 6, 1);
} else {
frame.set_value(0, 6, 1);
}
}
void RadarConfig200::set_store_in_nvm_valid_p(uint8_t* data, bool valid) {
Byte frame(data);
if (valid) {
frame.set_value(1, 7, 1);
} else {
frame.set_value(0, 7, 1);
}
}
void RadarConfig200::set_ctrl_relay_valid_p(uint8_t* data, bool valid) {
Byte frame(data + 5);
if (valid) {
frame.set_bit_1(0);
} else {
frame.set_bit_0(0);
}
}
void RadarConfig200::set_rcs_threshold_valid_p(uint8_t* data, bool valid) {
Byte frame(data + 6);
if (valid) {
frame.set_bit_1(0);
} else {
frame.set_bit_0(0);
}
}
void RadarConfig200::set_max_distance_p(uint8_t* data, uint16_t value) {
value /= 2;
uint8_t low = static_cast<uint8_t>(value >> 2);
Byte frame_low(data + 1);
frame_low.set_value(low, 0, 8);
uint8_t high = static_cast<uint8_t>(value << 6);
high &= 0xc0;
Byte frame_high(data + 2);
frame_high.set_value(high, 0, 8);
}
void RadarConfig200::set_sensor_id_p(uint8_t* data, uint8_t value) {
Byte frame(data + 4);
frame.set_value(value, 0, 3);
}
void RadarConfig200::set_output_type_p(
uint8_t* data, RadarState_201::OutputType type) {
Byte frame(data + 4);
uint8_t value = static_cast<uint8_t>(type);
frame.set_value(value, 3, 2);
}
void RadarConfig200::set_radar_power_p(uint8_t* data, uint8_t value) {
Byte frame(data + 4);
frame.set_value(value, 5, 3);
}
void RadarConfig200::set_ctrl_relay_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 1, 1);
}
void RadarConfig200::set_send_ext_info_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 3, 1);
}
void RadarConfig200::set_send_quality_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 2, 1);
}
void RadarConfig200::set_sort_index_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 4, 3);
}
void RadarConfig200::set_store_in_nvm_p(uint8_t* data, uint8_t value) {
Byte frame(data + 5);
frame.set_value(value, 7, 1);
}
void RadarConfig200::set_rcs_threshold_p(
uint8_t* data, RadarState_201::RcsThreshold rcs_threshold) {
Byte frame(data + 6);
uint8_t value = static_cast<uint8_t>(rcs_threshold);
frame.set_value(value, 1, 3);
}
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/object_list_status_60a.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 "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
class ObjectListStatus60A
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
ObjectListStatus60A();
void Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const override;
private:
int num_of_objects(const std::uint8_t* bytes, int32_t length) const;
int meas_counter(const std::uint8_t* bytes, int32_t length) const;
int interface_version(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/const_vars.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
namespace apollo {
namespace drivers {
namespace conti_radar {
const int CONTIID_START = 0x600;
const int CONTIID_END = 0x702;
const int WAIT_TIME = 4000;
// Try this many times when receiving using bcan, by default.
const int BCAN_RECV_TRIES = 4;
const int RADAR_CONFIG = 0x200;
const int RADAR_STATE = 0x201;
const int CAN_BUFFER_NUM = 20;
const int CANBYTE = 13;
const int ETHER_WAIT = 5000000;
const int DISCONNECT_WAIT = 5;
// cluster quality
const double LINEAR_RMS[32] = {0.005, 0.006, 0.008, 0.011, 0.014, 0.018, 0.023,
0.029, 0.038, 0.049, 0.063, 0.081, 0.105, 0.135,
0.174, 0.224, 0.288, 0.371, 0.478, 0.616, 0.794,
1.023, 1.317, 1.697, 2.187, 2.817, 3.630, 4.676,
6.025, 7.762, 10.000, 100.00};
const double ANGLE_RMS[32] = {
0.005, 0.007, 0.010, 0.014, 0.020, 0.029, 0.041, 0.058,
0.082, 0.116, 0.165, 0.234, 0.332, 0.471, 0.669, 0.949,
1.346, 1.909, 2.709, 3.843, 5.451, 7.734, 10.971, 15.565,
22.061, 31.325, 44.439, 63.044, 69.437, 126.881, 180.000, 360.00};
const double PROBOFEXIST[8] = {0.00, 0.25, 0.5, 0.75, 0.90, 0.99, 0.999, 1.0};
const double CLUSTER_DIST_RES = 0.2;
const double CLUSTER_DIST_LONG_MIN = -500;
const double CLUSTER_DIST_LAT_MIN = -102.3;
const double CLUSTER_VREL_RES = 0.25;
const double CLUSTER_VREL_LONG_MIN = -128.0;
const double CLUSTER_VREL_LAT_MIN = -64.0;
const double CLUSTER_RCS_RES = 0.5;
const double CLUSTER_RCS = -64.0;
// Object general information
const double OBJECT_DIST_RES = 0.2;
const double OBJECT_DIST_LONG_MIN = -500;
const double OBJECT_DIST_LAT_MIN = -204.6;
const double OBJECT_VREL_RES = 0.25;
const double OBJECT_VREL_LONG_MIN = -128.0;
const double OBJECT_VREL_LAT_MIN = -64.0;
const double OBJECT_RCS_RES = 0.5;
const double OBJECT_RCS_MIN = -64.0;
// Object extended information
const double OBJECT_AREL_RES = 0.01;
const double OBJECT_AREL_LONG_MIN = -10.0;
const double OBJECT_AREL_LAT_MIN = -2.5;
const double OBJECT_ORIENTATION_ANGEL_MIN = -180.0;
const double OBJECT_ORIENTATION_ANGEL_RES = 0.4;
const double OBJECT_WIDTH_RES = 0.2;
const double OBJECT_LENGTH_RES = 0.2;
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/object_quality_info_60c.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/drivers/radar/conti_radar/protocol/object_quality_info_60c.h"
#include "modules/drivers/radar/conti_radar/protocol/const_vars.h"
#include "glog/logging.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::canbus::Byte;
ObjectQualityInfo60C::ObjectQualityInfo60C() {}
const uint32_t ObjectQualityInfo60C::ID = 0x60C;
void ObjectQualityInfo60C::Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const {
int obj_id = object_id(bytes, length);
for (int i = 0; i < conti_radar->contiobs_size(); ++i) {
if (conti_radar->contiobs(i).obstacle_id() == obj_id) {
auto obs = conti_radar->mutable_contiobs(i);
obs->set_longitude_dist_rms(
LINEAR_RMS[longitude_dist_rms(bytes, length)]);
obs->set_lateral_dist_rms(LINEAR_RMS[lateral_dist_rms(bytes, length)]);
obs->set_longitude_vel_rms(LINEAR_RMS[longitude_vel_rms(bytes, length)]);
obs->set_lateral_vel_rms(LINEAR_RMS[lateral_vel_rms(bytes, length)]);
obs->set_longitude_accel_rms(
LINEAR_RMS[longitude_accel_rms(bytes, length)]);
obs->set_lateral_accel_rms(LINEAR_RMS[lateral_accel_rms(bytes, length)]);
obs->set_oritation_angle_rms(
ANGLE_RMS[oritation_angle_rms(bytes, length)]);
obs->set_probexist(PROBOFEXIST[probexist(bytes, length)]);
obs->set_meas_state(meas_state(bytes, length));
break;
}
}
}
int ObjectQualityInfo60C::object_id(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
int32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::longitude_dist_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(3, 5);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::lateral_dist_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
int32_t x = t0.get_byte(0, 3);
Byte t1(bytes + 2);
int32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::longitude_vel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(1, 5);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::lateral_vel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
int32_t x = t0.get_byte(0, 1);
Byte t1(bytes + 3);
int32_t t = t1.get_byte(4, 4);
x <<= 4;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::longitude_accel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 3);
int32_t x = t0.get_byte(0, 4);
Byte t1(bytes + 4);
int32_t t = t1.get_byte(7, 1);
x <<= 1;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::lateral_accel_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(2, 5);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::oritation_angle_rms(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
int32_t x = t0.get_byte(0, 2);
Byte t1(bytes + 5);
int32_t t = t1.get_byte(5, 3);
x <<= 3;
x |= t;
int ret = x;
return ret;
}
int ObjectQualityInfo60C::probexist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(5, 3);
int ret = x;
return ret;
}
int ObjectQualityInfo60C::meas_state(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
int32_t x = t0.get_byte(2, 3);
int ret = x;
return ret;
}
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/motion_input_speed_300.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/drivers/radar/conti_radar/protocol/motion_input_speed_300.h"
#include "modules/drivers/canbus/common/byte.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
using apollo::drivers::canbus::Byte;
const uint32_t MotionInputSpeed300::ID = 0x300;
MotionInputSpeed300::MotionInputSpeed300() {}
MotionInputSpeed300::~MotionInputSpeed300() {}
uint32_t MotionInputSpeed300::GetPeriod() const {
static const uint32_t PERIOD = 20 * 1000;
return PERIOD;
}
/**
* @brief update the data
* @param data a pointer to the data to be updated
*/
void MotionInputSpeed300::UpdateData(uint8_t* data) {
if (std::isnan(speed_)) {
AWARN << "speed is nan";
return;
}
uint32_t speed_direction = 0;
if (fabs(speed_) < 0.02) {
speed_direction = 0;
} else if (speed_ < 0) {
speed_direction = 2;
} else {
speed_direction = 1;
}
uint32_t speed_value = static_cast<uint32_t>(fabs(speed_) / 0.02);
Byte frame_speed_direction(data);
frame_speed_direction.set_value(
static_cast<unsigned char>((speed_direction << 6) & 0x00C0) |
static_cast<unsigned char>((speed_value & 0x1F00) >> 8),
0, 8);
Byte frame_speed(data + 1);
frame_speed.set_value(static_cast<unsigned char>(speed_value & 0x00FF), 0, 8);
}
/**
* @brief reset the private variables
*/
void MotionInputSpeed300::Reset() { speed_ = NAN; }
void MotionInputSpeed300::SetSpeed(const float& speed) { speed_ = speed; }
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/cluster_quality_info_702.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 "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
class ClusterQualityInfo702
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
ClusterQualityInfo702();
void Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const override;
private:
int target_id(const std::uint8_t* bytes, int32_t length) const;
int longitude_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int longitude_vel_rms(const std::uint8_t* bytes, int32_t length) const;
int pdh0(const std::uint8_t* bytes, int32_t length) const;
int ambig_state(const std::uint8_t* bytes, int32_t length) const;
int invalid_state(const std::uint8_t* bytes, int32_t length) const;
int lateral_vel_rms(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/cluster_general_info_701.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/drivers/radar/conti_radar/protocol/cluster_general_info_701.h"
#include "glog/logging.h"
#include "cyber/time/time.h"
#include "modules/drivers/canbus/common/byte.h"
#include "modules/drivers/canbus/common/canbus_consts.h"
#include "modules/drivers/radar/conti_radar/protocol/const_vars.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::canbus::Byte;
ClusterGeneralInfo701::ClusterGeneralInfo701() {}
const uint32_t ClusterGeneralInfo701::ID = 0x701;
void ClusterGeneralInfo701::Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const {
auto obs = conti_radar->add_contiobs();
obs->set_clusterortrack(true);
obs->set_obstacle_id(obstacle_id(bytes, length));
obs->set_longitude_dist(longitude_dist(bytes, length));
obs->set_lateral_dist(lateral_dist(bytes, length));
obs->set_longitude_vel(longitude_vel(bytes, length));
obs->set_lateral_vel(lateral_vel(bytes, length));
obs->set_rcs(rcs(bytes, length));
obs->set_dynprop(dynprop(bytes, length));
double timestamp = apollo::cyber::Time::Now().ToSecond();
auto header = obs->mutable_header();
header->CopyFrom(conti_radar->header());
header->set_timestamp_sec(timestamp);
}
int ClusterGeneralInfo701::obstacle_id(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes);
uint32_t x = t0.get_byte(0, 8);
int ret = x;
return ret;
}
double ClusterGeneralInfo701::longitude_dist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 1);
uint32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 2);
uint32_t t = t1.get_byte(3, 5);
x <<= 5;
x |= t;
double ret = x * CLUSTER_DIST_RES + CLUSTER_DIST_LONG_MIN;
return ret;
}
double ClusterGeneralInfo701::lateral_dist(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 2);
uint32_t x = t0.get_byte(0, 2);
Byte t1(bytes + 3);
uint32_t t = t1.get_byte(0, 8);
x <<= 8;
x |= t;
double ret = x * CLUSTER_DIST_RES + CLUSTER_DIST_LAT_MIN;
return ret;
}
double ClusterGeneralInfo701::longitude_vel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 4);
uint32_t x = t0.get_byte(0, 8);
Byte t1(bytes + 5);
uint32_t t = t1.get_byte(6, 2);
x <<= 2;
x |= t;
double ret = x * CLUSTER_VREL_RES + CLUSTER_VREL_LONG_MIN;
return ret;
}
double ClusterGeneralInfo701::lateral_vel(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 5);
uint32_t x = t0.get_byte(0, 6);
Byte t1(bytes + 6);
uint32_t t = t1.get_byte(5, 3);
x <<= 3;
x |= t;
double ret = x * CLUSTER_VREL_RES + CLUSTER_VREL_LAT_MIN;
return ret;
}
double ClusterGeneralInfo701::rcs(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 7);
uint32_t x = t0.get_byte(0, 8);
double ret = x * CLUSTER_RCS_RES + CLUSTER_RCS;
return ret;
}
int ClusterGeneralInfo701::dynprop(const std::uint8_t* bytes,
int32_t length) const {
Byte t0(bytes + 6);
uint32_t x = t0.get_byte(0, 3);
int ret = x;
return ret;
}
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/cluster_general_info_701.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 "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
class ClusterGeneralInfo701
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
ClusterGeneralInfo701();
void Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const override;
private:
int obstacle_id(const std::uint8_t* bytes, int32_t length) const;
double longitude_dist(const std::uint8_t* bytes, int32_t length) const;
double lateral_dist(const std::uint8_t* bytes, int32_t length) const;
double longitude_vel(const std::uint8_t* bytes, int32_t length) const;
double lateral_vel(const std::uint8_t* bytes, int32_t length) const;
double rcs(const std::uint8_t* bytes, int32_t length) const;
int dynprop(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar
|
apollo_public_repos/apollo/modules/drivers/radar/conti_radar/protocol/object_quality_info_60c.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 "modules/drivers/canbus/can_comm/protocol_data.h"
#include "modules/common_msgs/sensor_msgs/conti_radar.pb.h"
namespace apollo {
namespace drivers {
namespace conti_radar {
using apollo::drivers::ContiRadar;
class ObjectQualityInfo60C
: public apollo::drivers::canbus::ProtocolData<ContiRadar> {
public:
static const uint32_t ID;
ObjectQualityInfo60C();
void Parse(const std::uint8_t* bytes, int32_t length,
ContiRadar* conti_radar) const override;
private:
int object_id(const std::uint8_t* bytes, int32_t length) const;
int longitude_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_dist_rms(const std::uint8_t* bytes, int32_t length) const;
int longitude_vel_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_vel_rms(const std::uint8_t* bytes, int32_t length) const;
int longitude_accel_rms(const std::uint8_t* bytes, int32_t length) const;
int lateral_accel_rms(const std::uint8_t* bytes, int32_t length) const;
int oritation_angle_rms(const std::uint8_t* bytes, int32_t length) const;
int probexist(const std::uint8_t* bytes, int32_t length) const;
int meas_state(const std::uint8_t* bytes, int32_t length) const;
};
} // namespace conti_radar
} // namespace drivers
} // namespace apollo
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.