cmake官网正常是上不去的,需要fq
syntax = "proto2";
import "std_msgs.proto";
package dispensing.machine_control;
message Wheel{
optional float wheel_rpm = 1;
optional float wheel_angle = 2;
optional float wheel_distance = 3;
repeated std_msgs.Header header = 4;
}
message Header {
optional uint32 seq = 1;
optional uint64 stamp = 2;
optional string frame_id = 3;
}
message IoInputStatus{
optional float io = 1;
}
/*set_*/
//ROS
deviceInfoBasic.voltage = bms_data->Voltage_of_pack;
//Cyber
deviceInfoBasic.set_voltage(bms_data->voltage_of_pack());
//对于string类型,提供一个mutable_方法,返回变量值的可修改指针
/* 针对repeated变量 */
message SingleModuleStu{
optional int32 module_index = 1;
repeated int32 status = 2;
}
//获取repeated变量的大小(_size)
int nSize = motor_info->status_size();
//通过下脚标访问其中的数据成员组
int nSize = motor_info->status_size();
int16_t mAddr = 0x2002;
if(nSize <= 0)
{
return;
}
m_motor_num = nSize;
for(int j = 0; j < nSize*2; j += 2)
{
m_motor_err_split_info[j] = (m_motor_err_info[j/2] >> 16) & 0xFFFF;
m_motor_err_split_info[j+1] = (m_motor_err_info[j/2]) & 0xFFFF;
}
//通过下脚标返回其中的成员的mutable_的方法
inline ::std::string* mutable_name();
//_add方法:增加一个成员(如下)
为了方便特意将geometry_msgs、std_msgs从.msg文件改写成了同名的.proto文件
// geometry_msgs.proto 文件部分内容
message Twist{
repeated Vector3 linear = 1;
repeated Vector3 angular = 2;
}
message Vector3 {
optional double x = 1;
optional double y = 2;
optional double z = 3;
}
message PoseStamped {
repeated std_msgs.Header header = 1;
repeated Pose pose = 2;
}
geometry_msgs::Twist twist;
twist.add_linear()->set_x(0);
twist.add_linear()->set_y(0);
twist.add_linear()->set_z(0);
twist.add_angular()->set_x(0);
twist.add_angular()->set_y(0);
twist.add_angular()->set_z(0);
geometry_msgs::Twist twist;
geometry_msgs::Vector3* linear;
geometry_msgs::Vector3* angular;
linear = twist.add_linear();
angular = twist.add_angular();
linear->set_x(0);
linear->set_y(0);
linear->set_z(0);
angular->set_x(0);
angular->set_y(0);
angular->set_z(0);
#前期可以先用这个方法
aarch64-linux-gnu-strip machine_control
#后续版本稳定后可以将交叉编译的模式由debug改为release
Protobuf使用手册
ProtoBuf3 C++使用篇
protobuf repeated类型的使用
Protobuf 的 proto3 与 proto2 的区别
Apollo Cyber RT操作系统学习记录(一)