当前位置: 首页>>代码示例>>C++>>正文


C++ Network::connect方法代码示例

本文整理汇总了C++中Network::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ Network::connect方法的具体用法?C++ Network::connect怎么用?C++ Network::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Network的用法示例。


在下文中一共展示了Network::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]) {
  Network yarp;
  yarp::os::Node    *rosNode;
  rosNode = new yarp::os::Node("/ros_tests");
  yarp::os::Subscriber<geometry_msgs_Point> xd_inputPort;
  xd_inputPort.setReadOnly();
  bool outputOk = xd_inputPort.topic("/my_xd_in");
  BufferedPort<geometry_msgs_Point> xd_outputPort;
  bool outputOk_3 = xd_outputPort.open("/gaze_point");

  BufferedPort<geometry_msgs_Point>  receiverBuff1Mux1;
  bool receiver1Mux1Ok = receiverBuff1Mux1.open("/my_other_port_in");
  yarp::os::Publisher<geometry_msgs_Point> outputPort;
  outputPort.setWriteOnly();
  bool outputOk_1 = outputPort.topic("/my_x_out");
  
 if(!outputOk_3)
  {
    printf("outputOk_3 failed to open\n");
    return -1;
  }

  if(!outputOk_1)
  {
    printf("outputOk_1 failed to open\n");
    return -1;
  }
  bool connectSuccess = false;
  while(!connectSuccess)
  {
    printf("\nTrying to connect to /iKinGazeCtrl/x:o ... ");
    connectSuccess = yarp.connect("/iKinGazeCtrl/x:o", receiverBuff1Mux1.getName());
    yarp::os::Time::delay(1);
  }

  connectSuccess = false;
  
  while(!connectSuccess)
  {
    printf("\nTrying to connect to /iKinGazeCtrl/xd:i ... ");
    connectSuccess = yarp.connect(xd_outputPort.getName(),"/iKinGazeCtrl/xd:i");
    yarp::os::Time::delay(1);
  }
  while(true){
    geometry_msgs_Point *reading1Mux1;
    reading1Mux1 = xd_inputPort.read(false);
    if (reading1Mux1 != NULL){
	geometry_msgs_Point & out = xd_outputPort.prepare();
	out = *reading1Mux1;
	xd_outputPort.write();
    }
    geometry_msgs_Point *reading1Mux;
    reading1Mux = receiverBuff1Mux1.read();

    geometry_msgs_Point & out_ = outputPort.prepare();
    out_ = *reading1Mux;
    outputPort.write();
  }
  return 0;
}
开发者ID:plinioMoreno,项目名称:yarp-ros-tests,代码行数:60,代码来源:ReadAndWriteTopicsTestUsingNode.cpp

示例2: test2

void test2() {
	using namespace Utility;
	using namespace std;
	using namespace ml;
	typedef double T;

	Timer<float> timer;
	timer.start();
	Network<T>* network = new Network<T>();
	ILayer<T>* l1 = new Layer<T>(100);
	ILayer<T>* l2 = new Layer<T>(200);
	ILayer<T>* l3 = new Layer<T>(500);
	ILayer<T>* l4 = new Layer<T>(10);
	l1->setName("L1");
	l2->setName("L2");
	l3->setName("L3");
	l4->setName("L4");
	network->setInputLayer(l1);
	network->connect(l1, l2);
	network->connect(l2, l3);
	network->connect(l3, l4);
	network->setOutputLayer(l4);
	network->init();

	ml::Mat<T> samples(100, 100, 1);
    ml::Mat<T> nominals(1, 10, 0); 
    network->train(samples, nominals);

	timer.stop();
	cout << timer.getTime() << endl;
}
开发者ID:oulrich1,项目名称:Network,代码行数:31,代码来源:main.cpp

示例3: test_crazy_network_1

