1

我正在填写一些 flatbuffer 消息,但是当我编码然后解码它们时,我会得到垃圾。我没有包含完整的消息以避免无关信息,但我能够成功提取联合组件的枚举值。但是,当我提取枚举标识的类型时,我打印出的双精度数组包含垃圾,如下图所示。

以下是缓冲区的重要部分:

输入输出:

KukaJAVAdriver sending armposition command:[1, 0, 0, 0, 0, 0, 1]
re-extracted 7 joint angles: 0 11 02 03 04 05 06 1

联合状态.fbs:

table JointState {
  // @todo consider adding name string
  position:[double]; // angle in radians
  velocity:[double]; // velocity in radians/second
  acceleration:[double]; // acceleration in radians/(second^2)
  torque:[double]; // Newton Meters (N*m)
}

ArmControlState.fbs:

include "JointState.fbs";
include "Geometry.fbs";

namespace grl.flatbuffer;

table StartArm {
}

table StopArm {
}

table PauseArm {
}

table TeachArm {
}

table ShutdownArm {
}

table MoveArmTrajectory {
  traj:[JointState];
}

table MoveArmJointServo {
  goal:JointState;
}

table MoveArmCartesianServo {
  parent:string; // Object/Frame/Coordinate System to move wrt. Empty default is robot base
  goal:Pose;
}

union ArmState { StartArm, StopArm, PauseArm, ShutdownArm, TeachArm, MoveArmTrajectory, MoveArmJointServo, MoveArmCartesianServo }

table ArmControlState {
  name:string;   // entity to move
  sequenceNumber:long;
  timeStamp:double;
  state:ArmState;
}

编码:

          flatbuffers::Offset<flatbuffer::ArmControlState> controlState;


          switch (armControlMode_) {

              case flatbuffer::ArmState::ArmState_StartArm: {
                 controlState = flatbuffer::CreateArmControlState(*fbbP,bns,sequenceNumber++,duration,armControlMode_,flatbuffer::CreateStartArm(*fbbP).Union());
                 break;
              }
              case flatbuffer::ArmState::ArmState_MoveArmJointServo: {

                /// @todo when new
                JointScalar                          armPosVelAccelEmpty;
                auto armPositionBuffer = fbbP->CreateVector(armPosition_.data(),armPosition_.size());
                auto goalJointState = grl::flatbuffer::CreateJointState(*fbbP,armPositionBuffer);
                auto moveArmJointServo = grl::flatbuffer::CreateMoveArmJointServo(*fbbP,goalJointState);
                controlState = flatbuffer::CreateArmControlState(*fbbP,bns,sequenceNumber++,duration,armControlMode_,moveArmJointServo.Union());
                std::cout << "KukaJAVAdriver sending armposition command:" <<armPosition_<<"\n";
                 break;
              }
//...snip...
}

解码:

          auto states = flatbuffer::CreateKUKAiiwaStates(*fbbP,kukaiiwaStateVec);

          grl::flatbuffer::FinishKUKAiiwaStatesBuffer(*fbbP, states);

          flatbuffers::Verifier verifier(fbbP->GetBufferPointer(),fbbP->GetSize());
          BOOST_VERIFY(grl::flatbuffer::VerifyKUKAiiwaStatesBuffer(verifier));


          if(armControlMode_ == flatbuffer::ArmState::ArmState_MoveArmJointServo)
          {
              auto states2 = flatbuffer::GetKUKAiiwaStates(fbbP->GetBufferPointer());
              auto movearm = static_cast<const flatbuffer::MoveArmJointServo*>(states2->states()->Get(0)->armControlState()->state());
              std::cout << "re-extracted " << movearm->goal()->position()->size() << " joint angles: ";
              for(std::size_t i = 0; i <  movearm->goal()->position()->size(); ++i)
              {
                std::cout << i << " " << movearm->goal()->position()->Get(i);
              }
              std::cout << "\n";
          }

          kukaJavaDriverP->async_send_flatbuffer(fbbP);
4

1 回答 1

1

你没有得到垃圾,数据实际上是正确的。错误在此声明中:std::cout << i << " " << movearm->goal()->position()->Get(i);

相反,如果你写了类似的东西:std::cout << i << "=" << movearm->goal()->position()->Get(i) << ", ";它更具可读性:)

于 2016-03-10T18:41:43.037 回答