本文整理汇总了C++中ArTime::setToNow方法的典型用法代码示例。如果您正苦于以下问题:C++ ArTime::setToNow方法的具体用法?C++ ArTime::setToNow怎么用?C++ ArTime::setToNow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArTime
的用法示例。
在下文中一共展示了ArTime::setToNow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
int ret;
char bufWrite[1024];
char bufRead[1024];
int i, n;
for (i = 0; i < 1024; i++)
bufWrite[i] = 0x66;
srand(time(NULL));
int bytes1 = 0;
//int bytes2 = 0;
//int numToWrite = 1;
ArTime lastPrint;
if (argc < 2)
{
printf("Usage: %s <port>", argv[0]);
exit(0);
}
ArSerialConnection ser1;
ser1.setPort(argv[1]);
ser1.setBaud(38400);
if (!ser1.openSimple())
{
printf("Exiting since open failed\n");
exit(0);
}
printf("Port opened");
lastPrint.setToNow();
while (1)
{
if (ser1.write(bufWrite, rand() % 1024) < 0)
printf("Failed write\n");
n = rand() % 1024;
if ((ret = ser1.read(bufRead, n)) < 0)
printf("Failed read\n");
else if (ret > 0)
{
for (i = 0; i < ret; i++)
if (bufRead[i] != 0x66)
{
printf("Failed\n");
break;
}
bytes1 += ret;
}
if (lastPrint.mSecSince() > 1000)
{
printf("%d\n", bytes1);
lastPrint.setToNow();
}
}
}
示例2: userTask
void userTask(ArRobot *robot)
{
int timeTaken = (requestTime.mSecSince() -
robot->getIOPacketTime().mSecSince());
if (timeTaken > 500)
{
ArLog::log(ArLog::Terse, "\nits been: %ld giving up and trying again (missed %d got %d)", timeTaken, numPacketsMissed, numPacketsGotten);
numPacketsMissed++;
robot->comInt(ArCommands::IOREQUEST, 1);
requestTime.setToNow();
}
if (robot->getIOPacketTime().mSecSince() > requestTime.mSecSince())
return;
else
{
if (timeTaken > 30)
{
ArLog::log(ArLog::Terse, "\nlast packet time: %ld", timeTaken);
}
printf("\r%d packets gotten %d missed ", numPacketsGotten,
numPacketsMissed);
numPacketsGotten++;
fflush(stdout);
robot->comInt(ArCommands::IOREQUEST, 1);
requestTime.setToNow();
}
}
示例3: main
int main(int argc, char** argv)
{
// set up our simpleConnector
ArSimpleConnector simpleConnector(&argc, argv);
// robot
ArRobot robot;
// a key handler so we can do our key handling
ArKeyHandler keyHandler;
ArLog::init(ArLog::StdOut,ArLog::Verbose);
// if there are more arguments left then it means we didn't
// understand an option
if (!simpleConnector.parseArgs() || argc > 1)
{
simpleConnector.logOptions();
keyHandler.restore();
exit(1);
}
// mandatory init
Aria::init();
ArLog::init(ArLog::StdOut, ArLog::Terse, NULL, true);
// let the global aria stuff know about it
Aria::setKeyHandler(&keyHandler);
// toss it on the robot
robot.attachKeyHandler(&keyHandler);
// set up the robot for connecting
if (!simpleConnector.connectRobot(&robot))
{
printf("Could not connect to robot... exiting\n");
Aria::shutdown();
keyHandler.restore();
return 1;
}
// turn on the motors for the velocity response test
robot.comInt(ArCommands::ENABLE, 1);
velTime.setToNow();
// turn off the sonar
robot.comInt(ArCommands::SONAR, 0);
ArGlobalFunctor1<ArRobot *> userTaskCB(&userTask, &robot);
robot.addUserTask("iotest", 100, &userTaskCB);
robot.comInt(ArCommands::IOREQUEST, 1);
requestTime.setToNow();
//start the robot running, true so that if we lose connection the run stops
robot.run(true);
// now exit
Aria::shutdown();
return 0;
}
示例4: getTimeRead
AREXPORT ArTime ArSerialConnection::getTimeRead(int index)
{
ArTime ret;
struct timeval timeStamp;
if (myPort <= 0)
{
ret.setToNow();
return ret;
}
if (myTakingTimeStamps)
{
timeStamp.tv_sec = index;
if (ioctl(myPort, TIOGETTIMESTAMP, &timeStamp) == 0)
{
ret.setSec(timeStamp.tv_sec);
ret.setMSec(timeStamp.tv_usec / 1000);
}
else
ret.setToNow();
}
else
ret.setToNow();
return ret;
}
示例5: go_to_position
int go_to_position(ArRobot * robot, ArSick * sick, tracking_object position, float v = 300.0)
{
(*robot).lock();
(*robot).setDeltaHeading(position.degree - 90);
(*robot).unlock();
ArUtil::sleep(10);
long int drive_time = (position.distance * 1000)/(v);
ArTime start;
(*robot).lock();
(*robot).setVel(v);
(*robot).unlock();
start.setToNow();
while(start.mSecSince() < drive_time)
{
;
}
(*robot).lock();
(*robot).setVel(0);
(*robot).unlock();
return(0);
}
示例6: printf
ArActionDesired *JoydriveAction::fire(ArActionDesired currentDesired)
{
int rot, trans;
printf("%6ld ms since last loop. ms longer than desired: %6ld. mpac %d\n",
lastLoopTime.mSecSince(),
lastLoopTime.mSecSince() - loopTime, myRobot->getMotorPacCount());
lastLoopTime.setToNow();
if (myJoyHandler.haveJoystick() && (myJoyHandler.getButton(1) ||
myJoyHandler.getButton(2)))
{
if (ArMath::fabs(myRobot->getVel()) < 10.0)
myRobot->comInt(ArCommands::ENABLE, 1);
myJoyHandler.getAdjusted(&rot, &trans);
myDesired.setVel(trans);
myDesired.setDeltaHeading(-rot);
return &myDesired;
}
else
{
myDesired.setVel(0);
myDesired.setDeltaHeading(0);
return &myDesired;
}
}
示例7: checkArm
/**
Requests that P2OS checks to see if the arm is still alive and immediately
exits. This is not a full init and differs that P2OS will still accept
arm commands and the arm will not be parked. If P2OS fails to find the arm
it will change the status byte accordingly and stop accepting arm related
commands except for init commands. If the parameter waitForResponse is true
then checkArm() will wait the appropriate amoutn of time and check the
status of the arm. If you wish to do the waiting else where the arm check
sequence takes about 200ms, so the user should wait 300ms then send a
ArP2Arm::requestStatus() to get the results of the check arm request. Since
there is a very noticable time delay, the user should use the
ArP2Arm::setPacketCB() to set a callback so the user knows when the packet
has been received.
This can be usefull for telling if the arm is still alive. The arm
controller can be powered on/off separately from the robot.
@param waitForResponse cause the function to block until their is a response
@see requestInit
@see setPacketCB
*/
AREXPORT ArP2Arm::State ArP2Arm::checkArm(bool waitForResponse)
{
ArTime now;
if (isGood())
{
now.setToNow();
if (!comArmInfo())
return(COMM_FAILED);
if (waitForResponse)
{
ArUtil::sleep(300);
if (!myLastInfoTime.isAfter(now))
return(COMM_FAILED);
if (isGood())
return(SUCCESS);
else
return(NO_ARM_FOUND);
}
else
return(SUCCESS);
}
else
return(NOT_CONNECTED);
}
示例8: setRobot
/**
Initialize the P2 Arm class. This must be called before anything else. The
setRobot() must be called to let ArP2Arm know what instance of an ArRobot
to use. It talks to the robot and makes sure that there is an arm on it
and it is in a good condition. The AROS/P2OS arm servers take care of AUX
port serial communications with the P2 Arm controller.
*/
AREXPORT ArP2Arm::State ArP2Arm::init()
{
ArLog::log(ArLog::Normal, "Initializing the arm.");
ArTime now;
if (myInited)
return(ALREADY_INITED);
if (!myRobot || !myRobot->isRunning() || !myRobot->isConnected())
return(ROBOT_NOT_SETUP);
Aria::addUninitCallBack(&myAriaUninitCB, ArListPos::FIRST);
ArLog::log(ArLog::Verbose, "Adding the P2 Arm packet handler.");
myRobot->addPacketHandler(&myArmPacketHandler, ArListPos::FIRST);
now.setToNow();
if (!comArmStats(StatusSingle))
return(COMM_FAILED);
ArUtil::sleep(100);
if (!comArmInfo())
return(COMM_FAILED);
ArUtil::sleep(300);
if (!now.isAfter(myLastStatusTime) || !now.isAfter(myLastInfoTime))
return(COMM_FAILED);
if (!(myStatus & ArmGood))
return(NO_ARM_FOUND);
myInited=true;
return(SUCCESS);
}
示例9: getTimeRead
AREXPORT ArTime ArTcpConnection::getTimeRead(int index)
{
MRPT_UNUSED_PARAM(index);
ArTime now;
now.setToNow();
return now;
}
示例10: userTask
void userTask(ArRobot *robot)
{
if (robot->getIOPacketTime().mSecSince() > requestTime.mSecSince())
return;
else
{
ArLog::log(ArLog::Terse, "last packet time: %ld", requestTime.mSecSince() - robot->getIOPacketTime().mSecSince());
fflush(stdout);
robot->comInt(ArCommands::IOREQUEST, 1);
requestTime.setToNow();
}
/* Uncomment the next section to test response in velocity commands. */
/*
if (abs((int)(robot->getVel() - vel)) <= ABOUT_RIGHT &&
velTime.secSince() > 5)
{
if (vel == 0)
vel = 200;
else if (vel == 200)
vel = 400;
else if (vel == 400)
vel = 0;
robot->setVel(vel);
velTime.setToNow();
}
ArLog::log(ArLog::Terse, "vel requested: %d\trobot vel: %3.2f\tvel time: %d", vel, robot->getVel(), velTime.mSecSince());
*/
ArLog::log(ArLog::Terse, "Aria cycle time: %d", robot->getCycleTime());
fflush(stdout);
}
示例11: setState
void TakeBlockToWall::setState(State state)
{
myState = state;
myNewState = true;
myStateStartTime.setToNow();
myStateStartPos = myRobot->getPose();
}
示例12: while
void *FillerThread::runThread(void *arg)
{
while (1)
{
myStartBusyTime.setToNow();
while (myStartBusyTime.mSecSince() < 150);
}
}
示例13: if
ArActionDesired *Acquire::fire(ArActionDesired currentDesired)
{
myDesired.reset();
myDesired.setVel(0);
switch (myState) {
case STATE_START_LOOKING:
myFirstTurn.clear();
mySecondTurn.clear();
myState = STATE_LOOKING;
myGripper->liftUp();
myGripper->gripClose();
printf("Acquire: Raising lift\n");
myStartUp.setToNow();
myTryingGripper = true;
case STATE_LOOKING:
if (myTryingGripper && (myStartUp.mSecSince() < 600 ||
((!myGripper->isLiftMaxed() ||
myGripper->getGripState() != 2) &&
myStartUp.mSecSince() < 5000)))
{
myGripper->liftUp();
myGripper->gripClose();
myDesired.setVel(0);
myDesired.setDeltaHeading(0);
return &myDesired;
}
else if (myTryingGripper)
{
printf("Acquire: Done raising lift %ld after started.\n",
myStartUp.mSecSince());
myTryingGripper = false;
}
if (myActs->getNumBlobs(myChannel) > 0)
{
myDesired.setDeltaHeading(0);
myState = STATE_SUCCEEDED;
printf("Acquire: Succeeded!\n");
}
else if (myFirstTurn.didAll() && mySecondTurn.didAll())
{
myDesired.setDeltaHeading(0);
myState = STATE_FAILED;
printf("Acquire: Did two revolutions, didn't see the blob, Failed!\n");
}
else
{
myFirstTurn.update(myRobot->getTh());
if (myFirstTurn.didAll())
mySecondTurn.update(myRobot->getTh());
myDesired.setDeltaHeading(8);
}
return &myDesired;
default:
myDesired.setVel(0);
myDesired.setDeltaHeading(0);
return &myDesired;
}
}
示例14: main
int main(void)
{
ArTcpConnection con;
ArRobot robot;
int ret;
std::string str;
JoydriveAction jdAct;
FillerThread ft;
ft.create();
FillerThread ft2;
ft2.create();
Aria::init();
/*
if (!jdAct.joystickInited())
{
printf("Do not have a joystick, set up the joystick then rerun the program\n\n");
Aria::shutdown();
return 1;
}
*/
if ((ret = con.open()) != 0)
{
str = con.getOpenMessage(ret);
printf("Open failed: %s\n", str.c_str());
Aria::shutdown();
return 1;
}
robot.setDeviceConnection(&con);
if (!robot.blockingConnect())
{
printf("Could not connect to robot... exiting\n");
Aria::shutdown();
return 1;
}
robot.comInt(ArCommands::SONAR, 0);
robot.comInt(ArCommands::ENABLE, 1);
robot.comInt(ArCommands::SOUNDTOG, 0);
lastLoopTime.setToNow();
loopTime = robot.getCycleTime();
robot.addAction(&jdAct, 100);
robot.runAsync(true);
robot.waitForRunExit();
Aria::shutdown();
return 0;
}
示例15:
std::vector<tracking_object> get_moving_objects(ArSick * sick, int ms_time, int num_scans, char user_command, int upper_angle = 10, int lower_angle = 350)
{
std::vector<tracking_object> objects1;
std::vector<tracking_object> objects2;
std::vector<tracking_object> obj_vector;
int t_elapsed;
ArTime start;
do
{
start.setToNow();
objects1 = run_sick_scan(sick, num_scans);
usleep(ms_time*1000);
objects2 = run_sick_scan(sick, num_scans, user_command);
t_elapsed = start.mSecSince();
}while((objects1.size() != objects2.size())&&(objects1.size() > 0));
unsigned int i = 0;
unsigned int j = 0;
for(j = 0; j < objects2.size(); j++)
{
tracking_object v;
tracking_object new_v;
v = objects2[j];
v.vmag = 99999.9;
for(i = 0; i < objects1.size(); i++)
{
new_v = v_calc(objects1[i],objects2[j],t_elapsed);
if (new_v.vmag < v.vmag)
{
v = new_v;
}
}
if(v.vmag > 3.0)
{
v.vmag = 0.0;
v.vrad = 0.0;
v.vtan = 0.0;
v.theta_dot = 0.0;
}
obj_vector.push_back(v);
}
return(obj_vector);
}