コード例 #1
0
int main( int argc, char** argv ){

#if (CISST_OS == CISST_LINUX_XENOMAI)
  // Xenomai stuff
  mlockall(MCL_CURRENT | MCL_FUTURE);
  RT_TASK task;
  rt_task_shadow( &task, "CANServer", 80, 0);
#endif

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  if( argc !=2 ){
    std::cerr << "Usage: " << argv[0] << " can[?]" << std::endl;
    return -1;
  }

  // Better to have the CAN device in loopback mode
  std::cout << "Ensure that the CAN device is in loopback mode" << std::endl;

  // get local component manager                                                
  mtsManagerLocal *taskManager;
  taskManager = mtsManagerLocal::GetInstance();

  // The RTSocketCAN component
#if (CISST_OS == CISST_LINUX_XENOMAI)
  mtsRTSocketCAN can( "CAN",
		      argv[1],
		      osaCANBus::RATE_1000,
		      osaCANBus::LOOPBACK_ON );
#else
  mtsSocketCAN can( "CAN",
		    argv[1],
		    osaCANBus::RATE_1000,
		    osaCANBus::LOOPBACK_ON );
#endif
  taskManager->AddComponent( &can );
  
  // A client
  CANclient client;
  taskManager->AddComponent( &client );

  // Connect the interfaces
  taskManager->Connect( client.GetName(), "IO", can.GetName(), "IO" );
  taskManager->Connect( client.GetName(), "CTL", can.GetName(), "CTL" );
  
  taskManager->CreateAll();
  taskManager->StartAll();

  // Wait to exit
  std::cout << "ENTER to exit" << std::endl;
  cmnGetChar();

  //taskManager->KillAll();
  //taskManager->Cleanup();

  return 0;
}
コード例 #2
0
ファイル: mtsWAMExample.cpp プロジェクト: jhu-saw/sawBarrett
int main( int argc, char** argv ){

  mtsTaskManager* taskManager = mtsTaskManager::GetInstance();

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  if( argc != 2 ){
    std::cout << "Usage: " << argv[0] << " can[0-1]" << std::endl;
    return -1;
  }

  osaSocketCAN can( argv[1], osaCANBus::RATE_1000 );

  if( can.Open() != osaCANBus::ESUCCESS ){
    CMN_LOG_RUN_ERROR << argv[0] << "Failed to open " << argv[1] << std::endl;
    return -1;
  }

  mtsWAM WAM( "WAM", &can, osaWAM::WAM_7DOF, OSA_CPU4, 80 );
  WAM.Configure();
  WAM.SetPositions( vctDynamicVector<double>(7, 
					     0.0, -cmnPI_2, 0.0, cmnPI, 
					     0.0, 0.0, 0.0 ) );
  taskManager->AddComponent( &WAM );

  WAMprobe probe;
  taskManager->AddComponent( &probe );

  taskManager->Connect( probe.GetName(), "Input",  WAM.GetName(),   "Output" );
  taskManager->Connect( probe.GetName(), "Output", WAM.GetName(),   "Input" );


  taskManager->CreateAll();
  taskManager->WaitForStateAll( mtsComponentState::READY );

  taskManager->StartAll();
  taskManager->WaitForStateAll( mtsComponentState::ACTIVE );

  std::cout << "ENTER to exit" << std::endl;
  cmnGetChar();

  taskManager->KillAll();
  taskManager->Cleanup();

  if( can.Close() != osaCANBus::ESUCCESS ){
    CMN_LOG_RUN_ERROR << argv[0] << "Failed to open " << argv[1] << std::endl;
    return -1;
  }

  return 0;
}
コード例 #3
0
int svlVideoCodecTCPStream::DialogCompression()
{
    if (Opened) return SVL_FAIL;

    std::string extension;
    std::cout << " # Enable lossy (JPEG) compression ('y' or other): ";
    int ival = cmnGetChar();
    if (ival == 'y' || ival == 'Y') {
        std::cout << "YES" << std::endl;
        return DialogCompression(".njpg");
    }
    std::cout << "NO" << std::endl;
    return DialogCompression(".ncvi");
}
コード例 #4
0
int main( int argc, char** argv ){

  mlockall(MCL_CURRENT | MCL_FUTURE);
  RT_TASK task;
  rt_task_shadow( &task, "GroupTest", 99, 0 );

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  if( argc != 2 ){
    std::cout << "Usage: " << argv[0] << " rtcan[0-1]" << std::endl;
    return -1;
  }

  osaRTSocketCAN can( argv[1], osaCANBus::RATE_1000 );

  if( can.Open() != osaCANBus::ESUCCESS ){
    std::cerr << argv[0] << "Failed to open " << argv[1] << std::endl;
    return -1;
  }

  osaBH8_280 BH( &can );

  if( BH.Initialize() != osaBH8_280::ESUCCESS ){
    std::cerr << "Failed to initialize WAM" << std::endl;
    return -1;
  }
  std::cout << "\n\n\n\n";
  double t1 = osaGetTime();
  size_t cnt=0;

  while( 1 ){

    Eigen::VectorXd q( 4, 0.1 );

    BH.GetPositions( q );
    //BH.SetPositions( q );

    }
    cmnGetChar();
  return 0;
}
コード例 #5
0
int main( int argc, char** argv ){

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  if( argc != 2 ){
    std::cout << "Usage: " << argv[0] << " can[0-1]" << std::endl;
    return -1;
  }

  osaSocketCAN can( argv[1], osaCANBus::RATE_1000 );

  if( can.Open() != osaCANBus::ESUCCESS ){
    CMN_LOG_RUN_ERROR << argv[0] << "Failed to open " << argv[1] << std::endl;
    return -1;
  }

  osaBH8_280 BH( &can );

  if( BH.Initialize() != osaBH8_280::ESUCCESS ){
    CMN_LOG_RUN_ERROR << "Failed to initialize WAM" << std::endl;
    return -1;
  }
  std::cout << "\n\n\n\n";
  double t1 = osaGetTime();
  size_t cnt=0;

  while( 1 ){

    vctDynamicVector<double> q( 4, 0.1 );

    BH.GetPositions( q );
    //BH.SetPositions( q );

    }
    cmnGetChar();
  return 0;
}
コード例 #6
0
int main(){

  mtsTaskManager* taskManager = mtsTaskManager::GetInstance();

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  osg::ref_ptr< osaOSGWorld > world = new osaOSGWorld;

  // Create a camera
  int x = 0, y = 0;
  int width = 320, height = 240;
  double Znear = 0.1, Zfar = 10.0;
  mtsOSGMono* camera;
  camera = new mtsOSGMono( "camera",
			   world,
			   x, y,
			   width, height,
			   55.0, ((double)width)/((double)height),
			   Znear, Zfar,
			   false );
  taskManager->AddComponent( camera );

  // create the camera motion
  CameraMotion cmotion;
  taskManager->AddComponent( &cmotion );

  // create the hubble motion
  HubbleMotion hmotion;
  taskManager->AddComponent( &hmotion );

  cmnPath path;
  path.AddRelativeToCisstShare("/models");
  path.AddRelativeToCisstShare("/models/hubble");

  vctFrame4x4<double> Rt(  vctMatrixRotation3<double>(),
			   vctFixedSizeVector<double,3>( 0.0, 0.0, 0.5 ) );
  mtsOSGBody* hubble;
  hubble = new mtsOSGBody( "hubble", path.Find("hst.3ds"), world, Rt, 0.8 );
  taskManager->AddComponent( hubble );

  osg::ref_ptr< osaOSGBody > background;
  background = new osaOSGBody( path.Find("background.3ds"), world,
			       vctFrame4x4<double>() );

  taskManager->Connect( camera->GetName(), "Input",
			cmotion.GetName(), "Output" );

  taskManager->Connect( hubble->GetName(), "Input",
			hmotion.GetName(), "Output" );

  taskManager->CreateAll();
  taskManager->WaitForStateAll( mtsComponentState::READY );

  taskManager->StartAll();
  taskManager->WaitForStateAll( mtsComponentState::ACTIVE );

  cmnGetChar();
  std::cout << "ENTER to quit" << std::endl;
  cmnGetChar();

  taskManager->KillAll();
  taskManager->Cleanup();

  return 0;

}
コード例 #7
0
int main(){

  mtsTaskManager* taskManager = mtsTaskManager::GetInstance();

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  osg::ref_ptr< mtsODEWorld > world = NULL;
  world = new mtsODEWorld( "world", 0.00001 );
  taskManager->AddComponent( world.get() );

  // Create a camera
  int x = 0, y = 0;
  int width = 640, height = 480;
  double Znear = 0.1, Zfar = 10.0;
  mtsOSGMono* camera;
  camera = new mtsOSGMono( "camera",
			   world,
			   x, y, width, height,
			   55.0, ((double)width)/((double)height),
			   Znear, Zfar );
  taskManager->AddComponent( camera );


  cmnPath path;
  path.AddRelativeToCisstShare("/models/WAM");
  vctFrame4x4<double> Rtw0;

  std::vector< std::string > models;
  models.push_back( path.Find("l1.obj") );
  models.push_back( path.Find("l2.obj") );
  models.push_back( path.Find("l3.obj") );
  models.push_back( path.Find("l4.obj") );
  models.push_back( path.Find("l5.obj") );
  models.push_back( path.Find("l6.obj") );
  models.push_back( path.Find("l7.obj") );

  mtsODEManipulator* WAM;
  WAM = new mtsODEManipulator( "WAM",
			       0.001,
			       OSA_CPU1,
			       20,
			       models,
			       world,
			       Rtw0,
			       path.Find("wam7.rob"),
			       path.Find("l0.obj"),
			       vctDynamicVector<double>( 7, 0.0 ) );
  taskManager->AddComponent( WAM );

  WAMMotion motion( 0.001 );
  taskManager->AddComponent( &motion );

  taskManager->Connect( motion.GetName(), "Input",  WAM->GetName(), "Output" );
  taskManager->Connect( motion.GetName(), "Output", WAM->GetName(), "Input" );

  taskManager->CreateAll();
  taskManager->WaitForStateAll( mtsComponentState::READY );

  taskManager->StartAll();
  taskManager->WaitForStateAll( mtsComponentState::ACTIVE );

  cmnGetChar();
  std::cout << "ENTER to quit" << std::endl;
  cmnGetChar();

  taskManager->KillAll();
  taskManager->Cleanup();

  return 0;

}
コード例 #8
0
int main(int argc, char * argv[])
{
    // log configuration
    cmnLogger::SetMask(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskFunction(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskDefaultLog(CMN_LOG_ALLOW_ALL);
    cmnLogger::AddChannel(std::cout, CMN_LOG_ALLOW_ERRORS_AND_WARNINGS);

    // set the log level of detail on select components
    cmnLogger::SetMaskClassMatching("mts", CMN_LOG_ALLOW_ALL);

    // enable system-wide thread-safe logging
#ifdef MTS_LOGGING
    mtsManagerLocal::SetLogForwarding(true);
#endif

    std::string globalComponentManagerIP;
    int stateCollectionFlag = 0;

    if (argc != 2) {
        std::cerr << "Usage: " << argv[0] << " [GlobalManagerIP] [flagForDataCollection]" << std::endl;
        std::cerr << "       GlobalManagerIP is set as 127.0.0.1 by default" << std::endl;
    }

    // Set global component manager's ip and argument type
    // If flag is not specified, or not 1, then use generic type (mtsDouble)
    if (argc == 1) {
        globalComponentManagerIP = "localhost";
    } else if (argc == 2) {
        globalComponentManagerIP = argv[1];
    }else if (argc == 3) {
        globalComponentManagerIP = argv[1];
        stateCollectionFlag = atoi(argv[2]);
    } else {
        exit(-1);
    }

    std::cout << "Starting server, IP = " << globalComponentManagerIP << " 'q' to stop" << std::endl;
    if(stateCollectionFlag){
        std::cout << "        with data collection. 's' to start/stop data collection" << std::endl;
    }

    // Get the TaskManager instance and set operation mode
    mtsManagerLocal * componentManager;
    try {
        componentManager = mtsManagerLocal::GetInstance(globalComponentManagerIP, "ProcessClient");
    } catch (...) {
        CMN_LOG_INIT_ERROR << "Failed to initialize local component manager" << std::endl;
        return 1;
    }

    // client
    mtsMedtronicStealthlinkExampleComponent * componentExample;
    if(stateCollectionFlag)
        componentExample= new mtsMedtronicStealthlinkExampleComponent("Example", 50 * cmn_ms, true);
    else
        componentExample = new mtsMedtronicStealthlinkExampleComponent("Example", 50 * cmn_ms);

    // add the components to the component manager
    componentManager->AddComponent(componentExample);

    // Connect the test component to the Stealthlink component
    if (!componentManager->Connect("ProcessClient", componentExample->GetName(), "Stealthlink",
                                   "ProcessServer", "Stealthlink", "Controller")) {
        CMN_LOG_INIT_ERROR << "Could not connect test component to Stealthlink component." << std::endl;
        return 0;
    }

    // Now, connect to the tools (we assume these are pre-defined in the XML file)
    if (!componentManager->Connect("ProcessClient", componentExample->GetName(), "Pointer",
                                   "ProcessServer", "Stealthlink", "Pointer")) {
        CMN_LOG_INIT_WARNING << "Could not connect test component to Pointer tool." << std::endl;
    }
    if (!componentManager->Connect("ProcessClient", componentExample->GetName(), "Frame",
                                   "ProcessServer", "Stealthlink",  "Frame")) {
        CMN_LOG_INIT_WARNING << "Could not connect test component to Frame tool." << std::endl;
    }

    // Connect the registration interface
    if (!componentManager->Connect("ProcessClient", componentExample->GetName(), "Registration",
                                   "ProcessServer", "Stealthlink",  "Registration")) {
        CMN_LOG_INIT_ERROR << "Could not connect test component to Registration interface." << std::endl;
        return 0;
    }

    // Connect the exam information interface
    if (!componentManager->Connect("ProcessClient", componentExample->GetName(), "ExamInformation",
                                   "ProcessServer", "Stealthlink", "ExamInformation")) {
        CMN_LOG_INIT_ERROR << "Could not connect test component to ExamInformation interface." << std::endl;
        return 0;
    }
    
    if(stateCollectionFlag)
    {
        if (!componentManager->Connect("ProcessClient", componentExample->GetName(), "CollectorState",
                                       "ProcessServer", "StealthlinkStateCollector", "Control")) {
            CMN_LOG_INIT_ERROR << "Could not connect test component to Control interface." << std::endl;
            return 0;
        }
    }

    // create the tasks, i.e. find the commands
    componentManager->CreateAll();
    componentManager->WaitForStateAll(mtsComponentState::READY);

    // start the periodic Run
    componentManager->StartAll();
    componentManager->WaitForStateAll(mtsComponentState::ACTIVE);

    // wait for keyboard input in command window
    int ch;
    // execution result used by all functions
    mtsExecutionResult executionResult;

    bool GCMActive = true;
    bool started = false;
    while (GCMActive && ch != 'q') {
        osaSleep(5.0 * cmn_ms);
        GCMActive = componentManager->IsGCMActive();

        ch = cmnGetChar();

        switch (ch) {
        case 's':
            if(started)
            {
                if(componentExample->CollectorState.StopCollection.IsValid())
                {
                    executionResult = componentExample->CollectorState.StopCollection();
                    osaSleep(0.1 * cmn_s);
                    std::cout << "Stop data collection" << std::endl;
                    started = false;
                }
            }
            else
            {
                if(componentExample->CollectorState.StartCollection.IsValid())
                {
                    executionResult = componentExample->CollectorState.StartCollection();
                    osaSleep(0.1 * cmn_s);
                    if(executionResult.IsOK())
                    {
                        std::cout << "Start data collection" << std::endl;
                        started = true;
                    }
                    else
                        std::cout << "StartCollection failed to execute." << std::endl;

                }
            }
            break;

        default:
            break;
        }

    }

    if (!GCMActive) {
        CMN_LOG_RUN_ERROR << "Global Component Manager is disconnected" << std::endl;
    }

    // cleanup
    componentManager->KillAll();
    componentManager->WaitForStateAll(mtsComponentState::FINISHED, 20.0 * cmn_s);

    // delete components
    delete componentExample;

    componentManager->Cleanup();

    return 0;
}
コード例 #9
0
ファイル: main_cisst.cpp プロジェクト: safecass/safecass
int main(int argc, char *argv[])
{
    srand(time(NULL));

    cmnLogger::AddChannel(std::cout, CMN_LOG_ALLOW_ERRORS_AND_WARNINGS);
    
    // Enable safety framework
    mtsComponentManager::InstallSafetyCoordinator();

    mtsManagerLocal * ComponentManager = 0;
    try {
        ComponentManager = mtsComponentManager::GetInstance();
    } catch (...) {
        std::cerr << "Failed to initialize local component manager" << std::endl;
        return 1;
    }

    // Create and setup components
    SensorWrapper sensorWrapper("Sensor", PERIOD);
    Control control("Control", PERIOD);
    UI ui("UI", PERIOD);

    SCASSERT(ComponentManager->AddComponent(&sensorWrapper));
    SCASSERT(ComponentManager->AddComponent(&control));
    SCASSERT(ComponentManager->AddComponent(&ui));

    // Read json file
    std::string fileName(JSON_FOLDER"/Sensor.json");
    if (!GetSafetyCoordinator->ReadConfigFile(fileName)) {
        std::cerr << "Failed to read json file: " << fileName << std::endl;
        return 1;
    }
    fileName = JSON_FOLDER"/Control.json";
    if (!GetSafetyCoordinator->ReadConfigFile(fileName)) {
        std::cerr << "Failed to read json file: " << fileName << std::endl;
        return 1;
    }

    CONNECT_LOCAL(sensorWrapper.GetName(), "SensorValue",
                  control.GetName(), "ReadSensorValue");
    CONNECT_LOCAL(control.GetName(), "ControlValue",
                  ui.GetName(), "ReadControlValue");

    // Install data collector
    mtsCollectorState collectorSensor(sensorWrapper.GetName(),
                                      sensorWrapper.GetDefaultStateTableName(),
                                      mtsCollectorBase::COLLECTOR_FILE_FORMAT_CSV);
    collectorSensor.AddSignal("SensorValue");
    collectorSensor.AddSignal("SensorValue2");

    SCASSERT(ComponentManager->AddComponent(&collectorSensor));

    collectorSensor.Connect();

    ComponentManager->CreateAll();
    ComponentManager->WaitForStateAll(mtsComponentState::READY);
    ComponentManager->StartAll();
    ComponentManager->WaitForStateAll(mtsComponentState::ACTIVE);

    // start data collection
    collectorSensor.StartCollection(0.0);

    std::cout << "Press 'q' to quit." << std::endl;

    // loop until 'q' is pressed
    int key = ' ';
    while (key != 'q') {
        key = cmnGetChar();
        osaSleep(100 * cmn_ms);
    }
    std::cout << std::endl;

    // stop data collection
    collectorSensor.StopCollection(0.0);

    std::cout << "Cleaning up... " << std::flush;

    ComponentManager->KillAll();
    ComponentManager->WaitForStateAll(mtsComponentState::FINISHED, 2.0 * cmn_s);
    ComponentManager->Cleanup();

    std::cout << "Done\n";

    return 0;
}
コード例 #10
0
int main(){

  mtsTaskManager* taskManager = mtsTaskManager::GetInstance();

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  osg::ref_ptr< mtsODEWorld > world = NULL;
  world = new mtsODEWorld( "world", 0.0001, vctFixedSizeVector<double,3>(0.0) );
  taskManager->AddComponent( world.get() );

  // Create a camera
  int x = 0, y = 0;
  int width = 640, height = 480;
  double Znear = 0.1, Zfar = 10.0;
  mtsOSGMono* camera;
  camera = new mtsOSGMono( "camera",
                           world,
                           x, y,
                           width, height,
                           55.0, ((double)width)/((double)height),
                           Znear, Zfar );
  taskManager->AddComponent( camera );

  cmnPath path;
  path.AddRelativeToCisstShare("/models/BH");
  std::string l0 = path.Find("l0.rob", cmnPath::READ);
  std::string l1 = path.Find("l1.rob", cmnPath::READ);
  std::string l2 = path.Find("l2.rob", cmnPath::READ);
  std::string l3 = path.Find("l3.rob", cmnPath::READ);
  std::string f1f2 = path.Find("f1f2.rob", cmnPath::READ);
  std::string f3 = path.Find("f3.rob", cmnPath::READ);

  vctFrame4x4<double> Rtw0;
  Rtw0[2][3] = 0.1;

  mtsODEBarrettHand* BH;
  BH = new mtsODEBarrettHand( "BH",
			      0.001,
			      OSA_CPU1,
			      20,
			      l0,
			      l1,
			      l2,
			      l3,
			      world,
			      Rtw0,
			      f1f2,
			      f3 );
  taskManager->AddComponent( BH );

  BHMotion motion;
  taskManager->AddComponent( &motion );

  taskManager->Connect( motion.GetName(), "Input",  BH->GetName(), "Output" );
  taskManager->Connect( motion.GetName(), "Output", BH->GetName(), "Input" );

  taskManager->CreateAll();
  taskManager->WaitForStateAll( mtsComponentState::READY );

  taskManager->StartAll();
  taskManager->WaitForStateAll( mtsComponentState::ACTIVE );

  cmnGetChar();
  std::cout << "ESC to quit" << std::endl;
  cmnGetChar();

  taskManager->KillAll();
  taskManager->Cleanup();

  return 0;

}
コード例 #11
0
int main( ){

  mtsTaskManager* taskManager = mtsTaskManager::GetInstance();

  cmnLogger::SetMask( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskFunction( CMN_LOG_ALLOW_ALL );
  cmnLogger::SetMaskDefaultLog( CMN_LOG_ALLOW_ALL );

  // Create the OSG world
  osg::ref_ptr< osaOSGWorld > world = new osaOSGWorld;

  // Create OSG camera
  int x = 0, y = 0;
  int width = 640, height = 480;
  double Znear = 0.1, Zfar = 10.0;

  osg::Node::NodeMask maskleft  = 0x01;
  osg::Node::NodeMask maskright = 0x02;

  mtsOSGStereo* camera;
  camera = new mtsOSGStereo( "camera",
			     world,
			     x, y,
			     width, height,
			     55.0, ((double)width)/((double)height),
			     Znear, Zfar,
			     0.1 );
  camera->setCullMask( maskleft, osaOSGStereo::LEFT );
  camera->setCullMask( maskright, osaOSGStereo::RIGHT );
  taskManager->AddComponent( camera );

  // create the hubble motion
  HubbleMotion hmotion;
  taskManager->AddComponent( &hmotion );


  // create hubble
  cmnPath path;
  path.AddRelativeToCisstShare("/models/hubble");
  path.AddRelativeToCisstShare("/movies");

  vctFrame4x4<double> Rt( vctMatrixRotation3<double>(),
			  vctFixedSizeVector<double,3>( 0.0, 0.0, 0.5 ) );
  mtsOSGBody* hubble;
  hubble = new mtsOSGBody( "hubble", path.Find("hst.3ds"), world, Rt, 1.0, .5 );
  taskManager->AddComponent( hubble );


  // connect the motion to hubble
  taskManager->Connect( hubble->GetName(), "Input",
  			hmotion.GetName(), "Output" );


  // start the components
  taskManager->CreateAll();
  taskManager->WaitForStateAll( mtsComponentState::READY );
  taskManager->StartAll();
  taskManager->WaitForStateAll( mtsComponentState::ACTIVE );


  // Start the svl stuff
  svlInitialize();

  // Creating SVL objects
  svlStreamManager streamleft;
  svlFilterSourceVideoFile sourceleft(1);
  svlOSGImage imageleft( -0.5, -0.5, 1, 1, world );

  // Configure the filters
  sourceleft.SetFilePath( path.Find( "left.mpg" ) );
  imageleft.setNodeMask( maskleft );

  streamleft.SetSourceFilter( &sourceleft );
  sourceleft.GetOutput()->Connect( imageleft.GetInput() );

  svlStreamManager streamright;
  svlFilterSourceVideoFile sourceright(1);
  svlOSGImage imageright( -0.5, -0.5, 1, 1, world );

  sourceright.SetFilePath( path.Find( "right.mpg" ) );
  imageright.setNodeMask( maskright );

  streamright.SetSourceFilter( &sourceright );
  sourceright.GetOutput()->Connect( imageright.GetInput() );

  // start the streams
  if (streamleft.Play() != SVL_OK)
    { std::cerr << "Cannot start left stream." <<std::endl; }

  if (streamright.Play() != SVL_OK)
    { std::cerr << "Cannot start right stream." <<std::endl; }

  std::cout << "ENTER to exit." << std::endl;
  cmnGetChar();
  cmnGetChar();

  streamleft.Release();
  streamright.Release();

  taskManager->KillAll();
  taskManager->Cleanup();

  return 0;

}
コード例 #12
0
ファイル: main.cpp プロジェクト: branman59x/cisst
int main(int argc, char** argv)
{
    cmnLogger::SetMask(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskFunction(CMN_LOG_ALLOW_ALL);
    cmnLogger::SetMaskDefaultLog(CMN_LOG_ALLOW_ALL);

    cmnCommandLineOptions options;
    const std::string configFilePrefix = "camera-viewer";

    int portNumber = 0;
    std::string codecName = ".njpg";

    int numberOfChannels = 1;
    int latencyInFrames = 0;
    unsigned int width = 0;
    unsigned int height = 0;

    int numberOfThreads = 4;
    options.AddOptionOneValue("t", "threads",
                              "Number of threads, default is 4",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &numberOfThreads);

    options.AddOptionOneValue("c", "channels",
                              "Number of channels, 1 for mono (default), 2 for stereo",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &numberOfChannels);

    options.AddOptionOneValue("p", "port",
                              "IP port for network based codec",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &portNumber);

    options.AddOptionNoValue("d", "dual-port",
                             "Create two ports to send left/right separately (default is single port)",
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    options.AddOptionOneValue("w", "width",
                              "Resize width (if specified, requires height)",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &width);

    options.AddOptionOneValue("h", "height",
                              "Resize height (if specified, requires width)",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &height);

    options.AddOptionNoValue("f", "flip-horizontal",
                             "Flip image left to right",
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    options.AddOptionOneValue("l", "latency",
                              "Add latency (in number of frames)",
                              cmnCommandLineOptions::OPTIONAL_OPTION, &latencyInFrames);

    options.AddOptionNoValue("s", "save-configuration",
                             std::string("Save camera configuration in ") + configFilePrefix + std::string("-{mono,stereo}.dat"),
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    options.AddOptionNoValue("n", "no-window",
                             "don't display preview",
                             cmnCommandLineOptions::OPTIONAL_OPTION);

    std::string errorMessage;
    if (!options.Parse(argc, argv, errorMessage)) {
        std::cerr << "Error: " << errorMessage << std::endl;
        options.PrintUsage(std::cerr);
        return -1;
    }

    if ((numberOfChannels != 1) && (numberOfChannels != 2)) {
        std::cerr << "Error: number of channels can be either 1 or 2." << std::endl;
        return -1;
    }

    std::string configFile = configFilePrefix;
    if (numberOfChannels == 1) {
        configFile.append("-mono.dat");
    } else {
        configFile.append("-stereo.dat");
    }

    if ((width != 0) || (height != 0)) {
        if ((width == 0) || (height == 0)) {
            std::cerr << "Error: you need to specify both width and height, both need to be greater than 0." << std::endl;
            return -1;
        }
    }

    svlInitialize();

    // connect the source to the stream
    svlFilterSourceVideoCapture source(numberOfChannels);
    if (source.LoadSettings(configFile.c_str()) != SVL_OK) {
        source.DialogSetup(SVL_LEFT);
        source.DialogSetup(SVL_RIGHT);
    }
    if (options.IsSet("save-configuration")) {
        source.SaveSettings(configFile.c_str());
    }

    svlFilterImageWindow previewWindow;
    previewWindow.SetName("Video");
    previewWindow.SetTitle("cisstCameraViewer");

    svlStreamManager stream(numberOfThreads);
    stream.SetSourceFilter(&source);

    // connect the source to next filter
    svlFilterOutput * output;
    output = source.GetOutput();

    // first resize if needed
    svlFilterImageResizer resize;
    if (width != 0) {
        resize.SetName("Resize");
        resize.SetInterpolation(true);
        resize.SetOutputSize(width, height, SVL_LEFT);
        resize.SetOutputSize(width, height, SVL_RIGHT);
        output->Connect(resize.GetInput());
        output = resize.GetOutput();
    }

    // flip if needed
    svlFilterImageFlipRotate flip;
    if (options.IsSet("flip-horizontal")) {
        flip.SetHorizontalFlip(true);
        output->Connect(flip.GetInput());
        output = flip.GetOutput();
    }

    // latency if needed
    svlFilterAddLatency latency;
    if (latencyInFrames > 0) {
        latency.SetFrameDelayed(latencyInFrames);
        output->Connect(latency.GetInput());
        output = latency.GetOutput();
    }

    // writer on network
    svlFilterVideoFileWriter writer;
    svlFilterStereoImageJoiner stereoJoiner;

    if (options.IsSet("port")) {
        // detect if codec is available
        svlVideoCodecBase * codec = svlVideoIO::GetCodec(codecName);
        if (codec == 0) {
            std::string formatlist;
            svlVideoIO::GetFormatList(formatlist);
            std::cerr << "Error: can't find codec " << codecName << std::endl
                      << "Supported formats:" << std::endl
                      << formatlist << std::endl;
            return -1;
        }
        svlVideoIO::Compression * compr = codec->GetCompression();
        svlVideoIO::ReleaseCodec(codec);
        compr->data[0] = 75;

        writer.SetCodecParams(compr);
        svlVideoIO::ReleaseCompression(compr);

        std::stringstream filePath;
        filePath << "@" << portNumber << codecName;
        std::cout << "Opening network using " << filePath.str() << std::endl;

        // stereo
        if (numberOfChannels == 2) {
            // two channels
            if (options.IsSet("dual-port")) {
                writer.SetFilePath(filePath.str(), SVL_LEFT);
                filePath.str(std::string());
                filePath << "@" << portNumber + 1 << codecName;
                std::cout << "Opening network using " << filePath.str() << std::endl;
                writer.SetFilePath(filePath.str(), SVL_RIGHT);
            } else {
                // join the two channels using the stereo image joiner
                output->Connect(stereoJoiner.GetInput());
                output = stereoJoiner.GetOutput();
                writer.SetFilePath(filePath.str());
            }
        } else {
            writer.SetFilePath(filePath.str());
        }
        writer.OpenFile();

        output->Connect(writer.GetInput());
        output = writer.GetOutput();
    }

    // connect the last filter to preview if desired
    if (!options.IsSet("no-window")) {
        output->Connect(previewWindow.GetInput());
    }

    if (stream.Play() != SVL_OK) {
        std::cerr << "Failed to start the stream." << std::endl;
        return 0;
    }
    std::cout << argv[0] << " started, press 'q' to stop." << std::endl;

    char c;
    do {
        c = cmnGetChar();
        switch (c) {
        case '+':
            latency.UpLatency();
            break;
        case '-':
            latency.DownLatency();
            break;
        }
    } while (c != 'q');

    std::cout << "Stopping video stream." << std::endl;
    stream.Release();

    cmnLogger::Kill();
    return 0;
}