void test_crazy_network_1() {
    using namespace std;
    using namespace ml;
    typedef int T;

    Timer<float> timer;
    timer.start();
    

    // Defining network
    Network<T>* network = new Network<T>();
    ILayer<T>* l1 = new Layer<T>(100, "L1");
    ILayer<T>* l2 = new Layer<T>(200, "L2");
    ILayer<T>* l3 = new Layer<T>(500, "L3");

    // Defining subnet, middle node is actually l2. sorta recurrent
    Network<T>* aSubNet = new Network<T>();//.. = something else

    // Defining rest of network
    ILayer<T>* l4 = aSubNet;
    ILayer<T>* l5 = new Layer<T>(2, "L5");
    l4->setName("N4");
    network->setInputLayer(l1);
    network->connect(l1, l2);
    network->connect(l2, l3);
    network->connect(l3, l4);
    network->connect(l3, l2); // note: circularity back to l2
    network->connect(l4, l2); //       here again as well
    network->connect(l4, l5); // note: connecting subnet arbitrarily to another layer..
    network->setOutputLayer(l5);

    // Proper way to finish defining a subnet after completely defining which 
    // network owns the recurrent layers (l2 is owned by parent network..)
    {
        ILayer<T>* s1 = new Layer<T>(100, "S1");
        ILayer<T>* s3 = new Layer<T>(5000, "S3");
        aSubNet->setInputLayer(s1);
        aSubNet->connect(s1, l2);
        aSubNet->connect(l2, s3);
        aSubNet->setOutputLayer(s3);
        aSubNet->setName("SubNet 1");
    }

    // Finish defining parent network and init.. feed.. train..
    network->init();
    ml::Mat<T> input(1, 100, 1); // input vec must be the same size as the input layer's size
    network->feed(input);

    ml::Mat<T> samples(100, 100, 1);
    ml::Mat<T> nominals(1, 2, 0); 
    // network->train(samples, nominals);

    timer.stop();
    cout << timer.getTime() << endl;
}
开发者ID:oulrich1,项目名称:Network,代码行数:55,代码来源:main.cpp

示例4: test_live

bool test_live() {
    printf("\n*** test_live()\n");

    Network yarp;
    yarp.setLocalMode(true);

    Demo client;
    Server server;

    Port client_port,server_port;
    client_port.open("/client");
    server_port.open("/server");
    yarp.connect(client_port.getName(),server_port.getName());

    int x = 0;
    client.yarp().attachAsClient(client_port);
    server.yarp().attachAsServer(server_port);
    x = client.add_one(99);
    printf("Result %d\n", x);
    client.test_void(200);
    client.test_void(201);
    x = client.add_one(100);
    printf("Result %d\n", x);
    client.test_1way(200);
    client.test_1way(201);
    x = client.add_one(101);
    printf("Result %d\n", x);

    return (x==102);
}
开发者ID:paulfitz,项目名称:yarp,代码行数:30,代码来源:main.cpp

示例5: main

int main(int argc, char *argv[]) {
    if (argc<3) {
        fprintf(stderr, "Please supply (1) a port name for the client\n");
        fprintf(stderr, "              (2) a port name for the server\n");
        return 1;
    }

    Network yarp;
    const char *client_name = argv[1];
    const char *server_name = argv[2];

    RpcClient port;
    port.open(client_name);

    int ct = 0;
    while (true) {
	if (port.getOutputCount()==0) {
	  printf("Trying to connect to %s\n", server_name);
	  yarp.connect(client_name,server_name);
	} else {
	  Bottle cmd;
	  cmd.addString("COUNT");
	  cmd.addInt32(ct);
	  ct++;
	  printf("Sending message... %s\n", cmd.toString().c_str());
	  Bottle response;
	  port.write(cmd,response);
	  printf("Got response: %s\n", response.toString().c_str());
	}
	Time::delay(1);
    }
}
开发者ID:robotology,项目名称:yarp,代码行数:32,代码来源:rpc_client.cpp

示例6: void

  void			receiveMe(const std::string &ip, int port, const std::string &dir, void (*cb)(int, void*), void *data) {
    Network		net;
    FILE		*file;
    char		*buff;
    int			received;
    int			i = 0, odoSize;
    ANetwork::t_frame	frame;
    bool		reading = true;

    try {
      net.init(port, ANetwork::TCP_MODE);
      net.connect(ip);
      net.write(CreateRequest::create(1, 2, 3, "File"));
      frame = net.read();
      odoSize = atoi(frame.data);
      frame = net.read();
      file = fopen(std::string(dir + frame.data).c_str(), "wb");
      while (reading) {
	buff = (char*) net.getSocket()->read(D_BUF, &received);
	if (received <= 0)
	  break;
	i += fwrite(buff, 1, received, file);
	cb(i * 100 / odoSize, data);
      }
      fclose(file);
    } catch (const std::exception &e) {
      std::cout << e.what() << std::endl;
    }
  };
开发者ID:antgar,项目名称:rtype_cpp,代码行数:29,代码来源:File.hpp

示例7: main

