Separate control for 2 robots

Typically: "How do I... ", "How can I... " questions
Post Reply
Rose111
Posts: 10
Joined: 13 Sep 2018, 08:05

Separate control for 2 robots

Post by Rose111 » 05 Oct 2018, 12:33

Greetings,
I have two epuck robots having different control strategies. each one of them has a class to handle it, get his position and calculate the velocity to control it.
I have problems and I need help.
In the main I write this code to communicate each class via a different channel.

Code: Select all

Epuck1 *e1Ptr = new Epuck1();
Epuck0 *e0Ptr = new Epuck0();
int clientID = simxStart((simxChar*)"127.0.0.1", 19000, false, true, 2000, 5);
int clientID1 = simxStart((simxChar*)"127.0.0.1", 19001, false, true, 2000, 5);
if (clientID != -1 && clientID1 !=-1)
{
	printf("Connected to remote API server\n");
	std::thread th1(&Epuck1::send_control_1,e1Ptr, clientID);
	std::thread th0(&Epuck0::send_control_0,e0Ptr, clientID1);
	th1.join();
	th0.join();
	delete e1Ptr;
	delete e0Ptr;
	simxFinish(clientID);
	simxFinish(clientID1);
}
And a small part of the Function "Send_control_1 or 0" as follows:

Code: Select all

void Epuck1::send_control_1(int client)
{
	int ret1 = simxGetObjectHandle(client, "ePuck_leftJoint#1", &left_motor_1, simx_opmode_blocking);
	int ret2 = simxGetObjectHandle(client, "ePuck_rightJoint#1", &right_motor_1, simx_opmode_blocking);
	int ret3 = simxGetObjectHandle(client, "ePuck_bodyElements#1", &epuck_1, simx_opmode_blocking);
	int ret4 = simxGetObjectHandle(client, "ReferenceFrame", &ref_frame, simx_opmode_blocking);
}
I noticed that I cannot handle the true values of object handles, and the return code is '3', and for this reason I cannot continue.

The second thing is:
when I go in the function Is that writting of the function good to handle the object of the 2 robots at the same time or I have to call the function simxGetObjectHandle in thread and how can I call it?

Any suggestions can help me please?

Thanks.

Rose111
Posts: 10
Joined: 13 Sep 2018, 08:05

Re: Separate control for 2 robots

Post by Rose111 » 07 Oct 2018, 13:05

Hello..
Just when I connect to the port number 19997 I have a good output.. but with another port I have not..

Please I need help to connect with another port.
This is a simple code to connect with another port.

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <tuple>
using namespace std;
extern "C" {
#include "extApi.h"
}

std::tuple<int, int, int, int> handles(int client)
{
	int left_motor, right_motor, epuck, ref_frame;
	int ret1 = simxGetObjectHandle(client, "ePuck_leftJoint#0", &left_motor, simx_opmode_blocking);
	int ret2 = simxGetObjectHandle(client, "ePuck_rightJoint#0", &right_motor, simx_opmode_blocking);
	int ret3 = simxGetObjectHandle(client, "ePuck_bodyElements#0", &epuck, simx_opmode_blocking);
	int ret4 = simxGetObjectHandle(client, "ReferenceFrame", &ref_frame, simx_opmode_blocking);
	return std::make_tuple(left_motor, right_motor, epuck, ref_frame);
}
int main(int argc, char* argv[])
{
	int left_motor_0, left_motor_1, right_motor_0, right_motor_1,epuck_0,epuck_1,ref_frame;
	int clientID = simxStart((simxChar*)"127.0.0.1", 19997, false, true, 2000, 5);
	int clientID1 = simxStart((simxChar*)"127.0.0.1", 19998, false, true, 2000, 5);

	if (clientID != -1 && clientID1 != -1)
	{
		printf("Connected to remote API server\n");
		std::tie(left_motor_0, right_motor_0, epuck_0, ref_frame) = handles(clientID1);
		simxFinish(clientID);
		simxFinish(clientID1);
	}
	system("pause");
	return(0);
}

Rose111
Posts: 10
Joined: 13 Sep 2018, 08:05

Re: Separate control for 2 robots

Post by Rose111 » 07 Oct 2018, 19:43

I have solved the problem. Thank you.

Post Reply