Skip to content

Instantly share code, notes, and snippets.

@jwpleow
Created May 5, 2023 07:00
Show Gist options
  • Select an option

  • Save jwpleow/125e5c3021da2b08cb3490aa79500a7d to your computer and use it in GitHub Desktop.

Select an option

Save jwpleow/125e5c3021da2b08cb3490aa79500a7d to your computer and use it in GitHub Desktop.
test
#include <bosdyn/api/geometry.pb.h>
#include <CLI/CLI.hpp>
#include <chrono>
#include <thread>
#include "bosdyn/client/sdk/client_sdk.h"
#include "bosdyn/client/lease/lease_client.h"
#include "bosdyn/math/frame_helpers.h"
#include "bosdyn/math/proto_math.h"
#include "bosdyn/client/robot_command/robot_command_builder.h"
#include "bosdyn/client/robot_command/robot_command_client.h"
#include "bosdyn/client/robot_id/robot_id_client.h"
#include "bosdyn/client/time_sync/time_sync_helpers.h"
#include "bosdyn/client/util/cli_util.h"
#include "bosdyn/client/estop/estop_client.h"
#include "bosdyn/client/estop/estop_keepalive.h"
#include "bosdyn/client/estop/estop_endpoint.h"
int main(int argc, char** argv) {
// Parse the arguments.
CLI::App parser{"BasicRobotCommand"};
::bosdyn::client::CommonCLIArgs common_args;
::bosdyn::client::AddCommonArguments(parser, common_args);
CLI11_PARSE(parser, argc, argv);
// Create a Client SDK object.
std::unique_ptr<::bosdyn::client::ClientSdk> client_sdk = ::bosdyn::client::CreateStandardSDK("basic_cmd_spot");
// Create a robot instance. A robot instance represents a single user on a single robot.
::bosdyn::client::Result<std::unique_ptr<::bosdyn::client::Robot>> robot_result =
client_sdk->CreateRobot(common_args.hostname);
if (!robot_result.status) {
std::cerr << "Could not create robot: " << robot_result.status.DebugString() << std::endl;
return 0;
}
std::unique_ptr<::bosdyn::client::Robot> robot = std::move(robot_result.response);
// Set the username and password to use for authentication with the robot.
auto status = robot->Authenticate(common_args.username, common_args.password);
if (!status) {
std::cerr << "Could not authenticate with robot: " << status.DebugString() << std::endl;
return 0;
}
std::cout << "------Robot instance configured" << std::endl;
auto estop_client_resp = robot->EnsureServiceClient<::bosdyn::client::EstopClient>(::bosdyn::client::EstopClient::GetDefaultServiceName());
if(!estop_client_resp){
std::cout << "Estop client fail: " << estop_client_resp.status.DebugString() << "\n";
return 0;
}
auto _estopClient = estop_client_resp.move();
std::cout << "Created estop client!\n";
auto _estopEndpoint = std::make_unique<::bosdyn::client::EstopEndpoint>(_estopClient, std::string("basic_cmd_spot"), ::bosdyn::common::Duration(20));
std::cout << "Created estop endpoint!\n";
const auto estopSetupStatus = _estopEndpoint->ForceSimpleSetup();
if (!estopSetupStatus) {
std::cout << "Estop simple setup failed: " << estopSetupStatus.DebugString() << "\n";
return 1;
}
std::cout << "Force simple setup went through! " << estopSetupStatus.DebugString() << "\n";
auto _estopKeepalive = std::make_unique<::bosdyn::client::EstopKeepAlive>(_estopEndpoint.get());
const auto statuss = _estopKeepalive->GetEstopEndpoint()->Allow();
if (!statuss) {
std::cout << "EstopKeepalive creation failed: " << statuss.DebugString() << "\n";
return 1;
}
std::cout << "EstopKeepalive allowed: " << statuss.DebugString() << "\n";
while(1){
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
const auto statusss =_estopKeepalive->GetEstopEndpoint()->Stop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment