Encode to png
This commit is contained in:
parent
19a0e63500
commit
1c6d5dfe5c
|
@ -182,7 +182,7 @@ void protobuf_AssignDesc_carla_5fprotocol_2eproto() {
|
|||
::google::protobuf::MessageFactory::generated_factory(),
|
||||
sizeof(EpisodeReady));
|
||||
Reward_descriptor_ = file->message_type(6);
|
||||
static const int Reward_offsets_[16] = {
|
||||
static const int Reward_offsets_[18] = {
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, player_x_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, player_y_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, speed_),
|
||||
|
@ -197,6 +197,8 @@ void protobuf_AssignDesc_carla_5fprotocol_2eproto() {
|
|||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, ori_x_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, ori_y_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, ori_z_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, img_width_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, img_height_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, image_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, depth_),
|
||||
};
|
||||
|
@ -283,14 +285,15 @@ void protobuf_AddDesc_carla_5fprotocol_2eproto() {
|
|||
"ection_Matrix\032&\n\021Projection_Matrix\022\021\n\tca"
|
||||
"m_param\030\001 \003(\002\032(\n\010Position\022\r\n\005pos_x\030\001 \002(\002"
|
||||
"\022\r\n\005pos_y\030\002 \002(\002\"\035\n\014EpisodeReady\022\r\n\005ready"
|
||||
"\030\001 \001(\010\"\252\002\n\006Reward\022\020\n\010player_x\030\001 \001(\002\022\020\n\010p"
|
||||
"\030\001 \001(\010\"\321\002\n\006Reward\022\020\n\010player_x\030\001 \001(\002\022\020\n\010p"
|
||||
"layer_y\030\002 \001(\002\022\r\n\005speed\030\003 \001(\002\022\025\n\rcollisio"
|
||||
"n_gen\030\004 \001(\002\022\025\n\rcollision_ped\030\005 \001(\002\022\025\n\rco"
|
||||
"llision_car\030\006 \001(\002\022\021\n\tintersect\030\007 \001(\002\022\021\n\t"
|
||||
"inertia_x\030\010 \001(\002\022\021\n\tinertia_y\030\t \001(\002\022\021\n\tin"
|
||||
"ertia_z\030\n \001(\002\022\021\n\ttimestamp\030\013 \001(\005\022\r\n\005ori_"
|
||||
"x\030\014 \001(\002\022\r\n\005ori_y\030\r \001(\002\022\r\n\005ori_z\030\016 \001(\002\022\r\n"
|
||||
"\005image\030\017 \003(\014\022\r\n\005depth\030\020 \003(\014", 707);
|
||||
"x\030\014 \001(\002\022\r\n\005ori_y\030\r \001(\002\022\r\n\005ori_z\030\016 \001(\002\022\021\n"
|
||||
"\timg_width\030\017 \002(\005\022\022\n\nimg_height\030\020 \002(\005\022\r\n\005"
|
||||
"image\030\021 \003(\014\022\r\n\005depth\030\022 \003(\014", 746);
|
||||
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
|
||||
"carla_protocol.proto", &protobuf_RegisterTypes);
|
||||
EpisodeStart::default_instance_ = new EpisodeStart();
|
||||
|
@ -2398,6 +2401,8 @@ const int Reward::kTimestampFieldNumber;
|
|||
const int Reward::kOriXFieldNumber;
|
||||
const int Reward::kOriYFieldNumber;
|
||||
const int Reward::kOriZFieldNumber;
|
||||
const int Reward::kImgWidthFieldNumber;
|
||||
const int Reward::kImgHeightFieldNumber;
|
||||
const int Reward::kImageFieldNumber;
|
||||
const int Reward::kDepthFieldNumber;
|
||||
#endif // !_MSC_VER
|
||||
|
@ -2435,6 +2440,8 @@ void Reward::SharedCtor() {
|
|||
ori_x_ = 0;
|
||||
ori_y_ = 0;
|
||||
ori_z_ = 0;
|
||||
img_width_ = 0;
|
||||
img_height_ = 0;
|
||||
::memset(_has_bits_, 0, sizeof(_has_bits_));
|
||||
}
|
||||
|
||||
|
@ -2483,8 +2490,8 @@ void Reward::Clear() {
|
|||
if (_has_bits_[0 / 32] & 255) {
|
||||
ZR_(player_x_, inertia_x_);
|
||||
}
|
||||
if (_has_bits_[8 / 32] & 16128) {
|
||||
ZR_(inertia_y_, ori_z_);
|
||||
if (_has_bits_[8 / 32] & 65280) {
|
||||
ZR_(inertia_y_, img_height_);
|
||||
}
|
||||
|
||||
#undef OFFSET_OF_FIELD_
|
||||
|
@ -2711,34 +2718,64 @@ bool Reward::MergePartialFromCodedStream(
|
|||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(122)) goto parse_image;
|
||||
if (input->ExpectTag(120)) goto parse_img_width;
|
||||
break;
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
// required int32 img_width = 15;
|
||||
case 15: {
|
||||
if (tag == 122) {
|
||||
if (tag == 120) {
|
||||
parse_img_width:
|
||||
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
||||
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
|
||||
input, &img_width_)));
|
||||
set_has_img_width();
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(128)) goto parse_img_height;
|
||||
break;
|
||||
}
|
||||
|
||||
// required int32 img_height = 16;
|
||||
case 16: {
|
||||
if (tag == 128) {
|
||||
parse_img_height:
|
||||
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
||||
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
|
||||
input, &img_height_)));
|
||||
set_has_img_height();
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(138)) goto parse_image;
|
||||
break;
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
case 17: {
|
||||
if (tag == 138) {
|
||||
parse_image:
|
||||
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
|
||||
input, this->add_image()));
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(122)) goto parse_image;
|
||||
if (input->ExpectTag(130)) goto parse_depth;
|
||||
if (input->ExpectTag(138)) goto parse_image;
|
||||
if (input->ExpectTag(146)) goto parse_depth;
|
||||
break;
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
case 16: {
|
||||
if (tag == 130) {
|
||||
// repeated bytes depth = 18;
|
||||
case 18: {
|
||||
if (tag == 146) {
|
||||
parse_depth:
|
||||
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
|
||||
input, this->add_depth()));
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(130)) goto parse_depth;
|
||||
if (input->ExpectTag(146)) goto parse_depth;
|
||||
if (input->ExpectAtEnd()) goto success;
|
||||
break;
|
||||
}
|
||||
|
@ -2838,16 +2875,26 @@ void Reward::SerializeWithCachedSizes(
|
|||
::google::protobuf::internal::WireFormatLite::WriteFloat(14, this->ori_z(), output);
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteBytes(
|
||||
15, this->image(i), output);
|
||||
// required int32 img_width = 15;
|
||||
if (has_img_width()) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteInt32(15, this->img_width(), output);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// required int32 img_height = 16;
|
||||
if (has_img_height()) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteInt32(16, this->img_height(), output);
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteBytes(
|
||||
17, this->image(i), output);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 18;
|
||||
for (int i = 0; i < this->depth_size(); i++) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteBytes(
|
||||
16, this->depth(i), output);
|
||||
18, this->depth(i), output);
|
||||
}
|
||||
|
||||
if (!unknown_fields().empty()) {
|
||||
|
@ -2930,16 +2977,26 @@ void Reward::SerializeWithCachedSizes(
|
|||
target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(14, this->ori_z(), target);
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
WriteBytesToArray(15, this->image(i), target);
|
||||
// required int32 img_width = 15;
|
||||
if (has_img_width()) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(15, this->img_width(), target);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// required int32 img_height = 16;
|
||||
if (has_img_height()) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(16, this->img_height(), target);
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
WriteBytesToArray(17, this->image(i), target);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 18;
|
||||
for (int i = 0; i < this->depth_size(); i++) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
WriteBytesToArray(16, this->depth(i), target);
|
||||
WriteBytesToArray(18, this->depth(i), target);
|
||||
}
|
||||
|
||||
if (!unknown_fields().empty()) {
|
||||
|
@ -3028,15 +3085,29 @@ int Reward::ByteSize() const {
|
|||
total_size += 1 + 4;
|
||||
}
|
||||
|
||||
// required int32 img_width = 15;
|
||||
if (has_img_width()) {
|
||||
total_size += 1 +
|
||||
::google::protobuf::internal::WireFormatLite::Int32Size(
|
||||
this->img_width());
|
||||
}
|
||||
|
||||
// required int32 img_height = 16;
|
||||
if (has_img_height()) {
|
||||
total_size += 2 +
|
||||
::google::protobuf::internal::WireFormatLite::Int32Size(
|
||||
this->img_height());
|
||||
}
|
||||
|
||||
}
|
||||
// repeated bytes image = 15;
|
||||
total_size += 1 * this->image_size();
|
||||
// repeated bytes image = 17;
|
||||
total_size += 2 * this->image_size();
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
total_size += ::google::protobuf::internal::WireFormatLite::BytesSize(
|
||||
this->image(i));
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// repeated bytes depth = 18;
|
||||
total_size += 2 * this->depth_size();
|
||||
for (int i = 0; i < this->depth_size(); i++) {
|
||||
total_size += ::google::protobuf::internal::WireFormatLite::BytesSize(
|
||||
|
@ -3115,6 +3186,12 @@ void Reward::MergeFrom(const Reward& from) {
|
|||
if (from.has_ori_z()) {
|
||||
set_ori_z(from.ori_z());
|
||||
}
|
||||
if (from.has_img_width()) {
|
||||
set_img_width(from.img_width());
|
||||
}
|
||||
if (from.has_img_height()) {
|
||||
set_img_height(from.img_height());
|
||||
}
|
||||
}
|
||||
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
|
||||
}
|
||||
|
@ -3132,6 +3209,7 @@ void Reward::CopyFrom(const Reward& from) {
|
|||
}
|
||||
|
||||
bool Reward::IsInitialized() const {
|
||||
if ((_has_bits_[0] & 0x0000c000) != 0x0000c000) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3152,6 +3230,8 @@ void Reward::Swap(Reward* other) {
|
|||
std::swap(ori_x_, other->ori_x_);
|
||||
std::swap(ori_y_, other->ori_y_);
|
||||
std::swap(ori_z_, other->ori_z_);
|
||||
std::swap(img_width_, other->img_width_);
|
||||
std::swap(img_height_, other->img_height_);
|
||||
image_.Swap(&other->image_);
|
||||
depth_.Swap(&other->depth_);
|
||||
std::swap(_has_bits_[0], other->_has_bits_[0]);
|
||||
|
|
|
@ -904,10 +904,24 @@ class Reward : public ::google::protobuf::Message {
|
|||
inline float ori_z() const;
|
||||
inline void set_ori_z(float value);
|
||||
|
||||
// repeated bytes image = 15;
|
||||
// required int32 img_width = 15;
|
||||
inline bool has_img_width() const;
|
||||
inline void clear_img_width();
|
||||
static const int kImgWidthFieldNumber = 15;
|
||||
inline ::google::protobuf::int32 img_width() const;
|
||||
inline void set_img_width(::google::protobuf::int32 value);
|
||||
|
||||
// required int32 img_height = 16;
|
||||
inline bool has_img_height() const;
|
||||
inline void clear_img_height();
|
||||
static const int kImgHeightFieldNumber = 16;
|
||||
inline ::google::protobuf::int32 img_height() const;
|
||||
inline void set_img_height(::google::protobuf::int32 value);
|
||||
|
||||
// repeated bytes image = 17;
|
||||
inline int image_size() const;
|
||||
inline void clear_image();
|
||||
static const int kImageFieldNumber = 15;
|
||||
static const int kImageFieldNumber = 17;
|
||||
inline const ::std::string& image(int index) const;
|
||||
inline ::std::string* mutable_image(int index);
|
||||
inline void set_image(int index, const ::std::string& value);
|
||||
|
@ -920,10 +934,10 @@ class Reward : public ::google::protobuf::Message {
|
|||
inline const ::google::protobuf::RepeatedPtrField< ::std::string>& image() const;
|
||||
inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_image();
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// repeated bytes depth = 18;
|
||||
inline int depth_size() const;
|
||||
inline void clear_depth();
|
||||
static const int kDepthFieldNumber = 16;
|
||||
static const int kDepthFieldNumber = 18;
|
||||
inline const ::std::string& depth(int index) const;
|
||||
inline ::std::string* mutable_depth(int index);
|
||||
inline void set_depth(int index, const ::std::string& value);
|
||||
|
@ -966,6 +980,10 @@ class Reward : public ::google::protobuf::Message {
|
|||
inline void clear_has_ori_y();
|
||||
inline void set_has_ori_z();
|
||||
inline void clear_has_ori_z();
|
||||
inline void set_has_img_width();
|
||||
inline void clear_has_img_width();
|
||||
inline void set_has_img_height();
|
||||
inline void clear_has_img_height();
|
||||
|
||||
::google::protobuf::UnknownFieldSet _unknown_fields_;
|
||||
|
||||
|
@ -985,6 +1003,8 @@ class Reward : public ::google::protobuf::Message {
|
|||
float ori_x_;
|
||||
float ori_y_;
|
||||
float ori_z_;
|
||||
::google::protobuf::int32 img_width_;
|
||||
::google::protobuf::int32 img_height_;
|
||||
::google::protobuf::RepeatedPtrField< ::std::string> image_;
|
||||
::google::protobuf::RepeatedPtrField< ::std::string> depth_;
|
||||
friend void protobuf_AddDesc_carla_5fprotocol_2eproto();
|
||||
|
@ -1735,7 +1755,55 @@ inline void Reward::set_ori_z(float value) {
|
|||
// @@protoc_insertion_point(field_set:Reward.ori_z)
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
// required int32 img_width = 15;
|
||||
inline bool Reward::has_img_width() const {
|
||||
return (_has_bits_[0] & 0x00004000u) != 0;
|
||||
}
|
||||
inline void Reward::set_has_img_width() {
|
||||
_has_bits_[0] |= 0x00004000u;
|
||||
}
|
||||
inline void Reward::clear_has_img_width() {
|
||||
_has_bits_[0] &= ~0x00004000u;
|
||||
}
|
||||
inline void Reward::clear_img_width() {
|
||||
img_width_ = 0;
|
||||
clear_has_img_width();
|
||||
}
|
||||
inline ::google::protobuf::int32 Reward::img_width() const {
|
||||
// @@protoc_insertion_point(field_get:Reward.img_width)
|
||||
return img_width_;
|
||||
}
|
||||
inline void Reward::set_img_width(::google::protobuf::int32 value) {
|
||||
set_has_img_width();
|
||||
img_width_ = value;
|
||||
// @@protoc_insertion_point(field_set:Reward.img_width)
|
||||
}
|
||||
|
||||
// required int32 img_height = 16;
|
||||
inline bool Reward::has_img_height() const {
|
||||
return (_has_bits_[0] & 0x00008000u) != 0;
|
||||
}
|
||||
inline void Reward::set_has_img_height() {
|
||||
_has_bits_[0] |= 0x00008000u;
|
||||
}
|
||||
inline void Reward::clear_has_img_height() {
|
||||
_has_bits_[0] &= ~0x00008000u;
|
||||
}
|
||||
inline void Reward::clear_img_height() {
|
||||
img_height_ = 0;
|
||||
clear_has_img_height();
|
||||
}
|
||||
inline ::google::protobuf::int32 Reward::img_height() const {
|
||||
// @@protoc_insertion_point(field_get:Reward.img_height)
|
||||
return img_height_;
|
||||
}
|
||||
inline void Reward::set_img_height(::google::protobuf::int32 value) {
|
||||
set_has_img_height();
|
||||
img_height_ = value;
|
||||
// @@protoc_insertion_point(field_set:Reward.img_height)
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
inline int Reward::image_size() const {
|
||||
return image_.size();
|
||||
}
|
||||
|
@ -1789,7 +1857,7 @@ Reward::mutable_image() {
|
|||
return &image_;
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// repeated bytes depth = 18;
|
||||
inline int Reward::depth_size() const {
|
||||
return depth_.size();
|
||||
}
|
||||
|
|
|
@ -89,6 +89,8 @@ message Reward {
|
|||
optional float ori_x = 12;
|
||||
optional float ori_y = 13;
|
||||
optional float ori_z = 14;
|
||||
repeated bytes image = 15;
|
||||
repeated bytes depth = 16;
|
||||
required int32 img_width = 15;
|
||||
required int32 img_height = 16;
|
||||
repeated bytes image = 17;
|
||||
repeated bytes depth = 18;
|
||||
}
|
|
@ -182,7 +182,7 @@ void protobuf_AssignDesc_carla_5fprotocol_2eproto() {
|
|||
::google::protobuf::MessageFactory::generated_factory(),
|
||||
sizeof(EpisodeReady));
|
||||
Reward_descriptor_ = file->message_type(6);
|
||||
static const int Reward_offsets_[16] = {
|
||||
static const int Reward_offsets_[18] = {
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, player_x_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, player_y_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, speed_),
|
||||
|
@ -197,6 +197,8 @@ void protobuf_AssignDesc_carla_5fprotocol_2eproto() {
|
|||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, ori_x_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, ori_y_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, ori_z_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, img_width_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, img_height_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, image_),
|
||||
GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Reward, depth_),
|
||||
};
|
||||
|
@ -283,14 +285,15 @@ void protobuf_AddDesc_carla_5fprotocol_2eproto() {
|
|||
"ection_Matrix\032&\n\021Projection_Matrix\022\021\n\tca"
|
||||
"m_param\030\001 \003(\002\032(\n\010Position\022\r\n\005pos_x\030\001 \002(\002"
|
||||
"\022\r\n\005pos_y\030\002 \002(\002\"\035\n\014EpisodeReady\022\r\n\005ready"
|
||||
"\030\001 \001(\010\"\252\002\n\006Reward\022\020\n\010player_x\030\001 \001(\002\022\020\n\010p"
|
||||
"\030\001 \001(\010\"\321\002\n\006Reward\022\020\n\010player_x\030\001 \001(\002\022\020\n\010p"
|
||||
"layer_y\030\002 \001(\002\022\r\n\005speed\030\003 \001(\002\022\025\n\rcollisio"
|
||||
"n_gen\030\004 \001(\002\022\025\n\rcollision_ped\030\005 \001(\002\022\025\n\rco"
|
||||
"llision_car\030\006 \001(\002\022\021\n\tintersect\030\007 \001(\002\022\021\n\t"
|
||||
"inertia_x\030\010 \001(\002\022\021\n\tinertia_y\030\t \001(\002\022\021\n\tin"
|
||||
"ertia_z\030\n \001(\002\022\021\n\ttimestamp\030\013 \001(\005\022\r\n\005ori_"
|
||||
"x\030\014 \001(\002\022\r\n\005ori_y\030\r \001(\002\022\r\n\005ori_z\030\016 \001(\002\022\r\n"
|
||||
"\005image\030\017 \003(\014\022\r\n\005depth\030\020 \003(\014", 707);
|
||||
"x\030\014 \001(\002\022\r\n\005ori_y\030\r \001(\002\022\r\n\005ori_z\030\016 \001(\002\022\021\n"
|
||||
"\timg_width\030\017 \002(\005\022\022\n\nimg_height\030\020 \002(\005\022\r\n\005"
|
||||
"image\030\021 \003(\014\022\r\n\005depth\030\022 \003(\014", 746);
|
||||
::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
|
||||
"carla_protocol.proto", &protobuf_RegisterTypes);
|
||||
EpisodeStart::default_instance_ = new EpisodeStart();
|
||||
|
@ -2398,6 +2401,8 @@ const int Reward::kTimestampFieldNumber;
|
|||
const int Reward::kOriXFieldNumber;
|
||||
const int Reward::kOriYFieldNumber;
|
||||
const int Reward::kOriZFieldNumber;
|
||||
const int Reward::kImgWidthFieldNumber;
|
||||
const int Reward::kImgHeightFieldNumber;
|
||||
const int Reward::kImageFieldNumber;
|
||||
const int Reward::kDepthFieldNumber;
|
||||
#endif // !_MSC_VER
|
||||
|
@ -2435,6 +2440,8 @@ void Reward::SharedCtor() {
|
|||
ori_x_ = 0;
|
||||
ori_y_ = 0;
|
||||
ori_z_ = 0;
|
||||
img_width_ = 0;
|
||||
img_height_ = 0;
|
||||
::memset(_has_bits_, 0, sizeof(_has_bits_));
|
||||
}
|
||||
|
||||
|
@ -2483,8 +2490,8 @@ void Reward::Clear() {
|
|||
if (_has_bits_[0 / 32] & 255) {
|
||||
ZR_(player_x_, inertia_x_);
|
||||
}
|
||||
if (_has_bits_[8 / 32] & 16128) {
|
||||
ZR_(inertia_y_, ori_z_);
|
||||
if (_has_bits_[8 / 32] & 65280) {
|
||||
ZR_(inertia_y_, img_height_);
|
||||
}
|
||||
|
||||
#undef OFFSET_OF_FIELD_
|
||||
|
@ -2711,34 +2718,64 @@ bool Reward::MergePartialFromCodedStream(
|
|||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(122)) goto parse_image;
|
||||
if (input->ExpectTag(120)) goto parse_img_width;
|
||||
break;
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
// required int32 img_width = 15;
|
||||
case 15: {
|
||||
if (tag == 122) {
|
||||
if (tag == 120) {
|
||||
parse_img_width:
|
||||
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
||||
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
|
||||
input, &img_width_)));
|
||||
set_has_img_width();
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(128)) goto parse_img_height;
|
||||
break;
|
||||
}
|
||||
|
||||
// required int32 img_height = 16;
|
||||
case 16: {
|
||||
if (tag == 128) {
|
||||
parse_img_height:
|
||||
DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
|
||||
::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>(
|
||||
input, &img_height_)));
|
||||
set_has_img_height();
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(138)) goto parse_image;
|
||||
break;
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
case 17: {
|
||||
if (tag == 138) {
|
||||
parse_image:
|
||||
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
|
||||
input, this->add_image()));
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(122)) goto parse_image;
|
||||
if (input->ExpectTag(130)) goto parse_depth;
|
||||
if (input->ExpectTag(138)) goto parse_image;
|
||||
if (input->ExpectTag(146)) goto parse_depth;
|
||||
break;
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
case 16: {
|
||||
if (tag == 130) {
|
||||
// repeated bytes depth = 18;
|
||||
case 18: {
|
||||
if (tag == 146) {
|
||||
parse_depth:
|
||||
DO_(::google::protobuf::internal::WireFormatLite::ReadBytes(
|
||||
input, this->add_depth()));
|
||||
} else {
|
||||
goto handle_unusual;
|
||||
}
|
||||
if (input->ExpectTag(130)) goto parse_depth;
|
||||
if (input->ExpectTag(146)) goto parse_depth;
|
||||
if (input->ExpectAtEnd()) goto success;
|
||||
break;
|
||||
}
|
||||
|
@ -2838,16 +2875,26 @@ void Reward::SerializeWithCachedSizes(
|
|||
::google::protobuf::internal::WireFormatLite::WriteFloat(14, this->ori_z(), output);
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteBytes(
|
||||
15, this->image(i), output);
|
||||
// required int32 img_width = 15;
|
||||
if (has_img_width()) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteInt32(15, this->img_width(), output);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// required int32 img_height = 16;
|
||||
if (has_img_height()) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteInt32(16, this->img_height(), output);
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteBytes(
|
||||
17, this->image(i), output);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 18;
|
||||
for (int i = 0; i < this->depth_size(); i++) {
|
||||
::google::protobuf::internal::WireFormatLite::WriteBytes(
|
||||
16, this->depth(i), output);
|
||||
18, this->depth(i), output);
|
||||
}
|
||||
|
||||
if (!unknown_fields().empty()) {
|
||||
|
@ -2930,16 +2977,26 @@ void Reward::SerializeWithCachedSizes(
|
|||
target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(14, this->ori_z(), target);
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
WriteBytesToArray(15, this->image(i), target);
|
||||
// required int32 img_width = 15;
|
||||
if (has_img_width()) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(15, this->img_width(), target);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// required int32 img_height = 16;
|
||||
if (has_img_height()) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(16, this->img_height(), target);
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
WriteBytesToArray(17, this->image(i), target);
|
||||
}
|
||||
|
||||
// repeated bytes depth = 18;
|
||||
for (int i = 0; i < this->depth_size(); i++) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
WriteBytesToArray(16, this->depth(i), target);
|
||||
WriteBytesToArray(18, this->depth(i), target);
|
||||
}
|
||||
|
||||
if (!unknown_fields().empty()) {
|
||||
|
@ -3028,15 +3085,29 @@ int Reward::ByteSize() const {
|
|||
total_size += 1 + 4;
|
||||
}
|
||||
|
||||
// required int32 img_width = 15;
|
||||
if (has_img_width()) {
|
||||
total_size += 1 +
|
||||
::google::protobuf::internal::WireFormatLite::Int32Size(
|
||||
this->img_width());
|
||||
}
|
||||
|
||||
// required int32 img_height = 16;
|
||||
if (has_img_height()) {
|
||||
total_size += 2 +
|
||||
::google::protobuf::internal::WireFormatLite::Int32Size(
|
||||
this->img_height());
|
||||
}
|
||||
|
||||
}
|
||||
// repeated bytes image = 15;
|
||||
total_size += 1 * this->image_size();
|
||||
// repeated bytes image = 17;
|
||||
total_size += 2 * this->image_size();
|
||||
for (int i = 0; i < this->image_size(); i++) {
|
||||
total_size += ::google::protobuf::internal::WireFormatLite::BytesSize(
|
||||
this->image(i));
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// repeated bytes depth = 18;
|
||||
total_size += 2 * this->depth_size();
|
||||
for (int i = 0; i < this->depth_size(); i++) {
|
||||
total_size += ::google::protobuf::internal::WireFormatLite::BytesSize(
|
||||
|
@ -3115,6 +3186,12 @@ void Reward::MergeFrom(const Reward& from) {
|
|||
if (from.has_ori_z()) {
|
||||
set_ori_z(from.ori_z());
|
||||
}
|
||||
if (from.has_img_width()) {
|
||||
set_img_width(from.img_width());
|
||||
}
|
||||
if (from.has_img_height()) {
|
||||
set_img_height(from.img_height());
|
||||
}
|
||||
}
|
||||
mutable_unknown_fields()->MergeFrom(from.unknown_fields());
|
||||
}
|
||||
|
@ -3132,6 +3209,7 @@ void Reward::CopyFrom(const Reward& from) {
|
|||
}
|
||||
|
||||
bool Reward::IsInitialized() const {
|
||||
if ((_has_bits_[0] & 0x0000c000) != 0x0000c000) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -3152,6 +3230,8 @@ void Reward::Swap(Reward* other) {
|
|||
std::swap(ori_x_, other->ori_x_);
|
||||
std::swap(ori_y_, other->ori_y_);
|
||||
std::swap(ori_z_, other->ori_z_);
|
||||
std::swap(img_width_, other->img_width_);
|
||||
std::swap(img_height_, other->img_height_);
|
||||
image_.Swap(&other->image_);
|
||||
depth_.Swap(&other->depth_);
|
||||
std::swap(_has_bits_[0], other->_has_bits_[0]);
|
||||
|
|
|
@ -904,10 +904,24 @@ class Reward : public ::google::protobuf::Message {
|
|||
inline float ori_z() const;
|
||||
inline void set_ori_z(float value);
|
||||
|
||||
// repeated bytes image = 15;
|
||||
// required int32 img_width = 15;
|
||||
inline bool has_img_width() const;
|
||||
inline void clear_img_width();
|
||||
static const int kImgWidthFieldNumber = 15;
|
||||
inline ::google::protobuf::int32 img_width() const;
|
||||
inline void set_img_width(::google::protobuf::int32 value);
|
||||
|
||||
// required int32 img_height = 16;
|
||||
inline bool has_img_height() const;
|
||||
inline void clear_img_height();
|
||||
static const int kImgHeightFieldNumber = 16;
|
||||
inline ::google::protobuf::int32 img_height() const;
|
||||
inline void set_img_height(::google::protobuf::int32 value);
|
||||
|
||||
// repeated bytes image = 17;
|
||||
inline int image_size() const;
|
||||
inline void clear_image();
|
||||
static const int kImageFieldNumber = 15;
|
||||
static const int kImageFieldNumber = 17;
|
||||
inline const ::std::string& image(int index) const;
|
||||
inline ::std::string* mutable_image(int index);
|
||||
inline void set_image(int index, const ::std::string& value);
|
||||
|
@ -920,10 +934,10 @@ class Reward : public ::google::protobuf::Message {
|
|||
inline const ::google::protobuf::RepeatedPtrField< ::std::string>& image() const;
|
||||
inline ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_image();
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// repeated bytes depth = 18;
|
||||
inline int depth_size() const;
|
||||
inline void clear_depth();
|
||||
static const int kDepthFieldNumber = 16;
|
||||
static const int kDepthFieldNumber = 18;
|
||||
inline const ::std::string& depth(int index) const;
|
||||
inline ::std::string* mutable_depth(int index);
|
||||
inline void set_depth(int index, const ::std::string& value);
|
||||
|
@ -966,6 +980,10 @@ class Reward : public ::google::protobuf::Message {
|
|||
inline void clear_has_ori_y();
|
||||
inline void set_has_ori_z();
|
||||
inline void clear_has_ori_z();
|
||||
inline void set_has_img_width();
|
||||
inline void clear_has_img_width();
|
||||
inline void set_has_img_height();
|
||||
inline void clear_has_img_height();
|
||||
|
||||
::google::protobuf::UnknownFieldSet _unknown_fields_;
|
||||
|
||||
|
@ -985,6 +1003,8 @@ class Reward : public ::google::protobuf::Message {
|
|||
float ori_x_;
|
||||
float ori_y_;
|
||||
float ori_z_;
|
||||
::google::protobuf::int32 img_width_;
|
||||
::google::protobuf::int32 img_height_;
|
||||
::google::protobuf::RepeatedPtrField< ::std::string> image_;
|
||||
::google::protobuf::RepeatedPtrField< ::std::string> depth_;
|
||||
friend void protobuf_AddDesc_carla_5fprotocol_2eproto();
|
||||
|
@ -1735,7 +1755,55 @@ inline void Reward::set_ori_z(float value) {
|
|||
// @@protoc_insertion_point(field_set:Reward.ori_z)
|
||||
}
|
||||
|
||||
// repeated bytes image = 15;
|
||||
// required int32 img_width = 15;
|
||||
inline bool Reward::has_img_width() const {
|
||||
return (_has_bits_[0] & 0x00004000u) != 0;
|
||||
}
|
||||
inline void Reward::set_has_img_width() {
|
||||
_has_bits_[0] |= 0x00004000u;
|
||||
}
|
||||
inline void Reward::clear_has_img_width() {
|
||||
_has_bits_[0] &= ~0x00004000u;
|
||||
}
|
||||
inline void Reward::clear_img_width() {
|
||||
img_width_ = 0;
|
||||
clear_has_img_width();
|
||||
}
|
||||
inline ::google::protobuf::int32 Reward::img_width() const {
|
||||
// @@protoc_insertion_point(field_get:Reward.img_width)
|
||||
return img_width_;
|
||||
}
|
||||
inline void Reward::set_img_width(::google::protobuf::int32 value) {
|
||||
set_has_img_width();
|
||||
img_width_ = value;
|
||||
// @@protoc_insertion_point(field_set:Reward.img_width)
|
||||
}
|
||||
|
||||
// required int32 img_height = 16;
|
||||
inline bool Reward::has_img_height() const {
|
||||
return (_has_bits_[0] & 0x00008000u) != 0;
|
||||
}
|
||||
inline void Reward::set_has_img_height() {
|
||||
_has_bits_[0] |= 0x00008000u;
|
||||
}
|
||||
inline void Reward::clear_has_img_height() {
|
||||
_has_bits_[0] &= ~0x00008000u;
|
||||
}
|
||||
inline void Reward::clear_img_height() {
|
||||
img_height_ = 0;
|
||||
clear_has_img_height();
|
||||
}
|
||||
inline ::google::protobuf::int32 Reward::img_height() const {
|
||||
// @@protoc_insertion_point(field_get:Reward.img_height)
|
||||
return img_height_;
|
||||
}
|
||||
inline void Reward::set_img_height(::google::protobuf::int32 value) {
|
||||
set_has_img_height();
|
||||
img_height_ = value;
|
||||
// @@protoc_insertion_point(field_set:Reward.img_height)
|
||||
}
|
||||
|
||||
// repeated bytes image = 17;
|
||||
inline int Reward::image_size() const {
|
||||
return image_.size();
|
||||
}
|
||||
|
@ -1789,7 +1857,7 @@ Reward::mutable_image() {
|
|||
return &image_;
|
||||
}
|
||||
|
||||
// repeated bytes depth = 16;
|
||||
// repeated bytes depth = 18;
|
||||
inline int Reward::depth_size() const {
|
||||
return depth_.size();
|
||||
}
|
||||
|
|
|
@ -1,146 +1,158 @@
|
|||
#include "Carla.h"
|
||||
#include "CarlaCommunication.h"
|
||||
#include "lodepng.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace carla {
|
||||
namespace server {
|
||||
// -- Static methods ---------------------------------------------------------
|
||||
namespace server {
|
||||
|
||||
template <typename ERROR_CODE>
|
||||
static void logTCPError(const std::string &text, const ERROR_CODE &errorCode) {
|
||||
std::cerr << "CarlaConnection - TCP Server: " << text << ": " << errorCode.message() << std::endl;
|
||||
}
|
||||
// -- Static methods ---------------------------------------------------------
|
||||
|
||||
template <typename ERROR_CODE>
|
||||
static void logTCPError(const std::string &text, const ERROR_CODE &errorCode) {
|
||||
std::cerr << "CarlaConnection - TCP Server: " << text << ": " << errorCode.message() << std::endl;
|
||||
}
|
||||
|
||||
// This is the thread that sends a string over the TCP socket.
|
||||
static void serverWorkerThread(TCPServer &server, Reward &rwd) {
|
||||
TCPServer::error_code error;
|
||||
//message = message.size.c_ + message;
|
||||
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
lodepng::State state;
|
||||
|
||||
std::vector<unsigned char> png;
|
||||
|
||||
for (int i = 0; i < rwd.image_size(); ++i) {
|
||||
std::string image = rwd.image(i);
|
||||
std::vector<unsigned char> data(image.begin(), image.end());
|
||||
lodepng::encode(png, data, rwd.img_width(), rwd.img_height(), state);
|
||||
rwd.set_image(i, std::string(png.begin(), png.end()));
|
||||
}
|
||||
|
||||
std::string message;
|
||||
bool correctSerialize = rwd.SerializeToString(&message);
|
||||
|
||||
if (correctSerialize) {
|
||||
server.writeString(message, error);
|
||||
if (error) logTCPError("Failed to send", error);
|
||||
}
|
||||
else
|
||||
logTCPError("Falied to serialize", error);
|
||||
|
||||
}
|
||||
|
||||
//TODO:
|
||||
// Sortida amb google protocol
|
||||
// This is the thread that listens for string over the TCP socket.
|
||||
static std::string clientWorkerThread(TCPServer &server) {
|
||||
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
|
||||
std::string message;
|
||||
TCPServer::error_code error;
|
||||
|
||||
server.readString(message, error);
|
||||
if (error && (error != boost::asio::error::eof)) { // eof is expected.
|
||||
logTCPError("Failed to read", error);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
// This is the thread that sends a string over the TCP socket.
|
||||
static void serverWorkerThread(TCPServer &server, const std::string &message) {
|
||||
TCPServer::error_code error;
|
||||
//message = message.size.c_ + message;
|
||||
// This is the thread that listens & sends a string over the TCP world socket.
|
||||
static std::string worldReceiveThread(TCPServer &server) {
|
||||
std::string message;
|
||||
TCPServer::error_code error;
|
||||
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
|
||||
server.readString(message, error);
|
||||
if (error && (error != boost::asio::error::eof)) { // eof is expected.
|
||||
logTCPError("Failed to read world", error);
|
||||
return std::string();
|
||||
}
|
||||
return message;
|
||||
|
||||
}
|
||||
|
||||
static void worldSendThread(TCPServer &server, const std::string &message) {
|
||||
TCPServer::error_code error;
|
||||
//message = message.size + message;
|
||||
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
|
||||
server.writeString(message, error);
|
||||
if (error)
|
||||
logTCPError("Failed to send world", error);
|
||||
|
||||
if (error)
|
||||
logTCPError("Failed to send", error);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//TODO:
|
||||
// Sortida amb google protocol
|
||||
// This is the thread that listens for string over the TCP socket.
|
||||
static std::string clientWorkerThread(TCPServer &server) {
|
||||
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
|
||||
std::string message;
|
||||
TCPServer::error_code error;
|
||||
|
||||
server.readString(message, error);
|
||||
if (error && (error != boost::asio::error::eof)) { // eof is expected.
|
||||
logTCPError("Failed to read", error);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
||||
// This is the thread that listens & sends a string over the TCP world socket.
|
||||
static std::string worldReceiveThread(TCPServer &server) {
|
||||
std::string message;
|
||||
TCPServer::error_code error;
|
||||
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
|
||||
server.readString(message, error);
|
||||
if (error && (error != boost::asio::error::eof)) { // eof is expected.
|
||||
logTCPError("Failed to read world", error);
|
||||
return std::string();
|
||||
static void Connect(TCPServer &server) {
|
||||
if (!server.Connected()) server.AcceptSocket();
|
||||
}
|
||||
return message;
|
||||
|
||||
}
|
||||
|
||||
static void worldSendThread(TCPServer &server, const std::string &message) {
|
||||
TCPServer::error_code error;
|
||||
//message = message.size + message;
|
||||
|
||||
//if (!server.Connected()) server.AcceptSocket();
|
||||
|
||||
server.writeString(message, error);
|
||||
if (error)
|
||||
logTCPError("Failed to send world", error);
|
||||
|
||||
}
|
||||
|
||||
static void Connect(TCPServer &server) {
|
||||
if (!server.Connected()) server.AcceptSocket();
|
||||
}
|
||||
|
||||
CarlaCommunication::CarlaCommunication(int worldPort, int writePort, int readPort) :
|
||||
_world(worldPort),
|
||||
_server(writePort),
|
||||
_client(readPort),
|
||||
_worldThread{
|
||||
[this]() { return worldReceiveThread(this->_world); },
|
||||
[this](const std::string &msg) { worldSendThread(this->_world, msg); },
|
||||
[this]() { Connect(this->_world); }},
|
||||
_serverThread{
|
||||
[this](const std::string &str) { serverWorkerThread(this->_server, str); },
|
||||
[this]() { Connect(this->_server); }},
|
||||
_clientThread{
|
||||
[this]() { return clientWorkerThread(this->_client); },
|
||||
[this]() { Connect(this->_client); }}
|
||||
CarlaCommunication::CarlaCommunication(int worldPort, int writePort, int readPort) :
|
||||
_world(worldPort),
|
||||
_server(writePort),
|
||||
_client(readPort),
|
||||
_worldThread{
|
||||
[this]() { return worldReceiveThread(this->_world); },
|
||||
[this](const std::string &msg) { worldSendThread(this->_world, msg); },
|
||||
[this]() { Connect(this->_world); } },
|
||||
_serverThread{
|
||||
[this](Reward &rwd) { serverWorkerThread(this->_server, rwd); },
|
||||
[this]() { Connect(this->_server); } },
|
||||
_clientThread{
|
||||
[this]() { return clientWorkerThread(this->_client); },
|
||||
[this]() { Connect(this->_client); } }
|
||||
{
|
||||
|
||||
/*std::cout << "WorldPort: " << worldPort << std::endl;
|
||||
std::cout << "writePort: " << writePort << std::endl;
|
||||
std::cout << "readPort: " << readPort << std::endl;*/
|
||||
/*std::cout << "WorldPort: " << worldPort << std::endl;
|
||||
std::cout << "writePort: " << writePort << std::endl;
|
||||
std::cout << "readPort: " << readPort << std::endl;*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void CarlaCommunication::sendReward(const Reward &reward) {
|
||||
std::string message;
|
||||
bool error = !reward.SerializeToString(&message);
|
||||
if (!error) {
|
||||
_serverThread.push(message);
|
||||
void CarlaCommunication::sendReward(const Reward &reward) {
|
||||
_serverThread.push(reward);
|
||||
std::cout << "Send Reward" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bool CarlaCommunication::tryReadControl(std::string &control) {
|
||||
return _clientThread.tryPop(control);
|
||||
}
|
||||
bool CarlaCommunication::tryReadControl(std::string &control) {
|
||||
return _clientThread.tryPop(control);
|
||||
}
|
||||
|
||||
void CarlaCommunication::sendWorld(const World &world) {
|
||||
std::string message;
|
||||
bool error = !world.SerializeToString(&message);
|
||||
_worldThread.push(message);
|
||||
}
|
||||
|
||||
void CarlaCommunication::sendScene(const Scene &scene) {
|
||||
std::string message;
|
||||
bool error = !scene.SerializeToString(&message);
|
||||
_worldThread.push(message);
|
||||
}
|
||||
|
||||
void CarlaCommunication::sendReset(const EpisodeReady &ready) {
|
||||
std::string message;
|
||||
bool error = !ready.SerializeToString(&message);
|
||||
if (!error) {
|
||||
//std::cout << "Send End Reset" << std::endl;
|
||||
void CarlaCommunication::sendWorld(const World &world) {
|
||||
std::string message;
|
||||
bool error = !world.SerializeToString(&message);
|
||||
_worldThread.push(message);
|
||||
}
|
||||
else {
|
||||
std::cout << " >> SEND RESET ERROR <<" << std::endl;
|
||||
|
||||
void CarlaCommunication::sendScene(const Scene &scene) {
|
||||
std::string message;
|
||||
bool error = !scene.SerializeToString(&message);
|
||||
_worldThread.push(message);
|
||||
}
|
||||
|
||||
void CarlaCommunication::sendReset(const EpisodeReady &ready) {
|
||||
std::string message;
|
||||
bool error = !ready.SerializeToString(&message);
|
||||
if (!error) {
|
||||
//std::cout << "Send End Reset" << std::endl;
|
||||
_worldThread.push(message);
|
||||
}
|
||||
else {
|
||||
std::cout << " >> SEND RESET ERROR <<" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
bool CarlaCommunication::tryReadWorldInfo(std::string &info) {
|
||||
return _worldThread.tryPop(info);
|
||||
}
|
||||
}
|
||||
|
||||
bool CarlaCommunication::tryReadWorldInfo(std::string &info) {
|
||||
return _worldThread.tryPop(info);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace server {
|
|||
|
||||
TCPServer _world;
|
||||
|
||||
thread::AsyncReaderJobQueue<std::string> _serverThread;
|
||||
thread::AsyncReaderJobQueue<Reward> _serverThread;
|
||||
|
||||
thread::AsyncWriterJobQueue<std::string> _clientThread;
|
||||
|
||||
|
|
|
@ -11,111 +11,105 @@
|
|||
#include <atomic>
|
||||
|
||||
namespace carla {
|
||||
namespace server {
|
||||
namespace server {
|
||||
|
||||
struct Color {
|
||||
char red;
|
||||
char green;
|
||||
char blue;
|
||||
//char alpha;
|
||||
};
|
||||
struct Position {
|
||||
float x, y;
|
||||
};
|
||||
|
||||
struct Position {
|
||||
float x, y;
|
||||
};
|
||||
struct Reward_Values {
|
||||
float player_x, player_y;
|
||||
float speed;
|
||||
float collision_gen, collision_ped, collision_car;
|
||||
float intersect;
|
||||
float inertia_x, inertia_y, inertia_z;
|
||||
std::int32_t timestamp;
|
||||
float ori_x = 0, ori_y, ori_z;
|
||||
int img_width, img_height;
|
||||
std::vector<unsigned char> img;
|
||||
std::vector<unsigned char> img_2;
|
||||
std::vector<unsigned char> depth_1;
|
||||
std::vector<unsigned char> depth_2;
|
||||
};
|
||||
|
||||
struct Reward_Values {
|
||||
float player_x, player_y;
|
||||
float speed;
|
||||
float collision_gen, collision_ped, collision_car;
|
||||
float intersect;
|
||||
float inertia_x, inertia_y, inertia_z;
|
||||
std::int32_t timestamp;
|
||||
float ori_x = 0, ori_y, ori_z;
|
||||
std::vector<Color> img;
|
||||
std::vector<Color> img_2;
|
||||
std::vector<Color> depth_1;
|
||||
std::vector<Color> depth_2;
|
||||
};
|
||||
struct Scene_Values {
|
||||
std::vector<Position> _possible_Positions;
|
||||
std::vector<const float*> _projection_Matrix;
|
||||
};
|
||||
|
||||
struct Scene_Values {
|
||||
std::vector<Position> _possible_Positions;
|
||||
std::vector<const float *> _projection_Matrix;
|
||||
};
|
||||
enum Mode {
|
||||
MONO = 0,
|
||||
STEREO = 1
|
||||
};
|
||||
|
||||
enum Mode {
|
||||
MONO = 0,
|
||||
STEREO = 1
|
||||
};
|
||||
/// Asynchronous TCP server. Uses two ports, one for sending messages (write)
|
||||
/// and one for receiving messages (read).
|
||||
///
|
||||
/// Writing and reading are executed in two different threads. Each thread has
|
||||
/// its own queue of messages.
|
||||
///
|
||||
/// Note that a new socket is created for every connection (every write and
|
||||
/// read).
|
||||
class CARLA_API CarlaServer : private NonCopyable {
|
||||
public:
|
||||
|
||||
/// Asynchronous TCP server. Uses two ports, one for sending messages (write)
|
||||
/// and one for receiving messages (read).
|
||||
///
|
||||
/// Writing and reading are executed in two different threads. Each thread has
|
||||
/// its own queue of messages.
|
||||
///
|
||||
/// Note that a new socket is created for every connection (every write and
|
||||
/// read).
|
||||
class CARLA_API CarlaServer : private NonCopyable {
|
||||
public:
|
||||
/// Starts two threads for writing and reading.
|
||||
explicit CarlaServer(int writePort, int readPort, int worldPort, int modesCount, int scenesCount);
|
||||
|
||||
/// Starts two threads for writing and reading.
|
||||
explicit CarlaServer(int writePort, int readPort, int worldPort, int modesCount, int scenesCount);
|
||||
~CarlaServer();
|
||||
|
||||
~CarlaServer();
|
||||
///// Send values of the current player status
|
||||
void sendReward(const Reward_Values &values);
|
||||
|
||||
///// Send values of the current player status
|
||||
void sendReward( const Reward_Values &values);
|
||||
//// Send the values of the generated scene
|
||||
void sendSceneValues(const Scene_Values &values);
|
||||
|
||||
//// Send the values of the generated scene
|
||||
void sendSceneValues( const Scene_Values &values);
|
||||
//// Send a signal to the client to notify that the car is ready
|
||||
void sendEndReset();
|
||||
|
||||
//// Send a signal to the client to notify that the car is ready
|
||||
void sendEndReset();
|
||||
void sendWorld();
|
||||
|
||||
void sendWorld();
|
||||
///// Try to read the response of the client. Return false if the queue
|
||||
///// is empty.
|
||||
bool tryReadControl(float &steer, float &gas);
|
||||
|
||||
///// Try to read the response of the client. Return false if the queue
|
||||
///// is empty.
|
||||
bool tryReadControl(float &steer, float &gas);
|
||||
////Try to read if the client has selected an scene and mode. Return false if the queue is empty
|
||||
bool tryReadSceneInit(int &mode, int &scene);
|
||||
|
||||
////Try to read if the client has selected an scene and mode. Return false if the queue is empty
|
||||
bool tryReadSceneInit(int &mode, int &scene);
|
||||
////Try to read if the client has selected an end & start point. Return false if the queue is empty
|
||||
bool tryReadEpisodeStart(float &start_index, float &end_index);
|
||||
|
||||
////Try to read if the client has selected an end & start point. Return false if the queue is empty
|
||||
bool tryReadEpisodeStart(float &start_index, float &end_index);
|
||||
int GetModesCount() const;
|
||||
|
||||
int GetModesCount() const;
|
||||
int GetScenesCount() const;
|
||||
|
||||
int GetScenesCount() const;
|
||||
void setMode(Mode mode);
|
||||
|
||||
void setMode(Mode mode);
|
||||
Mode GetMode() const;
|
||||
|
||||
Mode GetMode() const;
|
||||
void SetScene(int scene);
|
||||
|
||||
void SetScene(int scene);
|
||||
int GetScene() const;
|
||||
|
||||
int GetScene() const;
|
||||
void SetReset(bool reset);
|
||||
|
||||
void SetReset(bool reset);
|
||||
bool Reset() const;
|
||||
|
||||
bool Reset() const;
|
||||
private:
|
||||
|
||||
private:
|
||||
//std::mutex _mutex;
|
||||
|
||||
//std::mutex _mutex;
|
||||
std::atomic<Mode> _mode{ MONO };
|
||||
std::atomic_int _scene;
|
||||
std::atomic_bool _reset;
|
||||
|
||||
std::atomic<Mode> _mode {MONO};
|
||||
std::atomic_int _scene;
|
||||
std::atomic_bool _reset;
|
||||
const int _modes;
|
||||
const int _scenes;
|
||||
|
||||
const int _modes;
|
||||
const int _scenes;
|
||||
const std::unique_ptr<CarlaCommunication> _communication;
|
||||
|
||||
const std::unique_ptr<CarlaCommunication> _communication;
|
||||
const std::unique_ptr<Protocol> _proto;
|
||||
};
|
||||
|
||||
const std::unique_ptr<Protocol> _proto;
|
||||
};
|
||||
|
||||
} // namespace server
|
||||
} // namespace server
|
||||
} // namespace carla
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
namespace carla {
|
||||
namespace server {
|
||||
|
||||
Protocol::Protocol(carla::server::CarlaServer *server) {
|
||||
_server = server;
|
||||
}
|
||||
|
@ -21,11 +22,9 @@ namespace carla {
|
|||
|
||||
//IMAGE 1
|
||||
std::string* image = reward.add_image();
|
||||
std::vector<Color> img = values.img;
|
||||
std::vector<unsigned char> img = values.img;
|
||||
for (int i = 0; i < img.size(); ++i) {
|
||||
(*image) += img[i].red;
|
||||
(*image) += img[i].green;
|
||||
(*image) += img[i].blue;
|
||||
(*image) += img[i];
|
||||
//image->append(GetBytes((img[i].green)));
|
||||
//image->append(GetBytes((img[i].blue)));
|
||||
//image->append(GetBytes((img[i].alpha)));
|
||||
|
@ -39,9 +38,7 @@ namespace carla {
|
|||
img = values.img_2;
|
||||
|
||||
for (int i = 0; i < img.size(); ++i) {
|
||||
(*image) += img[i].red;
|
||||
(*image) += img[i].green;
|
||||
(*image) += img[i].blue;
|
||||
(*image) += img[i];
|
||||
/*image->append(GetBytes((img[i].red)));
|
||||
image->append(GetBytes((img[i].green)));
|
||||
image->append(GetBytes((img[i].blue)));*/
|
||||
|
@ -53,9 +50,7 @@ namespace carla {
|
|||
img = values.depth_1;
|
||||
|
||||
for (int i = 0; i < img.size(); ++i) {
|
||||
(*image) += img[i].red;
|
||||
(*image) += img[i].green;
|
||||
(*image) += img[i].blue;
|
||||
(*image) += img[i];
|
||||
/*image->append(GetBytes((img[i].red)));
|
||||
image->append(GetBytes((img[i].green)));
|
||||
image->append(GetBytes((img[i].blue)));*/
|
||||
|
@ -67,9 +62,7 @@ namespace carla {
|
|||
img = values.depth_2;
|
||||
|
||||
for (int i = 0; i < img.size(); ++i) {
|
||||
(*image) += img[i].red;
|
||||
(*image) += img[i].green;
|
||||
(*image) += img[i].blue;
|
||||
(*image) += img[i];
|
||||
/*image->append(GetBytes((img[i].red)));
|
||||
image->append(GetBytes((img[i].green)));
|
||||
image->append(GetBytes((img[i].blue)));*/
|
||||
|
@ -88,6 +81,8 @@ namespace carla {
|
|||
reward.set_player_x(values.player_x);
|
||||
reward.set_speed(values.speed);
|
||||
reward.set_timestamp(values.timestamp);
|
||||
reward.set_img_width(values.img_width);
|
||||
reward.set_img_height(values.img_height);
|
||||
|
||||
return reward;
|
||||
}
|
||||
|
@ -121,16 +116,5 @@ namespace carla {
|
|||
world.add_scenes(_server->GetScenesCount());
|
||||
return world;
|
||||
}
|
||||
|
||||
const char* Protocol::GetBytes(int n) {
|
||||
char bytes[4];
|
||||
|
||||
bytes[0] = (n >> 24) & 0xFF;
|
||||
bytes[1] = (n >> 16) & 0xFF;
|
||||
bytes[2] = (n >> 8) & 0xFF;
|
||||
bytes[3] = n & 0xFF;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
|
||||
#include "carla/Protocol/carlaProtocol/carla_protocol.pb.h"
|
||||
|
||||
//#include "carla\server\CarlaServer.h"
|
||||
#include <string>
|
||||
|
||||
namespace carla {
|
||||
namespace server {
|
||||
|
||||
class CarlaServer;
|
||||
struct Reward_Values;
|
||||
struct Scene_Values;
|
||||
|
@ -24,8 +24,6 @@ namespace server {
|
|||
|
||||
World LoadWorld();
|
||||
|
||||
const char* GetBytes(int n);
|
||||
|
||||
private:
|
||||
|
||||
carla::server::CarlaServer *_server;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,6 @@
|
|||
#include "Carla.h"
|
||||
|
||||
#include "carla/server/CarlaServer.h"
|
||||
#include "lodepng.h"
|
||||
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
@ -30,7 +29,7 @@ static std::string daytimeString() {
|
|||
return str;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
try {
|
||||
if (argc != 6) {
|
||||
std::cerr << "Usage: server <send-port> <read-port>" << std::endl;
|
||||
|
@ -44,41 +43,47 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
// Let's simulate the game loop.
|
||||
|
||||
Color c1;
|
||||
c1.red = 255;
|
||||
c1.green = 0;
|
||||
c1.blue = 0;
|
||||
//c1.alpha = 0;
|
||||
int imageWidth = 512, imageHeight = 512;
|
||||
|
||||
Color c2;
|
||||
c2.red = 4;
|
||||
c2.green = 5;
|
||||
c2.blue = 6;
|
||||
//c2.alpha = 0;
|
||||
std::vector<unsigned char> img;
|
||||
img.resize(imageWidth * imageHeight * 4);
|
||||
for (int i = 0; i < imageHeight; ++i)
|
||||
for (int e = 0; e < imageWidth; ++e) {
|
||||
img[4 * imageWidth * i + 4 * e + 0] = 255 * !(e & i);
|
||||
img[4 * imageWidth * i + 4 * e + 1] = e ^ i;
|
||||
img[4 * imageWidth * i + 4 * e + 2] = e | i;
|
||||
img[4 * imageWidth * i + 4 * e + 3] = 255;
|
||||
}
|
||||
|
||||
Color c3;
|
||||
c3.red = 7;
|
||||
c3.green = 8;
|
||||
c3.blue = 9;
|
||||
//c3.alpha = 0;
|
||||
std::vector<unsigned char> img_2;
|
||||
img_2.resize(imageWidth * imageHeight * 4);
|
||||
for (int i = 0; i < imageHeight; ++i)
|
||||
for (int e = 0; e < imageWidth; ++e) {
|
||||
img_2[4 * imageWidth * i + 4 * e + 0] = 255 * !(e & i);
|
||||
img_2[4 * imageWidth * i + 4 * e + 1] = e ^ i;
|
||||
img_2[4 * imageWidth * i + 4 * e + 2] = e | i;
|
||||
img_2[4 * imageWidth * i + 4 * e + 3] = 255;
|
||||
}
|
||||
|
||||
Color c4;
|
||||
c4.red = 10;
|
||||
c4.green = 11;
|
||||
c4.blue = 12;
|
||||
//c4.alpha = 0;
|
||||
std::vector<unsigned char> depth_1;
|
||||
depth_1.resize(imageWidth * imageHeight * 4);
|
||||
for (int i = 0; i < imageHeight; ++i)
|
||||
for (int e = 0; e < imageWidth; ++e) {
|
||||
depth_1[4 * imageWidth * i + 4 * e + 0] = 255 * !(e & i);
|
||||
depth_1[4 * imageWidth * i + 4 * e + 1] = e ^ i;
|
||||
depth_1[4 * imageWidth * i + 4 * e + 2] = e | i;
|
||||
depth_1[4 * imageWidth * i + 4 * e + 3] = 255;
|
||||
}
|
||||
|
||||
std::vector<Color> img;
|
||||
for (int i = 0; i < 1024; ++i) img.push_back(c1);
|
||||
|
||||
std::vector<Color> img_2;
|
||||
for (int i = 0; i < 1024; ++i) img_2.push_back(c2);
|
||||
|
||||
std::vector<Color> depth_1;
|
||||
for (int i = 0; i < 1024; ++i) depth_1.push_back(c3);
|
||||
|
||||
std::vector<Color> depth_2;
|
||||
for (int i = 0; i < 1024; ++i) depth_2.push_back(c4);
|
||||
std::vector<unsigned char> depth_2;
|
||||
depth_2.resize(imageWidth * imageHeight * 4);
|
||||
for (int i = 0; i < imageHeight; ++i)
|
||||
for (int e = 0; e < imageWidth; ++e) {
|
||||
depth_2[4 * imageWidth * i + 4 * e + 0] = 255 * !(e & i);
|
||||
depth_2[4 * imageWidth * i + 4 * e + 1] = e ^ i;
|
||||
depth_2[4 * imageWidth * i + 4 * e + 2] = e | i;
|
||||
depth_2[4 * imageWidth * i + 4 * e + 3] = 255;
|
||||
}
|
||||
|
||||
Reward_Values testData;
|
||||
testData.player_x = 1.0f;
|
||||
|
@ -95,11 +100,14 @@ int main(int argc, char *argv[]) {
|
|||
testData.ori_x = 10.0f;
|
||||
testData.ori_y = 20.0f;
|
||||
testData.ori_z = 30.0f;
|
||||
testData.img_height = imageHeight;
|
||||
testData.img_width = imageWidth;
|
||||
testData.img = img;
|
||||
testData.img_2 = img_2;
|
||||
testData.depth_1 = depth_1;
|
||||
testData.depth_2 = depth_2;
|
||||
|
||||
|
||||
std::cout << "Server send World" << std::endl;
|
||||
server.sendWorld();
|
||||
|
||||
|
@ -112,13 +120,13 @@ int main(int argc, char *argv[]) {
|
|||
} while (!end);
|
||||
|
||||
std::vector<Position> positions;
|
||||
std::vector<const float *> pMatrix;
|
||||
std::vector<const float*> pMatrix;
|
||||
|
||||
positions.push_back(Position { 0.0f, 0.0f });
|
||||
positions.push_back(Position { 1.0f, 2.0f });
|
||||
positions.push_back(Position { 3.0f, 4.0f });
|
||||
positions.push_back(Position{ 0.0f, 0.0f });
|
||||
positions.push_back(Position{ 1.0f, 2.0f });
|
||||
positions.push_back(Position{ 3.0f, 4.0f });
|
||||
|
||||
float list[16] = { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
|
||||
float list[16] = { 10.0, 10.0,10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 };
|
||||
|
||||
pMatrix.push_back(list);
|
||||
|
||||
|
@ -153,28 +161,30 @@ int main(int argc, char *argv[]) {
|
|||
std::cout << "------> RESET <------" << std::endl;
|
||||
std::cout << " --> Start: " << startPoint << " End: " << endPoint << std::endl;
|
||||
server.sendEndReset();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
if (wait_control && server.tryReadControl(steer, gas)) {
|
||||
std::cout << "Steer: " << steer << "Gas: " << gas << std::endl;
|
||||
wait_control = false;
|
||||
} else if (!wait_control) {
|
||||
}
|
||||
else if (!wait_control) {
|
||||
server.sendReward(testData);
|
||||
wait_control = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(100ms);
|
||||
}
|
||||
Sleep(100);
|
||||
|
||||
}
|
||||
|
||||
} catch (const std::exception &e) {
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
return STLException;
|
||||
} catch (...) {
|
||||
}
|
||||
catch (...) {
|
||||
std::cerr << "Unknown exception thrown" << std::endl;
|
||||
return UnknownException;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue