#include <iostream>
#include <visp3/core/vpConfig.h>
#ifdef VISP_HAVE_NLOHMANN_JSON
#include <visp3/robot/vpSimulatorCamera.h>
#include <visp3/visual_features/vpFeatureBuilder.h>
#include <visp3/vs/vpServo.h>
#include <nlohmann/json.hpp>
using json = nlohmann::json;
enum vpInteractionMatrixTypeSubset
{
UNKNOWN = -1,
CURRENT,
DESIRED,
MEAN
};
NLOHMANN_JSON_SERIALIZE_ENUM(vpInteractionMatrixTypeSubset, {
{UNKNOWN, nullptr},
{CURRENT, "current"},
{DESIRED, "desired"},
{MEAN, "mean"} }
);
{
public:
{ }
{
case CURRENT:
case DESIRED:
case MEAN:
default:
}
}
};
{
}
a.
cMo = j.value(
"cMo", a.
cMo);
}
}
}
}
{
j = json {
};
}
Arguments readArguments(
const std::string &path)
{
if (!path.empty()) {
std::ifstream file(path);
if (!file.good()) {
std::stringstream ss;
ss << "Problem opening file " << path << ". Make sure it exists and is readable" << std::endl;
}
json j;
try {
j = json::parse(file);
}
catch (json::parse_error &e) {
std::stringstream msg;
msg << "Could not parse JSON file : \n";
msg << e.what() << std::endl;
msg << "Byte position of error: " << e.byte;
}
a = j;
file.close();
}
else {
std::cout << "Using default arguments. Try using a JSON file to set the arguments of the visual servoing." << std::endl;
}
return a;
}
{
j = json {
};
}
{
public:
m_arguments(arguments), m_desiredFeatures(desiredFeatures)
{ }
{
m_trajectory.push_back(r);
m_errorNorms.push_back(errorNorm);
m_points3D.push_back(points);
m_velocities.push_back(velocity);
m_interactionMatrices.push_back(interactionMatrix);
}
private:
std::vector<vpFeaturePoint> m_desiredFeatures;
std::vector<vpPoseVector> m_trajectory;
std::vector<double> m_errorNorms;
std::vector<std::vector<vpFeaturePoint> > m_points3D;
std::vector<vpColVector> m_velocities;
std::vector<vpMatrix> m_interactionMatrices;
};
{
j = json {
{
"parameters", res.
m_arguments},
{
"trajectory", res.
m_trajectory},
{
"errorNorm", res.
m_errorNorms},
{
"features", res.
m_points3D},
{
"desiredFeatures", res.
m_desiredFeatures},
{
"velocities", res.
m_velocities},
{
"interactionMatrices", res.
m_interactionMatrices}
};
}
{
std::ofstream file(path);
const json j = results;
file << j.dump(4);
file.close();
}
int main(int argc, char *argv[])
{
std::string arguments_path = "";
std::string output_path = "";
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--settings" && i + 1 < argc) {
arguments_path = std::string(argv[i + 1]);
}
else if (std::string(argv[i]) == "--output" && i + 1 < argc) {
output_path = std::string(argv[i + 1]);
}
}
if (output_path.empty()) {
std::cerr << "JSON output path must be specified" << std::endl;
return EXIT_FAILURE;
}
const Arguments args = readArguments(arguments_path);
try {
std::cout << cdMo << std::endl;
std::vector<vpFeaturePoint> features;
features.resize(4);
for (unsigned int i = 0; i < 4; i++) {
features[i] = pd[i];
}
wMo = wMc * cMo;
unsigned int iter = 0;
bool end = false;
std::cout << "Starting visual-servoing loop until convergence..." << std::endl;
while (!end) {
robot.getPosition(wMc);
for (unsigned int i = 0; i < 4; i++) {
features[i] = p[i];
}
end = true;
}
iter++;
}
std::cout << "Convergence in " << iter << " iterations" << std::endl;
saveResults(results, output_path);
}
std::cout << "Caught an exception: " << e << std::endl;
}
}
#else
int main()
{
std::cerr << "Cannot run tutorial: ViSP is not built with JSON integration. Install the JSON library and recompile ViSP" << std::endl;
}
#endif
vpInteractionMatrixTypeSubset interactionMatrixType
vpServo::vpServoIteractionMatrixType getInteractionMatrixType() const
[Custom ViSP object conversion]
friend void to_json(json &j, const ServoingExperimentData &res)
void onIter(const vpHomogeneousMatrix &cMo, const double errorNorm, const std::vector< vpFeaturePoint > &points, const vpColVector &velocity, const vpMatrix &interactionMatrix)
ServoingExperimentData(const Arguments &arguments, const std::vector< vpFeaturePoint > &desiredFeatures)
Implementation of column vector and the associated operations.
error that can be emitted by ViSP classes.
@ badValue
Used to indicate that a value is not in the allowed range.
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpHomogeneousMatrix inverse() const
Provides simple mathematics computation tools that are not available in the C mathematics library (ma...
Implementation of a matrix and operations on matrices.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
void setWorldCoordinates(double oX, double oY, double oZ)
Implementation of a pose vector and operations on poses.
void setVelocity(const vpRobot::vpControlFrameType frame, const vpColVector &vel) override
vpMatrix getInteractionMatrix() const
void setInteractionMatrixType(const vpServoIteractionMatrixType &interactionMatrixType, const vpServoInversionType &interactionMatrixInversion=PSEUDO_INVERSE)
void addFeature(vpBasicFeature &s_cur, vpBasicFeature &s_star, unsigned int select=vpBasicFeature::FEATURE_ALL)
void setServo(const vpServoType &servo_type)
vpColVector getError() const
vpColVector computeControlLaw()
vpServoIteractionMatrixType
Class that defines the simplest robot: a free flying camera.
VISP_EXPORT int wait(double t0, double t)