feat: integrate AUBO coordinate queue controls and routed QUIC endpoint reporting

This commit is contained in:
linbo 2026-11-09 13:49:13 +08:00
parent 89091dc435
commit 250775970c
15 changed files with 378 additions and 95 deletions

View File

@ -44,6 +44,18 @@ quic_edge {
# }
# }
platforms {
id: "platform_199"
server_host: "192.168.0.199"
server_port: 4433
enable_media: false
tls {
ca_file: "certs/cmvr-quic-ca.crt"
server_name: "192.168.0.199"
allow_insecure: false
}
}
reconnect {
initial_delay_ms: 500
maximum_delay_ms: 30000

View File

@ -43,6 +43,9 @@ add_library(cmvr_es::device::aubo_arm ALIAS aubo_arm)
install(TARGETS aubo_arm LIBRARY DESTINATION lib)
if(BUILD_TESTING)
add_executable(aubo_absolute_coordinate_test tests/aubo_absolute_coordinate_test.cpp)
target_include_directories(aubo_absolute_coordinate_test PRIVATE ${CMAKE_SOURCE_DIR}/cmvr-es)
add_test(NAME aubo_absolute_coordinate_test COMMAND aubo_absolute_coordinate_test)
add_executable(aubo_user_coordinate_store_test tests/aubo_user_coordinate_store_test.cpp)
target_include_directories(aubo_user_coordinate_store_test PRIVATE ${CMAKE_SOURCE_DIR}/cmvr-es)
target_link_libraries(aubo_user_coordinate_store_test PRIVATE jsoncpp Threads::Threads)

View File

@ -18,8 +18,8 @@ namespace cmvr::device {
class AuboArm final : public RobotArm {
public:
Result applyUserCoordinateSystem(const std::string& name, std::uint64_t revision) override;
Result calibrateUserCoordinate(const std::vector<std::vector<double>>& points, std::vector<double>& pose);
Result moveLRelativeInCoordinate(const CartesianPose& delta,const MotionOptions& options);
Result applyBuiltinCoordinate(const std::string& name,
std::vector<double>& actual_tcp_offset);
Result applyUserCoordinates(const std::vector<double>& user_pose,
@ -123,6 +123,9 @@ public:
std::shared_ptr<cmvr::IKSolver> kinematicsSolver() const override { return nullptr; }
CartesianPose fk(const std::string& base_link, const std::string& ee_link) override;
CartesianPose fk(bool is_tcp = true) override;
bool isBaseReference(const std::string& name) const;
Result getPoseInCoordinate(const std::string& name, const std::vector<double>& base_reference,
const std::string& end_frame, CartesianPose& pose);
CartesianVelocity getSpeedLCommandTwistBase() const override { return {}; }
bool busy() const override { return busy_.load(); }
@ -131,7 +134,7 @@ private:
Result moveLConfigured_(const CartesianPose& target, const MotionOptions& options,
const std::string& base_frame, const std::string& tcp_frame,
const std::vector<double>* user_pose,
const std::vector<double>* tcp_offset, bool relative_translation = false);
const std::vector<double>* tcp_offset);
enum class ActiveMotion {
None,
Joint,
@ -175,7 +178,7 @@ private:
mutable std::mutex mutex_;
mutable std::mutex user_coordinate_mutex_;
std::atomic<bool> user_coordinates_active_{false};
// Tool reference is sampled at the start of each MoveL, never at Apply.
// Absolute tool reference is frozen at Apply and shared by MoveL/GetPose.
std::atomic<bool> builtin_tool_reference_{false};
std::string applied_user_coordinate_name_;
std::uint64_t applied_user_coordinate_revision_{};

View File

@ -5,18 +5,24 @@
#include <cmath>
#include <stdexcept>
namespace cmvr::device {
// Absolute target transform: T_base_tcp_goal = T_base_reference * T_reference_tcp_goal.
// It deliberately has no current-TCP argument, so repeated goals cannot accumulate.
template<class Compose>
inline std::vector<double> coordinateTranslationTarget(const std::vector<double>& current,
const std::vector<double>& reference,const std::vector<double>& delta,Compose compose) {
inline std::vector<double> coordinateAbsoluteTarget(const std::vector<double>& reference,
const std::vector<double>& target,Compose compose) {
const auto valid=[](const std::vector<double>& p){return p.size()==6&&std::all_of(p.begin(),p.end(),[](double x){return std::isfinite(x);});};
if(!valid(current)||!valid(reference)||!valid(delta)||delta[3]!=0||delta[4]!=0||delta[5]!=0)
throw std::invalid_argument("axis translation requires finite poses and zero rotation increment");
const auto origin=compose(reference,std::vector<double>(6,0.0));
const auto tip=compose(reference,delta);
if(!valid(origin)||!valid(tip))throw std::runtime_error("SDK Math returned invalid translation");
auto target=current;for(int i=0;i<3;++i)target[i]+=tip[i]-origin[i];
if(!valid(target))throw std::runtime_error("invalid translated target");
return target;
if(!valid(reference)||!valid(target))throw std::invalid_argument("absolute reference and target require six finite m/rad values");
auto result=compose(reference,target);
if(!valid(result))throw std::runtime_error("SDK Math returned invalid absolute target");
return result;
}
// Feedback transform: T_reference_end = inverse(T_base_reference) * T_base_end.
template<class Inverse,class Compose>
inline std::vector<double> coordinateFeedbackPose(const std::vector<double>& reference,
const std::vector<double>& actual,Inverse inverse,Compose compose) {
const auto valid=[](const std::vector<double>& p){return p.size()==6&&std::all_of(p.begin(),p.end(),[](double x){return std::isfinite(x);});};
if(!valid(reference)||!valid(actual))throw std::invalid_argument("feedback reference and actual pose require six finite m/rad values");
return coordinateAbsoluteTarget(inverse(reference),actual,compose);
}
// Geometry validation for SDK Math::calibrateCoordinate(poses, 0): O, +X, +Y half-plane.
inline std::vector<double> threePointFrame(const std::vector<std::vector<double>>& points) {

View File

@ -1,5 +1,6 @@
#include "devices/arm/aubo_arm/include/aubo_arm.h"
#include "devices/arm/aubo_arm/include/three_point_frame.h"
#include "devices/arm/aubo_arm/include/user_coordinate_store.h"
#include "devices/arm/aubo_arm/include/aubo_motion_result.h"
#include <algorithm>
@ -447,14 +448,6 @@ Result AuboArm::calibrateUserCoordinate(const std::vector<std::vector<double>>&
#endif
}
Result AuboArm::moveLRelativeInCoordinate(const CartesianPose& delta,const MotionOptions& options)
{
if(delta.rx!=0 || delta.ry!=0 || delta.rz!=0)
return Result::failure(ArmErrorCode::InvalidArgument,"axis translation must not include rotation");
if(!user_coordinates_active_.load())return Result::failure(ArmErrorCode::CommandRejected,"apply a coordinate before axis translation");
return moveLConfigured_(delta,options,{},{},nullptr,nullptr,true);
}
Result AuboArm::configureWorkObject_(const std::vector<double>& base_user_pose, bool invalidate)
{
#if defined(CMVR_HAS_AUBO_SDK)
@ -490,6 +483,19 @@ Result AuboArm::configureWorkObject_(const std::vector<double>& base_user_pose,
#endif
}
Result AuboArm::applyUserCoordinateSystem(const std::string& name,std::uint64_t revision)
{
try {
const auto profile=UserCoordinateStore::forArm(id_).get(name,revision);
std::vector<double> actual;
return UserCoordinateStore::isBuiltin(profile.name)
? applyBuiltinCoordinate(profile.name,actual)
: applyUserCoordinates(profile.user_pose,profile.tcp_offset,actual,profile.name,profile.revision);
} catch(const CoordinateStoreError& e){
return Result::failure(e.kind==CoordinateStoreError::Storage?ArmErrorCode::CommandFailed:ArmErrorCode::InvalidArgument,e.what());
}
}
Result AuboArm::applyBuiltinCoordinate(const std::string& name,
std::vector<double>& actual_tcp_offset)
{
@ -506,7 +512,18 @@ Result AuboArm::applyBuiltinCoordinate(const std::string& name,
if(!offset || !offset->isArray() || offset->size()!=6)
return Result::failure(ArmErrorCode::CommandFailed,"missing TCP readback");
std::vector<double> tcp;for(const auto& x:*offset)tcp.push_back(x.asDouble());
const auto result=applyUserCoordinates(std::vector<double>(6,0.0),tcp,actual_tcp_offset,name,1);
std::vector<double> reference(6,0.0);
if(name=="__builtin_tool__") {
// Absolute goals use a fixed reference captured at Apply, not a new
// relative offset from whichever TCP position exists at each command.
try {
const auto current=fk(true);
reference={current.x,current.y,current.z,current.rx,current.ry,current.rz};
if(!std::all_of(reference.begin(),reference.end(),[](double v){return std::isfinite(v);}))
return Result::failure(ArmErrorCode::CommandFailed,"invalid current TCP for absolute tool reference");
} catch(const std::exception& e){return Result::failure(ArmErrorCode::CommandFailed,e.what());}
}
const auto result=applyUserCoordinates(reference,tcp,actual_tcp_offset,name,1);
if(result.ok())builtin_tool_reference_.store(name=="__builtin_tool__");
return result;
}
@ -631,7 +648,8 @@ bool AuboArm::executeJsonCommand(const std::string& request_json,
jsonMember(response,"transform") = "T_flange_tcp";
jsonMember(response,"units") = "m_rad";
jsonMember(response,"rotation_convention") = "RzRyRx";
jsonMember(response,"coordinate_api_version") = 3;
jsonMember(response,"coordinate_api_version") = 4;
jsonMember(response,"movel_target_mode") = "absolute_selected_frame";
jsonMember(response,"work_object_acknowledged") = !read_only;
jsonMember(response,"offset") = offset;
jsonMember(response,"user_frame_reference") = "base";
@ -822,6 +840,9 @@ ArmState AuboArm::getRobotState() const
state.actual_joint_state = getJointState();
state.target_joint_state = state.actual_joint_state;
state.actual_tcp_pose = getTcpPose(FrameType::Base);
// Host read-completion time in Unix seconds, not the controller's sample clock.
state.timestamp = std::chrono::duration<double>(
std::chrono::system_clock::now().time_since_epoch()).count();
return state;
}
@ -1412,7 +1433,7 @@ Result AuboArm::moveLConfigured_(const CartesianPose& target,
const MotionOptions& options,
const std::string& base_frame, const std::string& tcp_frame,
const std::vector<double>* user_pose,
const std::vector<double>* explicit_tcp_offset, bool relative_translation)
const std::vector<double>* explicit_tcp_offset)
{
if (options.cancellation_requested && options.cancellation_requested()) {
return Result::failure(ArmErrorCode::CommandRejected,
@ -1513,27 +1534,12 @@ Result AuboArm::moveLConfigured_(const CartesianPose& target,
if(selected)for(int i=0;i<6;++i)if(!std::isfinite(actual_tcp[i]) || std::abs(actual_tcp[i]-selected_tcp[i])>1e-8)
return Result::failure(ArmErrorCode::CommandRejected,"TCP changed after Apply; reapply coordinate");
auto math=sdk_->rpc_client->getMath();
if(relative_translation) {
const auto current=robot_interface->getRobotState()->getTcpPose();
if(current.size()!=6 || !std::all_of(current.begin(),current.end(),[](double v){return std::isfinite(v);}))
return Result::failure(ArmErrorCode::CommandFailed,"actual TCP unavailable");
const auto reference=builtin_tool_reference_.load()?current:selected_user;
pose=coordinateTranslationTarget(current,reference,pose,
if(user_pose || selected) {
// target is an absolute TCP pose expressed in the selected fixed
// reference, including all three orientation components.
pose=coordinateAbsoluteTarget(user_pose?*user_pose:selected_user,pose,
[&math](const auto& a,const auto& b){return math->poseTrans(a,b);});
} else if (builtin_tool_reference_.load() && !user_pose) {
// A tool-relative MoveL is an increment from the CURRENT TCP.
// WorkObject is base for this mode; compose once at command start.
if(!robot_interface->getRobotState() || !sdk_->rpc_client->getMath())
return Result::failure(ArmErrorCode::RobotNotReady,"tool-relative MoveL requires robot state and math interfaces");
const auto current=robot_interface->getRobotState()->getTcpPose();
if(current.size()!=6 || !std::all_of(current.begin(),current.end(),[](double x){return std::isfinite(x);}))
return Result::failure(ArmErrorCode::CommandFailed,"invalid current TCP pose for tool-relative MoveL");
pose=sdk_->rpc_client->getMath()->poseTrans(current,pose);
if(pose.size()!=6 || !std::all_of(pose.begin(),pose.end(),[](double x){return std::isfinite(x);}))
return Result::failure(ArmErrorCode::CommandFailed,"invalid tool-relative MoveL target");
}
if(!relative_translation && !builtin_tool_reference_.load() && (user_pose || selected))
pose=math->poseTrans(user_pose?*user_pose:selected_user,pose);
if(pose.size()!=6 || !std::all_of(pose.begin(),pose.end(),[](double v){return std::isfinite(v);}))
return Result::failure(ArmErrorCode::InvalidArgument,"invalid SDK-transformed MoveL target");
if (selected_base_frame != "base") {
@ -2389,22 +2395,55 @@ std::vector<double> AuboArm::ik(const std::string& base_link,
return {};
}
bool AuboArm::isBaseReference(const std::string& name) const
{
return name.empty() || name=="base" || name=="__builtin_base__" ||
(!vendor_cfg_.base_frame().empty() && name==vendor_cfg_.base_frame());
}
CartesianPose AuboArm::fk(const std::string& base_link, const std::string& ee_link)
{
// Never silently label a base-frame result as a requested user/world frame.
// The SDK RobotState getters below always report poses relative to base.
const bool base = base_link.empty() || base_link=="base" ||
base_link=="__builtin_base__" ||
(!vendor_cfg_.base_frame().empty() && base_link==vendor_cfg_.base_frame());
if(!base)throw std::invalid_argument(
"GetPose: this reference is not supported by the native SDK pose query: "+base_link+
"; request base explicitly; no coordinate conversion has been performed");
if(!isBaseReference(base_link))throw std::invalid_argument("GetPose: unsupported native reference: "+base_link);
if(ee_link=="flange" || ee_link=="tool0")return fk(false);
if(ee_link.empty() || ee_link=="tcp" ||
(!vendor_cfg_.tool_frame().empty() && ee_link==vendor_cfg_.tool_frame()))return fk(true);
throw std::invalid_argument("GetPose: unsupported end frame: "+ee_link);
}
Result AuboArm::getPoseInCoordinate(const std::string& name,const std::vector<double>& base_reference,
const std::string& end_frame,CartesianPose& pose)
{
#if defined(CMVR_HAS_AUBO_SDK)
const auto connected=ensureConnected_("GetPose");if(!connected.ok())return connected;
auto reference=base_reference;
const bool tool=name=="__builtin_tool__";
if(tool){
std::lock_guard<std::mutex> lock(user_coordinate_mutex_);
if(!user_coordinates_active_.load() || applied_user_coordinate_name_!=name)
return Result::failure(ArmErrorCode::RobotNotReady,"GetPose: apply the tool reference first; its origin is captured at Apply");
reference=applied_base_user_pose_;
}
try {
const auto actual=fk("base",end_frame);
auto math=sdk_->rpc_client->getMath();
if(!math)return Result::failure(ArmErrorCode::CommandFailed,"GetPose: SDK Math is unavailable");
const auto result=coordinateFeedbackPose(reference,
std::vector<double>{actual.x,actual.y,actual.z,actual.rx,actual.ry,actual.rz},
[&math](const auto& p){return math->poseInverse(p);},
[&math](const auto& a,const auto& b){return math->poseTrans(a,b);});
if(tool){
std::lock_guard<std::mutex> lock(user_coordinate_mutex_);
if(!user_coordinates_active_.load() || applied_user_coordinate_name_!=name || applied_base_user_pose_!=reference)
return Result::failure(ArmErrorCode::RobotNotReady,"GetPose: tool reference changed during query; query again");
}
pose=auboPoseFromVector(result,"SDK Math selected-frame GetPose");return Result::success();
} catch(const std::invalid_argument& e){return Result::failure(ArmErrorCode::InvalidArgument,e.what());}
catch(const std::exception& e){return Result::failure(ArmErrorCode::CommandFailed,e.what());}
#else
return unsupported_("GetPose in selected coordinate");
#endif
}
CartesianPose AuboArm::fk(bool is_tcp)
{
#if defined(CMVR_HAS_AUBO_SDK)

View File

@ -0,0 +1,49 @@
#include "devices/arm/aubo_arm/include/three_point_frame.h"
#include <Eigen/Geometry>
#include <iostream>
#include <limits>
using Pose=std::vector<double>;
using namespace cmvr::device;
#define CHECK(x) do{if(!(x)){std::cerr<<"FAIL "<<__LINE__<<": "<<#x<<"\n";return 1;}}while(false)
Eigen::Isometry3d matrix(const Pose& p){
Eigen::Isometry3d t=Eigen::Isometry3d::Identity();
t.translation()=Eigen::Vector3d(p[0],p[1],p[2]);
t.linear()=(Eigen::AngleAxisd(p[5],Eigen::Vector3d::UnitZ())*
Eigen::AngleAxisd(p[4],Eigen::Vector3d::UnitY())*
Eigen::AngleAxisd(p[3],Eigen::Vector3d::UnitX())).toRotationMatrix();
return t;
}
Pose compose(const Pose& a,const Pose& b){
const auto t=matrix(a)*matrix(b);const auto rpy=t.rotation().eulerAngles(2,1,0);
return {t.translation().x(),t.translation().y(),t.translation().z(),rpy[2],rpy[1],rpy[0]};
}
bool close(const Pose& a,const Eigen::Isometry3d& b){return (matrix(a).matrix()-b.matrix()).norm()<1e-10;}
int main(){
const double pi=std::acos(-1.0);
const Pose reference{1,2,3,0,0,pi/2},target{.2,.3,.4,.1,.2,.3};
auto result=coordinateAbsoluteTarget(reference,target,compose);
CHECK(std::abs(result[0]-.7)<1e-10&&std::abs(result[1]-2.2)<1e-10&&std::abs(result[2]-3.4)<1e-10);
CHECK(close(result,matrix(reference)*matrix(target)));
auto again=coordinateAbsoluteTarget(reference,target,compose);
CHECK(close(again,matrix(result))); // Repeated absolute goal never accumulates.
CHECK(close(coordinateAbsoluteTarget(reference,Pose(6,0),compose),matrix(reference)));
CHECK(close(coordinateAbsoluteTarget(Pose(6,0),target,compose),matrix(target)));
auto otherOrientation=target;otherOrientation[3]=-.7;otherOrientation[4]=.8;otherOrientation[5]=-.9;
const auto changed=coordinateAbsoluteTarget(reference,otherOrientation,compose);
for(int i=0;i<3;++i)CHECK(std::abs(changed[i]-result[i])<1e-10);
CHECK(close(changed,matrix(reference)*matrix(otherOrientation)));
const Pose tilted{-.72109,.30847,.78155,-1.5701438912895,-.0038997188954,.681738622814};
CHECK(close(coordinateAbsoluteTarget(tilted,target,compose),matrix(tilted)*matrix(target)));
const auto inverse=[](const Pose& p){
const auto t=matrix(p).inverse();const auto rpy=t.rotation().eulerAngles(2,1,0);
return Pose{t.translation().x(),t.translation().y(),t.translation().z(),rpy[2],rpy[1],rpy[0]};
};
CHECK(close(coordinateFeedbackPose(reference,result,inverse,compose),matrix(target)));
CHECK(close(coordinateFeedbackPose(tilted,coordinateAbsoluteTarget(tilted,target,compose),inverse,compose),matrix(target)));
CHECK(close(coordinateFeedbackPose(reference,reference,inverse,compose),Eigen::Isometry3d::Identity()));
CHECK(close(coordinateFeedbackPose(Pose(6,0),target,inverse,compose),matrix(target)));
bool rejected=false;try{auto bad=target;bad[3]=std::numeric_limits<double>::quiet_NaN();coordinateAbsoluteTarget(reference,bad,compose);}catch(const std::invalid_argument&){rejected=true;}CHECK(rejected);
rejected=false;try{coordinateAbsoluteTarget(Pose{0},target,compose);}catch(const std::invalid_argument&){rejected=true;}CHECK(rejected);
rejected=false;try{coordinateAbsoluteTarget(reference,target,[](const auto&,const auto&){return Pose{0};});}catch(const std::runtime_error&){rejected=true;}CHECK(rejected);
std::cout<<"PASS: absolute XYZ and orientation, fixed reference, no accumulation, zero target, invalid inputs; no SDK or hardware calls\n";
}

View File

@ -2,6 +2,7 @@
#define CMVR_ES_ROBOT_ARM_H
#include <cstddef>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
@ -65,6 +66,13 @@ public:
return false;
}
// Queue-safe coordinate selection: caller already owns the control lease.
// Unsupported backends must fail rather than silently execute in another frame.
virtual Result applyUserCoordinateSystem(const std::string&, std::uint64_t)
{
return Result::failure(ArmErrorCode::UnsupportedCommand,
"user coordinate selection is not supported by this arm");
}
virtual Result torqueOn() = 0;
virtual Result torqueOff() = 0;
virtual Result calibrateZeroQ(const std::string& joint_name) = 0;

View File

@ -40,6 +40,8 @@ bool finiteNonNegative(const double value)
const char* actionCommandName(const api::ActionStep::CommandCase command)
{
switch (command) {
case api::ActionStep::kArmApplyUserCoordinate:
return "ApplyUserCoordinateSystem";
case api::ActionStep::kArmMoveJ:
return "MoveJ";
case api::ActionStep::kArmMoveL:
@ -162,6 +164,30 @@ struct ActionQueue::Impl {
void registerCommands()
{
handlers.emplace(
api::ActionStep::kArmApplyUserCoordinate,
CommandHandler{
[this](const api::ActionStep& step,const std::size_t index,
PreparedStep& prepared,std::string& error){
const auto& command=step.arm_apply_user_coordinate();
return prepareArmStep(step,command.header().device_id(),index,
api::MotionOptions{},prepared,error,[&command,&error](const device::RobotArm&){
if(command.name().empty()){
error="coordinate name is required";return false;
}
if(command.has_coordinate()){
error="queue coordinate selection accepts only name and expected_revision; save the coordinate before submitting";return false;
}
return true;
});
},
[](const PreparedStep& prepared,const std::function<bool()>& canceled){
if(canceled())return device::Result::failure(device::ArmErrorCode::CommandRejected,"coordinate selection canceled before execution");
const auto& command=prepared.source.arm_apply_user_coordinate();
// Do not reacquire the arbiter: the queue owns the lease for its full duration.
return prepared.arm->applyUserCoordinateSystem(command.name(),command.expected_revision());
}});
handlers.emplace(
api::ActionStep::kArmMoveJ,
CommandHandler{

View File

@ -45,6 +45,14 @@ public:
}
bool supportsActionQueueMotion() const noexcept override { return true; }
bool fail_coordinate=false;
device::Result applyUserCoordinateSystem(const std::string& name,std::uint64_t revision) override {
std::lock_guard lock(mutex_);
calls_.push_back("Apply:"+name);
if(fail_coordinate || revision==999)return device::Result::failure(device::ArmErrorCode::InvalidArgument,"coordinate missing or revision changed");
selected_coordinate_=name;return device::Result::success();
}
std::vector<std::string> motionCoordinates() const {std::lock_guard lock(mutex_);return motion_coordinates_;}
device::Result torqueOn() override { return device::Result::success(); }
device::Result torqueOff() override { return device::Result::success(); }
device::Result calibrateZeroQ(const std::string&) override { return device::Result::success(); }
@ -78,6 +86,7 @@ public:
const device::MotionOptions& options,
device::FrameType) override
{
{std::lock_guard lock(mutex_);motion_coordinates_.push_back(selected_coordinate_);}
return runMotion("MoveL", options);
}
device::Result moveL(const device::CartesianPose&,
@ -170,6 +179,8 @@ public:
}
private:
std::string selected_coordinate_;
std::vector<std::string> motion_coordinates_;
device::Result runMotion(const std::string& name,
const device::MotionOptions& options)
{
@ -241,6 +252,43 @@ api::ActionQueueCommand_Request twoStepRequest(const std::string& device_id)
return request;
}
TEST(ActionQueueTest, AppliesCoordinatesBeforeEachMoveL)
{
auto arm=std::make_shared<FakeActionQueueArm>("coordinate_queue");auto queue=makeQueue(arm);
api::ActionQueueCommand_Request request;
for(const auto* name:{"fixture_a","__builtin_base__"}){
auto* apply=request.add_steps()->mutable_arm_apply_user_coordinate();
apply->mutable_header()->set_device_id(arm->id());apply->set_name(name);apply->set_expected_revision(1);
auto* move=request.add_steps()->mutable_arm_move_l();move->mutable_header()->set_device_id(arm->id());
}
api::ActionQueueCommand_Feedback result;queue.execute(request,result);
EXPECT_TRUE(result.header().success())<<result.header().error_message();EXPECT_EQ(result.completed_steps(),4U);
EXPECT_EQ(arm->calls(),(std::vector<std::string>{"Apply:fixture_a","MoveL","Apply:__builtin_base__","MoveL"}));
EXPECT_EQ(arm->motionCoordinates(),(std::vector<std::string>{"fixture_a","__builtin_base__"}));
}
TEST(ActionQueueTest, FailedCoordinateDoesNotRunFollowingMotion)
{
for(bool fail:{false,true}){
auto arm=std::make_shared<FakeActionQueueArm>("coordinate_failure");arm->fail_coordinate=fail;auto queue=makeQueue(arm);
api::ActionQueueCommand_Request request;
auto* apply=request.add_steps()->mutable_arm_apply_user_coordinate();apply->mutable_header()->set_device_id(arm->id());
apply->set_name("fixture");apply->set_expected_revision(fail?1:999);
request.add_steps()->mutable_arm_move_l()->mutable_header()->set_device_id(arm->id());
api::ActionQueueCommand_Feedback result;queue.execute(request,result);
EXPECT_EQ(result.result(),api::ACTION_RESULT_CODE_FAILED);EXPECT_EQ(result.completed_steps(),0U);EXPECT_EQ(result.failed_step_index(),0U);
EXPECT_EQ(arm->calls(),(std::vector<std::string>{"Apply:fixture"}));
}
}
TEST(ActionQueueTest, InvalidCoordinateStepRejectsWholeQueue)
{
auto arm=std::make_shared<FakeActionQueueArm>("coordinate_invalid");auto queue=makeQueue(arm);
auto request=twoStepRequest(arm->id());request.add_steps()->mutable_arm_apply_user_coordinate()->mutable_header()->set_device_id(arm->id());
api::ActionQueueCommand_Feedback result;queue.execute(request,result);
EXPECT_EQ(result.result(),api::ACTION_RESULT_CODE_REJECTED);EXPECT_TRUE(arm->calls().empty());
}
TEST(ActionQueueTest, ExecutesMoveJAndNamedFrameMoveLInOrder)
{
auto arm = std::make_shared<FakeActionQueueArm>("action_arm_order");

View File

@ -330,17 +330,37 @@ grpc::Status gRPCArmServiceImpl::moveL(grpc::ServerContext* context,
const api::MoveL_Request* request,
api::MoveL_Response* response)
{
const char* stage="control_acquire";
const auto log_failure=[request](const char* failure_stage,const std::string& error) {
CMVR_LOG(ERROR) << "[gRPCArmServiceImpl] (moveL): failed, id=" << request->header().device_id()
<< ", stage=" << failure_stage
<< ", coordinate=" << request->user_coordinate_name()
<< ", requested_revision=" << request->user_coordinate_revision()
<< ", relative_translation=" << request->coordinate_relative_translation()
<< ", frame=" << request->frame()
<< ", base_frame=" << request->base_frame()
<< ", tcp_frame=" << request->tcp_frame()
<< ", error=" << error;
};
const auto finish_result=[&](const device::Result& result) {
if(!result.ok())log_failure(stage,result.message);
return setResponseResult(response,result);
};
auto control_lease =
ControlCommandArbiter::instance().tryAcquireControl();
if (!control_lease) {
log_failure(stage,"control command rejected while ActionQueue or StopAll is active");
return setControlBusy(response);
}
try {
const std::string device_id = request->header().device_id();
stage="device_lookup";
auto arm = dmgr_.getDevice<device::RobotArm>(device_id);
if (!arm) {
log_failure(stage,"device not found");
return setDeviceNotFound(response, device_id);
}
stage="parameter_validation";
const bool has_named_frame =
(request->has_base_frame() && !request->base_frame().empty()) ||
(request->has_tcp_frame() && !request->tcp_frame().empty());
@ -355,18 +375,27 @@ grpc::Status gRPCArmServiceImpl::moveL(grpc::ServerContext* context,
<< ", frame=" << request->frame();
const bool explicit_user_frame = request->user_frame_pose_size() || request->tcp_offset_size();
device::Result result;
if(request->coordinate_relative_translation() && request->user_coordinate_name().empty())return setResponseResult(response,device::Result::failure(device::ArmErrorCode::InvalidArgument,"relative translation requires named applied coordinate"));
if(request->coordinate_relative_translation())return finish_result(device::Result::failure(device::ArmErrorCode::UnsupportedCommand,"incremental MoveL is not supported; send an absolute XYZ/RX/RY/RZ target in the selected coordinate system and omit coordinate_relative_translation or set it false"));
if (!request->user_coordinate_name().empty()) {
auto aubo=std::dynamic_pointer_cast<device::AuboArm>(arm);
if(!aubo || has_named_frame || explicit_user_frame)
return setResponseResult(response,device::Result::failure(device::ArmErrorCode::InvalidArgument,"saved user coordinates cannot combine with explicit frame parameters and require AUBO"));
return finish_result(device::Result::failure(device::ArmErrorCode::InvalidArgument,"saved user coordinates cannot combine with explicit frame parameters and require AUBO"));
stage="coordinate_lookup";
const auto profile=device::UserCoordinateStore::forArm(device_id).get(request->user_coordinate_name(),request->user_coordinate_revision());
if(!aubo->currentUserCoordinateMatches(profile.name,profile.revision))
return setResponseResult(response,device::Result::failure(device::ArmErrorCode::CommandRejected,"requested coordinate is not currently applied; call ApplyUserCoordinateSystem first"));
result=request->coordinate_relative_translation()
? aubo->moveLRelativeInCoordinate(toCartesianPose(request->target()),options)
: arm->moveL(toCartesianPose(request->target()),options,device::FrameType::Base);
stage="coordinate_application_check";
if(!aubo->currentUserCoordinateMatches(profile.name,profile.revision)) {
std::string applied_name;std::uint64_t applied_revision{};
const bool known=aubo->lastAppliedUserCoordinate(applied_name,applied_revision);
const auto failure=device::Result::failure(device::ArmErrorCode::CommandRejected,
"requested coordinate is not currently applied; call ApplyUserCoordinateSystem first");
log_failure(stage,failure.message+"; applied_name="+applied_name+
", applied_revision="+std::to_string(applied_revision)+", application_known="+(known?"true":"false"));
return setResponseResult(response,failure);
}
stage="execute";
result=arm->moveL(toCartesianPose(request->target()),options,device::FrameType::Base);
} else if (explicit_user_frame) {
stage="execute_inline_frame";
auto aubo = std::dynamic_pointer_cast<device::AuboArm>(arm);
if (!aubo || has_named_frame) {
result = device::Result::failure(device::ArmErrorCode::InvalidArgument,
@ -376,7 +405,9 @@ grpc::Status gRPCArmServiceImpl::moveL(grpc::ServerContext* context,
std::vector<double>(request->user_frame_pose().begin(),request->user_frame_pose().end()),
std::vector<double>(request->tcp_offset().begin(),request->tcp_offset().end()));
}
} else result = has_named_frame
} else {
stage="execute";
result = has_named_frame
? arm->moveL(toCartesianPose(request->target()),
options,
request->has_base_frame()
@ -388,6 +419,7 @@ grpc::Status gRPCArmServiceImpl::moveL(grpc::ServerContext* context,
: arm->moveL(toCartesianPose(request->target()),
options,
toFrameType(request->frame()));
}
if (result.ok()) {
CMVR_LOG(DEBUG) << "[gRPCArmServiceImpl] (moveL): success, id=" << device_id
<< ", frame=" << request->frame()
@ -399,16 +431,15 @@ grpc::Status gRPCArmServiceImpl::moveL(grpc::ServerContext* context,
<< (request->has_tcp_frame()
? request->tcp_frame()
: "<default>");
} else {
CMVR_LOG(DEBUG) << "[gRPCArmServiceImpl] (moveL): finished, id="
<< device_id << ", error=" << result.message;
}
return setResponseResult(response, result);
return finish_result(result);
} catch (const device::CoordinateStoreError& e) {
log_failure(stage,e.what());
fillFeedback(response->mutable_header(),false,e.what());
return grpc::Status(e.kind==device::CoordinateStoreError::Missing?grpc::StatusCode::NOT_FOUND:
e.kind==device::CoordinateStoreError::Conflict?grpc::StatusCode::ABORTED:grpc::StatusCode::INVALID_ARGUMENT,e.what());
} catch (const std::exception& e) {
log_failure(stage,e.what());
fillFeedback(response->mutable_header(), false, e.what());
return grpc::Status(grpc::StatusCode::INTERNAL, e.what());
}
@ -643,6 +674,9 @@ grpc::Status gRPCArmServiceImpl::getJointState(grpc::ServerContext*,
for (double v : state.velocity) msg->add_velocity(v);
for (double v : state.effort) msg->add_effort(v);
for (double v : state.current) msg->add_current(v);
// JointGroupState has no controller sample timestamp; report host read time.
const auto received_at = TimeUtil::GetCurrentTime();
msg->set_timestamp(static_cast<double>(received_at.seconds()) + received_at.nanos() * 1e-9);
fillFeedback(response->mutable_header(), true);
// CMVR_LOG(DEBUG) << "[gRPCArmServiceImpl] (getJointState): success, id=" << device_id
// << ", joints=" << msg->name_size()
@ -686,13 +720,21 @@ grpc::Status gRPCArmServiceImpl::getPose(grpc::ServerContext*,
return setDeviceNotFound(response, device_id);
}
const auto aubo=std::dynamic_pointer_cast<device::AuboArm>(arm);
const auto pose = aubo ? aubo->fk(request->base_link(),request->ee_link())
: request->base_link().empty() || request->ee_link().empty()
? arm->fk(true)
: arm->fk(request->base_link(), request->ee_link());
device::CartesianPose pose;
std::string reference="base";
if(aubo && !aubo->isBaseReference(request->base_link())){
const auto profile=device::UserCoordinateStore::forArm(device_id).get(request->base_link(),0);
const auto result=aubo->getPoseInCoordinate(profile.name,profile.user_pose,request->ee_link(),pose);
if(!result.ok())return setResponseResult(response,result);
reference=profile.name;
}else{
pose=aubo ? aubo->fk(request->base_link(),request->ee_link())
: request->base_link().empty() || request->ee_link().empty()
? arm->fk(true) : arm->fk(request->base_link(),request->ee_link());
}
*response->mutable_pose() = toApiCartesianPose(pose);
if(aubo){
response->set_reference_frame("base");
response->set_reference_frame(reference);
response->set_end_frame(request->ee_link()=="flange"||request->ee_link()=="tool0"?"flange":"tcp");
}
fillFeedback(response->mutable_header(), true);
@ -700,6 +742,10 @@ grpc::Status gRPCArmServiceImpl::getPose(grpc::ServerContext*,
<< ", pose=(" << pose.x << ", " << pose.y << ", " << pose.z
<< ", " << pose.rx << ", " << pose.ry << ", " << pose.rz << ")";
return grpc::Status::OK;
} catch(const device::CoordinateStoreError& e){
fillFeedback(response->mutable_header(),false,e.what());
return grpc::Status(e.kind==device::CoordinateStoreError::Missing?grpc::StatusCode::NOT_FOUND:
e.kind==device::CoordinateStoreError::Invalid?grpc::StatusCode::INVALID_ARGUMENT:grpc::StatusCode::INTERNAL,e.what());
} catch (const std::invalid_argument& e) {
fillFeedback(response->mutable_header(), false, e.what());
return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, e.what());

View File

@ -19,6 +19,7 @@
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <netdb.h>
#include <sys/socket.h>
#include <unistd.h>
@ -191,24 +192,43 @@ std::vector<v1::NetworkInterfaceAddress> collectInterfaceAddresses(
return addresses;
}
std::string advertisedGrpcHost(
const config::QuicEdgeConfig& config,
const std::vector<v1::NetworkInterfaceAddress>& interfaces)
// Ask the kernel which local source address routes to this platform. UDP connect
// selects a route only; it does not transmit a datagram or establish a session.
std::string advertisedGrpcHost(const config::QuicEdgeConfig& config)
{
if (!config.grpc_endpoint_host().empty() &&
config.grpc_endpoint_host() != "auto") {
if (!config.grpc_endpoint_host().empty() && config.grpc_endpoint_host() != "auto")
return config.grpc_endpoint_host();
}
for (const auto& address : interfaces) {
if (!address.loopback() &&
address.family() == v1::NetworkInterfaceAddress::ADDRESS_FAMILY_IPV4) {
return address.ip_address();
// Match the destination name actually passed to MsQuic ConnectionStart.
const auto& host = config.tls().allow_insecure() || config.tls().server_name().empty()
? config.server_host() : config.tls().server_name();
addrinfo hints{};hints.ai_family=AF_UNSPEC;hints.ai_socktype=SOCK_DGRAM;
hints.ai_protocol=IPPROTO_UDP;
addrinfo* addresses=nullptr;
const auto port=std::to_string(config.server_port());
if(::getaddrinfo(host.c_str(),port.c_str(),&hints,&addresses)!=0)return {};
std::string result;
for(const auto* address=addresses;address;address=address->ai_next){
const int fd=::socket(address->ai_family,SOCK_DGRAM,IPPROTO_UDP);
if(fd<0)continue;
sockaddr_storage local{};socklen_t size=sizeof(local);
const bool ok=::connect(fd,address->ai_addr,address->ai_addrlen)==0 &&
::getsockname(fd,reinterpret_cast<sockaddr*>(&local),&size)==0;
::close(fd);
if(!ok)continue;
const void* source=nullptr;int family=local.ss_family;
if(family==AF_INET)source=&reinterpret_cast<const sockaddr_in*>(&local)->sin_addr;
else if(family==AF_INET6){
const auto* ipv6=&reinterpret_cast<const sockaddr_in6*>(&local)->sin6_addr;
if(IN6_IS_ADDR_V4MAPPED(ipv6)){family=AF_INET;source=&ipv6->s6_addr[12];}
else source=ipv6;
}
std::array<char,INET6_ADDRSTRLEN> text{};
if(source && ::inet_ntop(family,source,text.data(),text.size()) &&
std::strcmp(text.data(),"0.0.0.0")!=0 && std::strcmp(text.data(),"::")!=0){result=text.data();break;}
}
for (const auto& address : interfaces) {
if (!address.loopback()) return address.ip_address();
}
return interfaces.empty() ? "127.0.0.1" : interfaces.front().ip_address();
::freeaddrinfo(addresses);
// Do not silently advertise an unrelated NIC when destination lookup fails.
return result;
}
void populateDescriptor(const config::QuicEdgeConfig& config,
@ -228,7 +248,7 @@ void populateDescriptor(const config::QuicEdgeConfig& config,
*descriptor->add_local_interfaces() = address;
}
auto* endpoint = descriptor->mutable_grpc_endpoint();
endpoint->set_host(advertisedGrpcHost(config, interfaces));
endpoint->set_host(advertisedGrpcHost(config));
endpoint->set_port(config.grpc_endpoint_port());
endpoint->set_tls(config.grpc_endpoint_tls());
}
@ -243,7 +263,7 @@ void populateHeartbeatNetwork(const config::QuicEdgeConfig& config,
*heartbeat->add_local_interfaces() = address;
}
auto* endpoint = heartbeat->mutable_grpc_endpoint();
endpoint->set_host(advertisedGrpcHost(config, interfaces));
endpoint->set_host(advertisedGrpcHost(config));
endpoint->set_port(config.grpc_endpoint_port());
endpoint->set_tls(config.grpc_endpoint_tls());
}
@ -1160,6 +1180,10 @@ bool QuicEdgeService::sendNodeRegistration(std::string* error)
auto* request = envelope.mutable_node_register_request();
populateDescriptor(config_, node_id_, boot_id_, software_version_,
request->mutable_node());
if(request->node().grpc_endpoint().host().empty()){
setError(error,"cannot select a local gRPC address routed to QUIC platform "+config_.server_host());
return false;
}
request->set_sent_at_unix_ms(unixTimeMs());
std::string serialized;
if (!envelope.SerializeToString(&serialized)) {
@ -1229,6 +1253,10 @@ bool QuicEdgeService::sendHeartbeat(const std::uint64_t sequence,
heartbeat->set_sent_at_unix_ms(sent_at_unix_ms);
heartbeat->set_software_version(software_version_);
populateHeartbeatNetwork(config_, heartbeat);
if(heartbeat->grpc_endpoint().host().empty()){
setError(error,"cannot select a local gRPC address routed to QUIC platform "+config_.server_host());
return false;
}
if (device_manager_snapshot.has_value()) {
populateDeviceManagerSnapshot(
*device_manager_snapshot, sent_at_unix_ms,

View File

@ -107,6 +107,7 @@ public:
last_registered_node_id_ = request.node().node_id();
last_registered_robot_id_ = request.node().robot_id();
last_grpc_endpoint_port_ = request.node().grpc_endpoint().port();
last_grpc_endpoint_host_ = request.node().grpc_endpoint().host();
last_interface_count_ = request.node().local_interfaces_size();
cmvr::quic_edge::v1::EdgeControlEnvelope response;
response.set_protocol_version(quic_edge::kProtocolVersion);
@ -260,6 +261,8 @@ public:
return last_registered_robot_id_;
}
std::string lastGrpcEndpointHost() const { std::lock_guard lock(mutex_);return last_grpc_endpoint_host_; }
std::uint32_t lastGrpcEndpointPort() const
{
std::lock_guard lock(mutex_);
@ -343,6 +346,7 @@ private:
std::uint64_t server_message_sequence_{0};
std::string last_registered_node_id_;
std::string last_registered_robot_id_;
std::string last_grpc_endpoint_host_;
std::uint32_t last_grpc_endpoint_port_{0};
int last_interface_count_{0};
std::vector<std::vector<std::uint8_t>> controls_;
@ -519,6 +523,8 @@ bool testServiceWithSharedHub()
CHECK_TRUE(transport_view->lastRegisteredRobotId() ==
"CN-CMVR-MBLRV1-CHAGAN-20260731-001");
CHECK_TRUE(transport_view->lastGrpcEndpointPort() == 50052U);
CHECK_TRUE(transport_view->lastGrpcEndpointHost() == "127.0.0.1");
CHECK_TRUE(transport_view->lastHeartbeat().grpc_endpoint().host() == "127.0.0.1");
CHECK_TRUE(transport_view->connectCount() == 1U);
media::MediaFrame::Config frame_config;

View File

@ -158,8 +158,8 @@ message UserCoordinateSystem {
// 内置记录标识:__builtin_base__(基座)、__builtin_tool__(工具)。
// List/Get 默认提供,revision 固定为 1;禁止 Create/Update/Delete。
// 内置记录的 user_pose/tcp_offset 全零仅作协议占位,不是实际 TCP 回读。
// Apply 保留当前 TCP 偏移,恢复基座 WorkObject;工具模式每次 MoveL
// 将 target 解释为相对下发时当前 TCP 的位姿增量,基座模式为绝对位姿。
// Apply 保留当前 TCP 偏移。基座模式使用Base绝对目标;工具模式固定
// Apply时的实际TCP为参考,后续MoveL使用相对该固定参考的绝对目标,不累加。
string name = 1;
// 服务端 SDK 三点标定结果 T_base_user,[x,y,z,rx,ry,rz],m/rad,RzRyRx。
// Create/Update 不采用客户端提供的该字段,只采用 calibration_points 重新计算。
@ -202,7 +202,8 @@ message MoveL {
message Request {
// 通用请求头,包含目标设备 ID 和请求时间戳。
CommandHeader.Request header = 1;
// TCP 目标位姿;位置单位为 m,姿态单位为 rad。
// 所选坐标系下的完整绝对TCP目标位姿:位置m、姿态rad(RzRyRx)。
// XYZ/RX/RY/RZ均为目标值,不是增量。重复同一目标不会累加移动。
CartesianPose target = 2;
// 运动参数;速度/加速度/加加速度单位分别为 m/s、m/s^2、m/s^3。
MotionOptions options = 3;
@ -220,13 +221,14 @@ message MoveL {
// T_flange_tcp, [x,y,z,rx,ry,rz], m/rad. Required together with user_frame_pose.
repeated double tcp_offset = 8;
// 校验当前已应用的服务端坐标系名称,不自动切换;请先调用 ApplyUserCoordinateSystem。
// 不传时沿用 SDK 当前工件系;不能与显式位姿或命名世界坐标系同时传入。
// 不传时沿用服务端当前已应用记录;不能与显式位姿或命名世界坐标系同时传入。
string user_coordinate_name = 9;
// 所选记录的版本号,非零时拒绝执行已被修改的记录。
uint64 user_coordinate_revision = 10;
// Translate from current actual TCP along selected frame axes; target.rx/ry/rz must be zero.
// Target xyz is a displacement in metres, orientation is held unchanged.
bool coordinate_relative_translation = 11;
// Deprecated increment mode. Must be false or omitted; true returns UNIMPLEMENTED.
// Check get_active_tcp_offset.coordinate_api_version >= 4 and
// movel_target_mode == "absolute_selected_frame" before using this contract.
bool coordinate_relative_translation = 11 [deprecated = true];
}
// MoveL 执行结果。
@ -465,7 +467,9 @@ message GetPose {
message Request {
// 通用请求头,包含目标设备 ID 和请求时间戳。
CommandHeader.Request header = 1;
// 参考坐标系名称,无单位;为空时使用驱动默认基准坐标系。
// 参考坐标系名称。遨博支持空/base/__builtin_base__(基座)、已保存的自定义坐标系名称,
// 以及 __builtin_tool__(必须先 Apply,使用 Apply 时冻结的工具参考系)。
// 自定义系按服务端当前保存的定义转换实际反馈;查询不切换当前应用,不触发运动。
string base_link = 2;
// 末端坐标系名称,无单位;为空时使用驱动默认 TCP 坐标系。
string ee_link = 3;
@ -477,8 +481,8 @@ message GetPose {
CommandHeader.Feedback header = 1;
// TCP 位姿;位置单位为 m,姿态单位为 rad。
CartesianPose pose = 2;
// 实际返回值的参考坐标系。遨博原生 RobotState 反馈固定为 base,
// 不会仅因 setWorkObjectData 被调用就变成用户坐标系。
// 实际返回位姿的参考坐标系:base 或请求的已保存坐标系名称。
// SDK 原生反馈始终在 Base 下;请求自定义系时由服务端使用 SDK Math 转换。
string reference_frame = 3;
// 实际返回的末端:tcp 为当前工具中心点,flange 为法兰。
string end_frame = 4;

View File

@ -15,7 +15,7 @@ service ArmService {
rpc clearFault(CommandHeader.Request) returns (CommandHeader.Feedback);
// 执行关节空间点到点运动;目标角度单位为 rad。
rpc moveJ(MoveJ.Request) returns (MoveJ.Response);
// 执行 TCP 笛卡尔直线运动;位置单位为 m,姿态单位为 rad。
// 执行所选坐标系下的绝对TCP目标直线运动,位置m、姿态rad;不接受增量目标。
rpc moveL(MoveL.Request) returns (MoveL.Response);
// 查询可用基准坐标系名称;返回名称列表,无单位。
rpc ListBaseFrame(ListFrame.Request) returns (ListFrame.Response);

View File

@ -122,6 +122,11 @@ message ActionStep {
oneof command {
MoveJ.Request arm_move_j = 10;
MoveL.Request arm_move_l = 11;
// Apply a saved coordinate before subsequent arm steps. Uses header.device_id,
// name and expected_revision (0 = latest); coordinate payload is not accepted.
// AUBO MoveL without legacy frame overrides follows this selection until switched.
// Switching does not move the arm. A failure aborts the remaining queue.
UserCoordinateSystemCommand.Request arm_apply_user_coordinate = 12;
}
}