int main(int argc, char *argv[])
{
    Network yarpy;

    bool run = true;

    BufferedPort<Bottle> inputBottle1;
    inputBottle1.open("/localNeuronPotentialReader1:i");    

    BufferedPort<Bottle> inputBottle2;
    inputBottle2.open("/localNeuronPotentialReader2:i");    

    BufferedPort<Bottle> inputBottle3;
    inputBottle3.open("/localNeuronPotentialReader3:i");    

    BufferedPort<Bottle> inputBottle4;
    inputBottle4.open("/localNeuronPotentialReader4:i");    

    BufferedPort<Bottle> inputBottle5;
    inputBottle5.open("/localNeuronPotentialReader5:i");    


    yarpy.connect( "/outputRF1", "/localNeuronPotentialReader1:i");
    yarpy.connect( "/outputRF2", "/localNeuronPotentialReader2:i");
    yarpy.connect( "/outputRF3", "/localNeuronPotentialReader3:i");
    yarpy.connect( "/outputRF4", "/localNeuronPotentialReader4:i");
    yarpy.connect( "/outputRF5", "/localNeuronPotentialReader5:i");

    vector<double> potential;

    while(run)
    {
        Bottle *tempData1; Bottle *tempData2; Bottle *tempData3; Bottle *tempData4; Bottle *tempData5;
        
        tempData1 = inputBottle1.read(); tempData2 = inputBottle2.read(); tempData3 = inputBottle3.read(); tempData4 = inputBottle4.read(); 
        tempData5 = inputBottle5.read();

        for (int i=0; i<tempData2->size(); i++)
        {
            cout << tempData2->get(i).asDouble() << " ";
        }
        cout << endl;

    }
       

}
开发者ID:himstien,项目名称:iCubFiles,代码行数:47,代码来源:main.cpp

示例8: test3

void test3() {
	using namespace std;
	using namespace ml;
	typedef int T;

	Timer<float> timer;
	timer.start();
	Network<T>* aSubNet = new Network<T>();//.. = something else
	aSubNet->setInputLayer(new Layer<T>(50));
	aSubNet->connect(aSubNet->getInputLayer(), new Layer<T>(1000));
	aSubNet->setOutputLayer(aSubNet->getInputLayer()->siblings[0]);
	aSubNet->setName("SubNet 1");

	Network<T>* network = new Network<T>();
	ILayer<T>* l1 = new Layer<T>(100);
	ILayer<T>* l2 = new Layer<T>(200);
	ILayer<T>* l3 = new Layer<T>(500);
	ILayer<T>* l4 = aSubNet;
	l1->setName("L1");
	l2->setName("L2");
	l3->setName("L3");
	l4->setName("L4");
	network->setInputLayer(l1);
	network->connect(l1, l2);
	network->connect(l2, l3);
	network->connect(l3, l4);
	network->connect(l3, l2); // Sigmoid(l1 * W1 + l3 * W4) -> L2 output
	network->connect(l4, l2);
	network->setOutputLayer(l4);
	network->init();
	ml::Mat<T> input(1, 100, 1);
	network->feed(input);

	/*
	network->init();
	for sample in samples:
	out = network->feed(sample);
	// todo: back prop out into network
	*/

	timer.stop();
	cout << timer.getTime() << endl;

}
开发者ID:oulrich1,项目名称:Network,代码行数:44,代码来源:main.cpp

示例9: Vector

RobotInterface::RobotInterface(PolyDriver* rd, IPositionControl* p, IVelocityControl* v, IEncoders* e, BufferedPort<Vector>* tdp,
							   std::vector<bool>& af, std::vector<bool>& aj) :
				robotDevice(rd),
				pos(p),
				vel(v),
				encs(e),
				tactileDataPort(tdp),
				activeFingers(af),
				activeJoints(aj),
				jointsNumber(0),
				activeFingersNumber(0),
				activeJointsNumber(0),
				iteration(0)

{
	Network yarp;

	// acquire the number of joints
	if(!pos->getAxes(&jointsNumber)) printf("ERROR: impossible to get the number of joints\n");

	// retrieve the number of active fingers
	for(unsigned int i = 0; i < activeFingers.size(); i++)
	{
		if(activeFingers[i] == true) activeFingersNumber++;
	}

	// retrieve the number of active joints
	for(unsigned int i = 0; i < activeJoints.size(); i++)
	{
		if(activeJoints[i] == true) activeJointsNumber++;
	}

	// go to home position (only for simulation, the real robot should be positioned manually)
	Vector home = Vector(jointsNumber, HOME_POSITION_VECTOR);
	positionMoveHand(home);

	// resize vectors so that they are coherent with the number of joints
	homePosition.resize(jointsNumber);
	
	// save the current joint position as an home position for each trial
	encs->getEncoders(homePosition.data());

	// debug
	printf("HOME POSITION:\t");
	for(int p = 0; p < jointsNumber; p++) printf("%f ", homePosition(p));

	// rpc connection for calibration
	rpcSkin.open(RPC_CLIENT_PORT.c_str());
	yarp.connect(RPC_CLIENT_PORT.c_str(), RPC_SERVER_PORT.c_str());
}
开发者ID:xufango,项目名称:contrib_bk,代码行数:50,代码来源:robotInterface.cpp

