Axis AxsJogIncr command

Hello all,
I have been trying to jog the motors via the sdk. i have the x axis in the status standstill. So if i read the docummentation correctly its now ready to recieve move commands. The problem is that i dont know how i need to declare and implement the axisjogcmd. This is done true the axis commands not the kinematic group. I added the code  below. It gives a error about MotionResult  not being declared. 

 


 Thanks in advance

#include <functional>
#include <thread>
#include <limits>

 

#include "ctrlx_datalayer_helper.h"
#include "datalayerclient.h"

 

#include <stdio.h>
#include <iostream>
using namespace std;

 

 

static void printStringList(comm::datalayer::Variant& data)
{
  if (data.getType() == comm::datalayer::VariantType::ARRAY_OF_STRING)
  {
    std::cout << "Node List: ";
    const char** strArray = data;
    for (uint32_t i = 0; i < data.getCount(); i++)
    {
      std::cout << strArray[i] << " ";
    }
    std::cout << std::endl;
  }
}
static void printMetadata(comm::datalayer::Variant& data)
{
  if (STATUS_FAILED(data.verifyFlatbuffers(comm::datalayer::VerifyMetadataBuffer)))
  {
    std::cout << "Invalid Flatbuffer: Not a MetadataBuffer";
    return;
  }

 

  auto metadata = comm::datalayer::GetMetadata(data.getData());
  std::cout << metadata->displayName()->c_str() << std::endl;
  std::cout << metadata->displayFormat() << std::endl;
  std::cout << metadata->description()->c_str() << std::endl;
  std::cout << metadata->descriptionUrl()->c_str() << std::endl;

 

  auto operations = metadata->operations();
  std::cout << "AllowedOperations: read=" << operations->read() << " write:" << operations->write() << " create:" << operations->create() << " delete:" << operations->delete_() << std::endl;

 

  auto references = metadata->references();
  for (flatbuffers::uoffset_t i = 0; i < references->size(); i++)
  {
    std::cout << references->Get(i)->type()->c_str() << std::endl;
    std::cout << references->Get(i)->targetAddress()->c_str() << std::endl;
  }
}
DataLayerClient::DataLayerClient(const std::string& ip, const std::string& user, const std::string& password, int sslPort)
  : m_ip(ip)
  , m_user(user)
  , m_password(password)
  , m_sslPort(sslPort)
  , m_client(nullptr)
{}

 

 

bool DataLayerClient::start()
{
  std::cout << "m_datalayer.start(..)" << std::endl;
  m_datalayerSystem.start(false);

 

  m_client = getClient(m_datalayerSystem, m_ip, m_user, m_password, m_sslPort);

 

  return m_client != nullptr && m_client->isConnected();
}

 

 

comm::datalayer::IClient::ResponseCallback DataLayerClient::responseCallback()
{
  // [&]    All needed symbols are provided per reference
  // (...)  Parameter provided by the calling site
  return [&](comm::datalayer::DlResult result, const comm::datalayer::Variant* data)
    {
      m_resultAsync = result;
      if (data != nullptr)
      {
        // data must not be nullptr otherwise the '=' operator crashes
        m_dataAsync = *data;

 

        if (m_dataAsync.getType() == comm::datalayer::VariantType::ARRAY_OF_STRING)
        {
          printStringList(m_dataAsync);
        }
      }

 

      std::cout << "ResponseCallback: " << std::string(result.toString()) << std::endl;
    };
}

 

bool DataLayerClient::waitForResponseCallback(int counter)
{
  for (;;)
  {
    if (counter > 0)
    {
      counter--;
      if (counter <= 0)
      {
        return false;
      }
    }

 

    //sleep(1);

 

    if (m_resultAsync != -1)
    {
      std::cout << "ResponseCallback finished: " << m_resultAsync.toString() << std::endl;
      return true;
    }
  }
}

 

 

void DataLayerClient::ping()
{
  std::cout << "ping" << std::endl;
  m_result = m_client->pingSync();
  std::cout << "m_client->pingSync() " << m_result.toString() << std::endl;

 

  m_resultAsync = -1;
  m_result = m_client->pingAsync(responseCallback());
  waitForResponseCallback(10);
}

 

//"fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input/data/ctrlX_DRIVE_XCS_SoE_X/AT.Position_feedback_value_1"
void DataLayerClient::readSync(const std::string& node)
{
  std::string address = node;
  m_result = m_client->readSync(address, &m_data);
   // std::cout << ("readSync() " + address) << endl;
    cout << int32_t(m_data) << endl;
}

 

void DataLayerClient::writeSync(const std::string& node)
{
  auto address = "motion/kin/Kinematics/cmd/group-ena";
  m_result = m_client->writeSync(address, &m_data);
  cout << m_result.toString() << endl;

}

 

 

void DataLayerClient::write()
{
  m_data.setValue(true);
  writeSync("bool8");

 

  m_data.setValue(-0.123456789f);
  writeSync("float32");

 

  m_data.setValue(-0.987654321);
  writeSync("float64");

 

  m_data.setValue((int8_t)-127);
  writeSync("int8");

 

  m_data.setValue((int16_t)-32767);
  writeSync("int16");

 

  m_data.setValue((int32_t)0x80000001);
  writeSync("int32");

 

  m_data.setValue((int64_t)0x8000000000000001);
  writeSync("int64");

 

  m_data.setValue("Changed by cpp ctrlX Data Layer Client");
  writeSync("string");
}

 

void DataLayerClient::createSync(const std::string& node)
{
  std::string address = node;
  m_client->removeSync(address); // First remove - may be node exists
  m_result = m_client->createSync(address, &m_data);
  cout << m_result.toString() << endl;
}

 

 

 

void DataLayerClient::stop()
{

  delete m_client;
  m_client = nullptr;
}

 

 

int main() {
  // builds object
    DataLayerClient test;

 

  // starts tcp
    test.start();

 

  //payload definition

 

 

 

    int p;
  // ping ctrl x core
    test.ping();

  //set power to true
  test.m_data.setValue(true);
  test.createSync("motion/axs/X/cmd/power");

 

  // this is the command responsible for jog the x axis
  virtual MotionResult axsPosCmd(const cmd::DataLayerClient::CmdSourceInfo & sourceInfo, const char* x, cmd::axs::AxsCmdType AXS_CMD_POS_ABS, double 400, const cmd::DynamicLimitsT & dynLim, bool true, uint64_t & cmdID) const = 0;

    for ( p = 0; p < 100; p++) {
       //cout << p << endl;

        //read out x encoder 100 times
     test.readSync("fieldbuses/ethercat/master/instances/ethercatmaster/realtime_data/input/data/ctrlX_DRIVE_XCS_SoE_X/AT.Position_feedback_value_1");

 

       


}  //set power to false
  //test.m_data.setValue(false);
  //test.createSync("motion/axs/X/cmd/power");
  //test.stop();
}

 

 

 


With kinde regards,

David

7 replies