void MainWindow::RunAdamsSim()
{
    ButtonAdamsSim->setStyleSheet("QPushButton {border-radius: 2px;padding: 0.2em 0.2em 0.3em 0.2em;border: 1px solid rgb(100, 100,100);background: QLinearGradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #34f32d, stop: 1 #000000);color: white;}");

    std::ostringstream ossStringLHip, ossStringRHip, ossStringLKnee, ossStringRKnee, ossStringTimeLeft, ossStringTimeRight,
            ossPeriod, ossCycles, ossDelay;

    vector <double> vTimeLeftLeg, vTimeRightLeg;
    vector <double> vHipR, vHipL, vKneeR, vKneeL;

    ossPeriod <<"period="<<lineEditPeriod->text().toStdString();
    ossCycles <<"cycles="<<lineEditCycles->text().toStdString();
    ossDelay <<"delay="<<lineEditDelay->text().toStdString();

    // Getting Time Values
    //GetTimeValues(vTimeValues);


    pHipRight->GetSamples(vTimeRightLeg);
    pHipLeft->GetSamples(vTimeLeftLeg);

    GetRobotObjectSampledValues(pHipLeft, vHipL);
    GetRobotObjectSampledValues(pHipRight, vHipR);
    GetRobotObjectSampledValues(pKneeLeft, vKneeL);
    GetRobotObjectSampledValues(pKneeRight, vKneeR);
    //pHipLeft->ExportMarkers(vTimeValues, vHipL);
    pHipLeft->GetValues(vTimeLeftLeg, vHipL);
    pHipRight->GetValues(vTimeRightLeg, vHipR);
    pKneeLeft->GetValues(vTimeLeftLeg, vKneeL);
    pKneeRight->GetValues(vTimeRightLeg, vKneeR);

    // Making string for left hip

    ossStringLHip << "vHipL=[";
    std::copy(vHipL.begin(), vHipL.end()-1, std::ostream_iterator <double>(ossStringLHip, " "));
    ossStringLHip << vHipL.back();
    ossStringLHip << "];";
    std::cout<<ossStringLHip.str()<<std::endl;

    // Making string for left hip

    ossStringRHip << "vHipR=[";
    std::copy(vHipR.begin(), vHipR.end()-1, std::ostream_iterator <double>(ossStringRHip, " "));
    ossStringRHip << vHipR.back();
    ossStringRHip << "];";

    // Making string for left knee

    ossStringLKnee << "vKneeL=[";
    std::copy(vKneeL.begin(), vKneeL.end()-1, std::ostream_iterator <double>(ossStringLKnee, " "));
    ossStringLKnee << vKneeL.back();
    ossStringLKnee << "];";

    // Making string for right knee

    ossStringRKnee << "vKneeR=[";
    std::copy(vKneeR.begin(), vKneeR.end()-1, std::ostream_iterator <double>(ossStringRKnee, " "));
    ossStringRKnee << vKneeR.back();
    ossStringRKnee << "];";

    // Making string for time values for Left Leg

    ossStringTimeLeft << "vTimeL=[";
    std::copy(vTimeLeftLeg.begin(), vTimeLeftLeg.end()-1, std::ostream_iterator <double>(ossStringTimeLeft, " "));
    ossStringTimeLeft << vTimeLeftLeg.back();
    ossStringTimeLeft << "];";
    std::cout<<ossStringTimeLeft.str()<<std::endl;

    // Making string for time values for Right Leg

    ossStringTimeRight << "vTimeR=[";
    std::copy(vTimeRightLeg.begin(), vTimeRightLeg.end()-1, std::ostream_iterator <double>(ossStringTimeRight, " "));
    ossStringTimeRight << vTimeRightLeg.back();
    ossStringTimeRight << "];";
    std::cout<<ossStringTimeRight.str()<<std::endl;

    Engine* m_matlabEngine;
    // Opening Matlab Engine
    m_matlabEngine=engOpen("\0");
    // Clearing
    engEvalString(m_matlabEngine, "clear;");
    engEvalString(m_matlabEngine, ossStringLHip.str().c_str());
    engEvalString(m_matlabEngine, ossStringTimeLeft.str().c_str());
    engEvalString(m_matlabEngine, ossStringTimeRight.str().c_str());
    engEvalString(m_matlabEngine, ossStringRHip.str().c_str());
    engEvalString(m_matlabEngine, ossStringRKnee.str().c_str());
    engEvalString(m_matlabEngine, ossStringLKnee.str().c_str());
    engEvalString(m_matlabEngine, ossPeriod.str().c_str());
    engEvalString(m_matlabEngine, ossCycles.str().c_str());
    engEvalString(m_matlabEngine, ossDelay.str().c_str());
    QString runEval(QString("run('%1');").arg("C:/Users/Zahid/GUI/RobotSim2/test_final_m2.m"));
    engEvalString(m_matlabEngine, "cd('C:/Users/Zahid/GUI/RobotSim2');");
    //engEvalString(m_matlabEngine, "Controls_Plant_2705_1");
    //engEvalString(m_matlabEngine, "open('test_final_model');");
    //engEvalString(m_matlabEngine, "sim('test_final_model');");
    engEvalString(m_matlabEngine, runEval.toUtf8().constData());
    engClose(m_matlabEngine);
    ButtonAdamsSim->setStyleSheet("QPushButton {border-radius: 2px;padding: 0.2em 0.2em 0.3em 0.2em;border: 1px solid rgb(100, 100,100);background: QLinearGradient( x1: 0, y1: 0.02, x2: 0, y2: 1.2, stop: 0 #220, stop: 1 #ffffff);color: white;}");
}
Example #2
0
int
main (int ac, char *av[])
{
	FILE *fp;

	/* save our name for usage() */
	me = av[0];

	/* crack args */
	while (--ac && **++av == '-') {
	    char *s = *av;
	    while (*++s) {
		switch (*s) {
		case 'b':	/* beep when true */
		    bflag++;
		    break;
		case 'd':
		    if (ac < 2) {
			fprintf (stderr, "-d requires open fileno\n");
			usage();
		    }
		    directfd = atoi(*++av);
		    ac--;
		    break;
		case 'e':	/* print each updated expression value */
		    eflag++;
		    break;
		case 'f':	/* print final expression value */
		    fflag++;
		    break;
		case 'h':
		    if (directfd >= 0) {
			fprintf (stderr, "Can not combine -d and -h\n");
			usage();
		    }
		    if (ac < 2) {
			fprintf (stderr, "-h requires host name\n");
			usage();
		    }
		    host = *++av;
		    ac--;
		    break;
		case 'i':	/* read expression from stdin */
		    iflag++;
		    break;
		case 'o':	/* print operands as they change */
		    oflag++;
		    break;
		case 'p':
		    if (directfd >= 0) {
			fprintf (stderr, "Can not combine -d and -p\n");
			usage();
		    }
		    if (ac < 2) {
			fprintf (stderr, "-p requires tcp port number\n");
			usage();
		    }
		    port = atoi(*++av);
		    ac--;
		    break;
		case 't':
		    if (ac < 2) {
			fprintf (stderr, "-t requires timeout\n");
			usage();
		    }
		    timeout = atoi(*++av);
		    ac--;
		    break;
		case 'v':	/* verbose */
		    verbose++;
		    break;
		case 'w':	/* wait for expression to be true */
		    wflag++;
		    break;
		default:
		    fprintf (stderr, "Unknown flag: %c\n", *s);
		    usage();
		}
	    }
	}

	/* now there are ac args starting with av[0] */

	/* compile expression from av[0] or stdin */
	if (ac == 0)
	    compile (NULL);
	else if (ac == 1)
	    compile (av[0]);
	else
	    usage();

        /* open connection */
	if (directfd >= 0) {
	    fp = fdopen (directfd, "r+");
	    setbuf (fp, NULL);		/* don't absorb next guy's stuff */
	    if (!fp) {
		fprintf (stderr, "Direct fd %d: %s\n",directfd,strerror(errno));
		exit(1);
	    }
	    if (verbose)
		fprintf (stderr, "Using direct fd %d\n", directfd);
	} else {
	    fp = openINDIServer();
	    if (verbose)
		fprintf (stderr, "Connected to %s on port %d\n", host, port);
	}

	/* build a parser context for cracking XML responses */
	lillp = newLilXML();

	/* set up to catch an io timeout function */
	signal (SIGALRM, onAlarm);

	/* send getProperties */
	getProps(fp);

	/* initialize all properties */
	initProps(fp);

	/* evaluate expression, return depending on flags */
	return (runEval(fp));
}