示例10: test_live_rpc

bool test_live_rpc() {
    printf("\n*** test_live_rpc()\n");

    Network yarp;
    yarp.setLocalMode(true);

    Demo client;
    Server server;

    Port client_port,server_port;
    client_port.open("/client");
    server_port.open("/server");
    yarp.connect(client_port.getName(),server_port.getName());

    int x = 0;
    client.yarp().attachAsClient(client_port);
    server.yarp().attachAsServer(server_port);

    // Check regular RPC works, even with oneways

    Bottle cmd, reply;
    cmd.fromString("[add] [one] 5");
    client_port.write(cmd,reply);
    printf("Cmd %s reply %s\n", cmd.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asInt()!=6) return false;

    cmd.fromString("[test] [void] 5");
    client_port.write(cmd,reply);
    printf("Cmd %s reply %s\n", cmd.toString().c_str(), reply.toString().c_str());

    cmd.fromString("[add] [one] 6");
    client_port.write(cmd,reply);
    printf("Cmd %s reply %s\n", cmd.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asInt()!=7) return false;

    cmd.fromString("[test] [1way] 5");
    client_port.write(cmd,reply);
    printf("Cmd %s reply %s\n", cmd.toString().c_str(), reply.toString().c_str());

    cmd.fromString("[add] [one] 7");
    client_port.write(cmd,reply);
    printf("Cmd %s reply %s\n", cmd.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asInt()!=8) return false;

    return true;
}
开发者ID:paulfitz,项目名称:yarp,代码行数:46,代码来源:main.cpp

示例11: main

int main(int argc, char *argv[]) {
    printf("This test creates two ports and writes from one to the other.\n");
    printf("Make sure no other YARP programs are running.\n");
    printf("(or else remove the yarpNetworkSetLocalMode line)\n");

    Network yarp;
    yarp.setLocalMode(1);

    Port p1, p2;
    bool ok = p1.open("/test1") && p2.open("/test2");
    if (!ok) {
        printf("failed to open ports\n");
        return 1;
    }

    ok = yarp.connect("/test1","/test2",NULL);
    if (!ok) {
        printf("failed to connect ports\n");
        return 1;
    }

    p1.enableBackgroundWrite(true);

    MyPortable i1, i2;
    i1.val = 15;

    printf("Writing (in background)...\n");
    p1.write(i1);

    printf("Reading...\n");

    p2.read(i2);

    printf("After read, received %d\n", i2.val);
    if (i2.val==15) {
        printf("Correct!\n");
    } else {
        printf("That's not right, something failed.\n");
        return 1;
    }

    p1.close();
    p2.close();

    return 0;
}
开发者ID:Tiger66639,项目名称:yarp,代码行数:46,代码来源:yarpcxx_test2.cpp

示例12: main

int main(int argc, char *argv[]) {
  Property config;
  config.fromCommand(argc,argv);

  Network yarp;
  Port client_port;

  std::string servername= config.find("server").asString().c_str();
  client_port.open("/demo/client");
  if (!yarp.connect("/demo/client",servername.c_str()))
  {
     std::cout << "Error! Could not connect to server " << servername << std::endl;
     return -1;
  }

  Demo demo;
  demo.yarp().attachAsClient(client_port);

  PointD point;
  point.x = 0;
  point.y = 0;
  point.z = 0;
  PointD offset;
  offset.x = 1;
  offset.y = 2;
  offset.z = 3;

  std::cout << "== get_answer ==" << std::endl;
  int answer=demo.get_answer();
  std::cout << answer << std::endl;

  std::cout<<"== add_one =="<<std::endl;
  answer = demo.add_one(answer);
  std::cout << answer << std::endl;

  std::cout<<"== double_down =="<<std::endl;
  answer = demo.double_down(answer);
  std::cout << answer << std::endl;

  std::cout<<"== add_point =="<<std::endl;
  point = demo.add_point(point,offset);
  std::cout<<("== done! ==\n");

  return 0;
}
开发者ID:ale-git,项目名称:yarp,代码行数:45,代码来源:DemoClient.cpp

