int main(int argc,char* argv[]) { int clientID=simxStart((simxChar*)"127.0.0.1",19999,true,true,2000,5); if (clientID!=-1) { printf("Connected to remote API server\n"); // 1. First send a command to display a specific message in a dialog box: int retStringCnt; char* retStrings; int result=simxCallScriptFunction(clientID,"remoteApiCommandServer",sim_scripttype_childscript,"displayText_function",0,NULL,0,NULL,1,"Hello world!",0,NULL,NULL,NULL,NULL,NULL,&retStringCnt,&retStrings,NULL,NULL,simx_opmode_blocking); if (result==simx_return_ok) printf("Returned message: %s\n",retStrings); // display the reply from V-REP (in this case, just a string) else printf("Remote function call failed\n"); // 2. Now create a dummy object at coordinate 0.1,0.2,0.3 with name 'MyDummyName': float coords[3]={0.1f,0.2f,0.3f}; int retIntCnt; int* retInts; result=simxCallScriptFunction(clientID,"remoteApiCommandServer",sim_scripttype_childscript,"createDummy_function",0,NULL,3,coords,1,"MyDummyName",0,NULL,&retIntCnt,&retInts,NULL,NULL,NULL,NULL,NULL,NULL,simx_opmode_blocking); if (result==simx_return_ok) printf("Dummy handle: %i\n",retInts[0]); // display the reply from V-REP (in this case, the handle of the created dummy) else printf("Remote function call failed\n"); extApi_sleepMs(2000); // Now close the connection to V-REP: simxFinish(clientID); } return(0); }
int main(int argc,char* argv[]) { int portNb=0; int leftMotorHandle; int rightMotorHandle; int sensorHandle; if (argc>=5) { portNb=atoi(argv[1]); leftMotorHandle=atoi(argv[2]); rightMotorHandle=atoi(argv[3]); sensorHandle=atoi(argv[4]); } else { printf("Indicate following arguments: 'portNumber leftMotorHandle rightMotorHandle sensorHandle'!\n"); extApi_sleepMs(5000); return 0; } int clientID=simxStart((simxChar*)"127.0.0.1",portNb,true,true,2000,5); if (clientID!=-1) { int driveBackStartTime=-99000; float motorSpeeds[2]; while (simxGetConnectionId(clientID)!=-1) { simxUChar sensorTrigger=0; if (simxReadProximitySensor(clientID,sensorHandle,&sensorTrigger,NULL,NULL,NULL,simx_opmode_streaming)==simx_return_ok) { // We succeeded at reading the proximity sensor int simulationTime=simxGetLastCmdTime(clientID); if (simulationTime-driveBackStartTime<3000) { // driving backwards while slightly turning: motorSpeeds[0]=-3.1415f*0.5f; motorSpeeds[1]=-3.1415f*0.25f; } else { // going forward: motorSpeeds[0]=3.1415f; motorSpeeds[1]=3.1415f; if (sensorTrigger) driveBackStartTime=simulationTime; // We detected something, and start the backward mode } simxSetJointTargetVelocity(clientID,leftMotorHandle,motorSpeeds[0],simx_opmode_oneshot); simxSetJointTargetVelocity(clientID,rightMotorHandle,motorSpeeds[1],simx_opmode_oneshot); } extApi_sleepMs(5); } simxFinish(clientID); } return(0); }
rys::rys(int portNb, const std::string& nazwa) { clientID=simxStart((simxChar*)"127.0.0.1",portNb,true,true,2000,5); linVelSignal=nazwa+"_linVel"; angVelSignal=nazwa+"_angVel"; positionSignal=nazwa+"_pozycja"; stopSignal=nazwa+"_stop"; sensorBackSignal=nazwa+"_sensorBack"; sensorFrontSignal=nazwa+"_sensorFront"; sensorUpSignal=nazwa+"_sensorUp"; }
RobotVREP::RobotVREP(bool video_recording, int port, const char * ip) { clientID = simxStart((simxChar*)ip, port, true, true, 2000, 5); if (clientID != -1) clog << "ROBOTLIB:\tThe connection has been successfully established with VREP" << endl; else { clog << "ROBOTLIB:" << endl; clog << "\tERROR: The connection to VREP was not possible" << endl; return; } vrep_error.open("vrep_error.txt"); simulation_in_progress = false; video_recording_flag = false; video_updated_name = false; video_id = 0; setVideoRecordingMode(video_recording); }
int main(int argc,char* argv[]) { int clientID=simxStart((simxChar*)"127.0.0.1",19999,true,true,2000,5); if (clientID!=-1) { printf("Connected to remote API server\n"); // Now try to retrieve data in a blocking fashion (i.e. a service call): int objectCount; int* objectHandles; int ret=simxGetObjects(clientID,sim_handle_all,&objectCount,&objectHandles,simx_opmode_blocking); if (ret==simx_return_ok) printf("Number of objects in the scene: %d\n",objectCount); else printf("Remote API function call returned with error code: %d\n",ret); extApi_sleepMs(2000); // Now retrieve streaming data (i.e. in a non-blocking fashion): int startTime=extApi_getTimeInMs(); int mouseX; simxGetIntegerParameter(clientID,sim_intparam_mouse_x,&mouseX,simx_opmode_streaming); // Initialize streaming while (extApi_getTimeDiffInMs(startTime) < 5000) { ret=simxGetIntegerParameter(clientID,sim_intparam_mouse_x,&mouseX,simx_opmode_buffer); // Try to retrieve the streamed data if (ret==simx_return_ok) // After initialization of streaming, it will take a few ms before the first value arrives, so check the return code printf("Mouse position x: %d\n",mouseX); // Mouse position x is actualized when the cursor is over V-REP's window } // Now send some data to V-REP in a non-blocking fashion: simxAddStatusbarMessage(clientID,"Hello V-REP!",simx_opmode_oneshot); // Before closing the connection to V-REP, make sure that the last command sent out had time to arrive. You can guarantee this with (for example): int pingTime; simxGetPingTime(clientID,&pingTime); // Now close the connection to V-REP: simxFinish(clientID); } return(0); }
int main(int argc, char** argv) { int portNb = 0; //Se define el puerto de conexión simxInt bodyElements, rightMotor, leftMotor,console; simxInt sensor_infra[8] = { -1,-1,-1,-1,-1,-1,-1,-1 }; simxInt objectivo; MyLogger log; if (log.Init()) { log.LogInfo("\n"); log.LogInfo(" "); log.LogInfo(" "); log.LogInfo(" "); log.LogInfo("**********************************************************************************"); log.LogInfo("************************** Inicializando Programa **************************"); log.LogInfo("Traza iniciada"); } std::stringstream ss; ss << "Leyendo Parametros (" << argc << ")..."; log.LogInfo(ss.str().c_str()); if (argc >= 15) { portNb = atoi(argv[1]); leftMotor = atoi(argv[2]); rightMotor = atoi(argv[3]); objectivo = atoi(argv[4]); bodyElements = atoi(argv[5]); console = atoi(argv[14]); ss.str(std::string()); ss << "portNb = " << portNb << " leftMotor = "<< leftMotor << " rightMotor = " << rightMotor << " objectivo = " << objectivo << " bodyElements = " << bodyElements<< " console = "<< console; log.LogDebug(ss.str().c_str()); ss.str(std::string()); for (int i = 0; i < 8; i++) { sensor_infra[i] = atoi(argv[i + 6]); ss << " sensor_infra[" << i << "] = " << sensor_infra[i]; } log.LogDebug(ss.str().c_str()); } else { log.LogInfo("Por favor indicar los parámetros correctos"); return 0; } //Conectar con V-REP int clientID = simxStart((simxChar*)"127.0.0.1", portNb, true, true, 2000, 5); //Si la conexión es exitosa iniciar la simulación if (clientID > -1) { Robot robot(bodyElements, leftMotor, rightMotor, clientID); for (int i = 0; i < 8; i++) robot.SetSensorInfra(i, sensor_infra[i]); VFH vfh(&robot, clientID,objectivo); vfh.Run(); simxFinish(clientID); } }
int main(int argc, char* argv[]) { int portNb=0; int motorHandles[7]; int motorHandles2[7]; if (argc>=9+7) { // We get the port and the motor handles (for the visual feedback, not for IK!) via command-line arguments portNb=atoi(argv[1]); motorHandles[0]=atoi(argv[2]); motorHandles[1]=atoi(argv[3]); motorHandles[2]=atoi(argv[4]); motorHandles[3]=atoi(argv[5]); motorHandles[4]=atoi(argv[6]); motorHandles[5]=atoi(argv[7]); motorHandles[6]=atoi(argv[8]); motorHandles2[0]=atoi(argv[9]); motorHandles2[1]=atoi(argv[10]); motorHandles2[2]=atoi(argv[11]); motorHandles2[3]=atoi(argv[12]); motorHandles2[4]=atoi(argv[13]); motorHandles2[5]=atoi(argv[14]); motorHandles2[6]=atoi(argv[15]); } else { printf("Indicate following arguments: 'portNumber motor1Handle motor2Handle .. motor7Handle'!\n"); extApi_sleepMs(5000); return 0; } // Read the kinematic file: FILE *file; file=fopen("lbr_iiwa_7_r800.ik","rb"); unsigned char* data=NULL; int dataLength=0; if (file) { fseek(file,0,SEEK_END); unsigned long fl=ftell(file); dataLength=(int)fl; fseek(file,0,SEEK_SET); data=new unsigned char[dataLength]; fread((char*)data,dataLength,1,file); fclose(file); } else { printf("The kinematic content file 'lbr.ik' could not be read!\n"); extApi_sleepMs(5000); return 0; } // Initialize the embedded robot model1: int handle1=simEmbLaunch(); simEmbStart(data,dataLength); // Initialize the embedded robot model2: int handle2=simEmbLaunch(); simEmbStart(data,dataLength); delete[] data; simEmbSwitch(handle1); // use robot model1 // Connect to V-REP at the above specified port, via the remote API. V-REP is just used for visual feed-back, not IK calculation! int clientID=simxStart("127.0.0.1",portNb,true,true,2000,5); if (clientID!=-1) { float simulationStep; simxGetFloatingParameter(clientID,sim_floatparam_simulation_time_step,&simulationStep,simx_opmode_streaming); simxSynchronous(clientID,1); // We enable the synchronous mode, so that we can trigger each simulation step from here int embeddedModelMotorHandles[7]; embeddedModelMotorHandles[0]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint1"); embeddedModelMotorHandles[1]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint2"); embeddedModelMotorHandles[2]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint3"); embeddedModelMotorHandles[3]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint4"); embeddedModelMotorHandles[4]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint5"); embeddedModelMotorHandles[5]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint6"); embeddedModelMotorHandles[6]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint7"); int embeddedModelTargetHandle=simEmbGetObjectHandle("LBR_iiwa_7_R800_target"); int embeddedModelBaseHandle=simEmbGetObjectHandle("LBR_iiwa_7_R800"); extIkReal v=0.0; // Get the initial target dummy matrix, of the embedded model: extIkReal matrix[12]; simEmbGetObjectMatrix(embeddedModelTargetHandle,embeddedModelBaseHandle,matrix); int embeddedModelMotorHandles2[7]; embeddedModelMotorHandles2[0]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint1"); embeddedModelMotorHandles2[1]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint2"); embeddedModelMotorHandles2[2]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint3"); embeddedModelMotorHandles2[3]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint4"); embeddedModelMotorHandles2[4]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint5"); embeddedModelMotorHandles2[5]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint6"); embeddedModelMotorHandles2[6]=simEmbGetObjectHandle("LBR_iiwa_7_R800_joint7"); int embeddedModelTargetHandle2=simEmbGetObjectHandle("LBR_iiwa_7_R800_target"); int embeddedModelBaseHandle2=simEmbGetObjectHandle("LBR_iiwa_7_R800"); extIkReal v2=0.0; // Get the initial target dummy matrix, of the embedded model: extIkReal matrix2[12]; simEmbGetObjectMatrix(embeddedModelTargetHandle2,embeddedModelBaseHandle2,matrix2); while (simxGetConnectionId(clientID)!=-1) { // Following 3 commands will slow down the simulation, but garantee that if the simulation time step was changed, // that there won't be any jumps. Following 3 commands are not needed if you don't modify the simulation time step // (i.e. dt) during simulation. simxUChar vrepWaitingForTrigger=0; while ( (vrepWaitingForTrigger==0)&&(simxGetConnectionId(clientID)!=-1) ) simxGetBooleanParameter(clientID,sim_boolparam_waiting_for_trigger,&vrepWaitingForTrigger,simx_opmode_oneshot_wait); simxGetFloatingParameter(clientID,sim_floatparam_simulation_time_step,&simulationStep,simx_opmode_buffer); v+=extIkReal(0.2)*extIkReal(simulationStep); v2+=extIkReal(0.28)*extIkReal(simulationStep); simEmbSwitch(handle1); // use robot model1 // Set the desired tip matrix by setting the target dummy matrix: matrix[3]=extIkReal(-0.3-cos(v)*0.1); matrix[7]=extIkReal(sin(v)*0.1); matrix[11]=extIkReal(0.629+sin(v*9)*0.01); simEmbSetObjectMatrix(embeddedModelTargetHandle,embeddedModelBaseHandle,matrix); // calculate IK: simEmbHandleIkGroup(sim_handle_all); // Read the corresponding motor angles and send them to V-REP: simxPauseCommunication(clientID,1); // Temporarily pause the remote API communication, in order to send all following commands at once extIkReal pos; simEmbGetJointPosition(embeddedModelMotorHandles[0],&pos); simxSetJointPosition(clientID,motorHandles[0],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles[1],&pos); simxSetJointPosition(clientID,motorHandles[1],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles[2],&pos); simxSetJointPosition(clientID,motorHandles[2],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles[3],&pos); simxSetJointPosition(clientID,motorHandles[3],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles[4],&pos); simxSetJointPosition(clientID,motorHandles[4],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles[5],&pos); simxSetJointPosition(clientID,motorHandles[5],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles[6],&pos); simxSetJointPosition(clientID,motorHandles[6],(float)pos,simx_opmode_oneshot); simEmbSwitch(handle2); // use robot model2 // Set the desired tip matrix by setting the target dummy matrix: matrix2[3]=extIkReal(-0.3-cos(v2)*0.1); matrix2[7]=extIkReal(sin(v2)*0.1); simEmbSetObjectMatrix(embeddedModelTargetHandle2,embeddedModelBaseHandle2,matrix2); // calculate IK: simEmbHandleIkGroup(sim_handle_all); // Read the corresponding motor angles and send them to V-REP: simEmbGetJointPosition(embeddedModelMotorHandles2[0],&pos); simxSetJointPosition(clientID,motorHandles2[0],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles2[1],&pos); simxSetJointPosition(clientID,motorHandles2[1],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles2[2],&pos); simxSetJointPosition(clientID,motorHandles2[2],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles2[3],&pos); simxSetJointPosition(clientID,motorHandles2[3],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles2[4],&pos); simxSetJointPosition(clientID,motorHandles2[4],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles2[5],&pos); simxSetJointPosition(clientID,motorHandles2[5],(float)pos,simx_opmode_oneshot); simEmbGetJointPosition(embeddedModelMotorHandles2[6],&pos); simxSetJointPosition(clientID,motorHandles2[6],(float)pos,simx_opmode_oneshot); simxPauseCommunication(clientID,0); // Unpause the remote API communication // Now step the simulation on V-REP side: int r=simx_return_remote_error_flag; // means for next remote API function call: step not triggered while (r==simx_return_remote_error_flag) r=simxSynchronousTrigger(clientID); // Trigger next simulation step if (r!=simx_return_ok) break; printf("."); } simEmbShutDown(); // End the external IK simEmbShutDown(); // End the external IK simxFinish(clientID); // End the remote API } return(0); }
int main(int argc,char* argv[]) { int portNb=0; int leftMotorHandle; int rightMotorHandle; int cuboidHandle; int goalHandle; if (argc>=6) { portNb=atoi(argv[1]); leftMotorHandle=atoi(argv[2]); rightMotorHandle=atoi(argv[3]); cuboidHandle=atoi(argv[4]); goalHandle=atoi(argv[5]); } else { extApi_sleepMs(5000); return 0; } int clientID=simxStart((simxChar*)"127.0.0.1",portNb,true,true,2000,5); if (clientID!=-1) { int driveBackStartTime=-99000; float motorSpeeds[2]; float leftMotorAngle; float ObjectPosition[3]; float GoalPosition[3]; float ObjectOrientation[3]; float minDistance=0.3; if (simxGetConnectionId(clientID)!=-1) { simxUChar sensorTrigger=0; simxGetObjectHandle(clientID, argv[2], &leftMotorHandle, simx_opmode_blocking); simxGetObjectHandle(clientID, argv[3], &rightMotorHandle, simx_opmode_blocking); simxGetObjectHandle(clientID, argv[4], &cuboidHandle, simx_opmode_blocking); simxGetObjectHandle(clientID, argv[5], &goalHandle, simx_opmode_blocking); simxGetObjectPosition(clientID,goalHandle,-1,GoalPosition,simx_opmode_oneshot_wait); MovetoPoint(GoalPosition, minDistance, clientID, leftMotorHandle, rightMotorHandle, cuboidHandle); simxSetJointTargetVelocity(clientID,leftMotorHandle,0,simx_opmode_blocking); simxSetJointTargetVelocity(clientID,rightMotorHandle,0,simx_opmode_blocking); extApi_sleepMs(5); } printf("Fin!\n"); simxFinish(clientID); } return(0); }