示例13: test_defaults_with_rpc

bool test_defaults_with_rpc() {
    printf("\n*** test_defaults_with_rpc()\n");


    Network yarp;
    yarp.setLocalMode(true);

    Server server;

    Port client_port,server_port;
    client_port.open("/client");
    server_port.open("/server");
    yarp.connect(client_port.getName(),server_port.getName());
    server.yarp().attachAsServer(server_port);

    Bottle msg, reply;
    msg.fromString("test_tail_defaults");
    client_port.write(msg,reply);
    printf("%s -> %s\n", msg.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asInt() != 42) return false;

    msg.fromString("test_tail_defaults 55");
    client_port.write(msg,reply);
    printf("%s -> %s\n", msg.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asInt() != 999) return false;

    msg.fromString("test longer tail defaults");
    client_port.write(msg,reply);
    printf("%s -> %s\n", msg.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asVocab() != VOCAB4('f','a','i','l')) return false;

    msg.fromString("test longer tail defaults 888");
    client_port.write(msg,reply);
    printf("%s -> %s\n", msg.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asInt() != 999) return false;

    msg.fromString("test longer tail defaults 888 ENUM2 47");
    client_port.write(msg,reply);
    printf("%s -> %s\n", msg.toString().c_str(), reply.toString().c_str());
    if (reply.get(0).asInt() != 47) return false;

    return true;
}
开发者ID:paulfitz,项目名称:yarp,代码行数:43,代码来源:main.cpp

示例14: main

int main(int argc, char *argv[]) {
  Property config;
  config.fromCommand(argc,argv);

  Network yarp;
  Port client_port;

  std::string servername= config.find("server").asString().c_str();
  client_port.open("/demo/client");
  if (!yarp.connect("/demo/client",servername.c_str()))
  {
     std::cout << "Error! Could not connect to server " << servername << std::endl;
     return -1;
  }

  Demo demo;
  demo.yarp().attachAsClient(client_port);
  
  // Let's chat with the server!
  
  std::cout << "Hey are you up and running?" << std::endl;
  while(!demo.is_running())
  {
      std::cout << "No? Well... start!" << std::endl;
      demo.start();
  }
  
  std::cout << "Wonderful! I have a question for you... so, what's the answer??" << std::endl;
  int32_t answer=demo.get_answer();
  std::cout << "What?? " << answer << "?? Are you kidding??";
  answer = demo.add_one(answer);
  std::cout << " It's definitely " << answer << "!!" << std::endl;
  demo.set_answer(answer);
  std::cout << "Got it? So, repeat after me: the answer is ... " << demo.get_answer() << "! Great!" << std::endl;

  std::cout << "Ok you can relax now, I'll leave you alone" << std::endl;
  demo.stop();
  
  std::cout<<"Bye" << std::endl;

  return 0;
}
开发者ID:AbuMussabRaja,项目名称:yarp,代码行数:42,代码来源:DemoClient.cpp

示例15: main

int main(int argc, char *argv[]) {
  if (argc!=2) {
    fprintf(stderr,"please supply name of rpc port to talk to\n");
    return 1;
  }
  Network yarp;
  Port port;
  if (!port.open("/motor/client")) {
    fprintf(stderr,"Failed to open a port, maybe run: yarpserver\n");
    return 1;
  }

  //yarp.connect("/motor/client",argv[1],"text_ack");
  yarp.connect("/motor/client",argv[1]);
  Motor motor;
  motor.query(port);
  int nj = motor.get_axes();

  vector<double> poss;
  for (int i=0; i<nj; i++) {
    poss.push_back(0.5*i);
  }
  motor.set_poss(poss);
  for (int i=0; i<10; i++) {
    motor.link().stream();
    motor.set_pos(0,i);
    motor.link().query();
    double v = motor.get_enc(0);
    printf("Motor %d at %g of %d axes\n", 0, v, motor.get_axes());
    vector<double> all = motor.get_encs();
    printf("  all encs:");
    for (int i=0; i<(int)all.size(); i++) {
      printf(" %d:%g", i, all[i]);
    }
    printf("\n");
  }

  port.close();
  return 0;
}
开发者ID:paulfitz,项目名称:yarp_thrift,代码行数:40,代码来源:motor_client.cpp


注:本文中的Network::connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。