Ejemplo n.º 1
0
int main(int argc, const char * argv[])
{
  string       errmsg;
  string       target;
  YVoltage    *sensor;
  YVoltage    *sensorAC;
  YVoltage    *sensorDC;
  YModule     *m;

  if (argc < 2) {
    usage();
  }
  target = (string) argv[1];

  YAPI::DisableExceptions();

  // Setup the API to use local USB devices
  if (YAPI::RegisterHub("usb", errmsg) != YAPI_SUCCESS) {
    cerr << "RegisterHub error: " << errmsg << endl;
    return 1;
  }

  if (target == "any") {
    // retreive any voltage sensor (can be AC or DC)
    sensor = YVoltage::FirstVoltage();
    if (sensor == NULL) {
      cerr << "No module connected (Check cable)" << endl;
      exit(1);
    }
  } else {
    sensor = YVoltage::FindVoltage(target + ".voltage1");
  }

  // we need to retreive both DC and AC voltage from the device.
  if (sensor->isOnline())  {
    m = sensor->get_module();
    sensorDC = YVoltage::FindVoltage(m->get_serialNumber() + ".voltage1");
    sensorAC = YVoltage::FindVoltage(m->get_serialNumber() + ".voltage2");
  } else {
    cerr << "No module connected (Check cable)" << endl;
    exit(1);
  }
  while(1) {
    if (!sensorDC->isOnline())  {
      cout << "Module disconnected" << endl;
      break;
    }
    cout << "Voltage,  DC : " << sensorDC->get_currentValue() << " v";
    cout << "   AC : " << sensorAC->get_currentValue() << " v";
    cout << "  (press Ctrl-C to exit)" << endl;
    YAPI::Sleep(1000, errmsg);
  };
  yFreeAPI();

  return 0;
}
Ejemplo n.º 2
0
int main(int argc, const char * argv[])
{
    string       errmsg;
    string       target;
    YCurrent    *sensor;
    YCurrent    *sensorAC;
    YCurrent    *sensorDC;
    YModule     *m;

    if (argc < 2)  usage(argv[0]);
    
    target = (string) argv[1];
    
    // Setup the API to use local USB devices
    if (yRegisterHub("usb", errmsg) != YAPI_SUCCESS) {
        cerr << "RegisterHub error: " << errmsg << endl;
        return 1;
    }

    if (target == "any") {
        // retreive any voltage sensor (can be AC or DC)
        sensor = yFirstCurrent();
        if (sensor==NULL)
            die ("No module connected");
    } else {
        sensor = yFindCurrent(target + ".current1");
    }
    
    // we need to retreive both DC and AC voltage from the device.    
    if (sensor->isOnline())  {
        m = sensor->get_module();
        sensorDC = yFindCurrent(m->get_serialNumber() + ".current1");
        sensorAC = yFindCurrent(m->get_serialNumber() + ".current2");
      } else {
        die("Module not connected");
      }
    while(1) {
        if (!m->isOnline())  die("Module not connected");        
        cout << "Current,  DC : " << sensorDC->get_currentValue() << " mA";
        cout << "   AC : " << sensorAC->get_currentValue() << " mA";
        cout << "  (press Ctrl-C to exit)" << endl;
        ySleep(1000,errmsg);
    };
        
    return 0;
}
Ejemplo n.º 3
0
int main(int argc, const char * argv[])
{
    int i;
    string      errmsg;
    vector<string> hubs;
    vector<string> shield;
    vector<string> devices;

    // Setup the API to use local USB devices
    if(YAPI::RegisterHub("usb", errmsg) != YAPI_SUCCESS) {
        cerr << "RegisterHub error: " << errmsg << endl;
        return 1;
    }
    for (i = 1; i < argc; i++) {
        string hub_url = string(argv[i]);
        cout << "Update module connected to hub " << hub_url << endl;
        if(YAPI::RegisterHub(hub_url, errmsg) != YAPI_SUCCESS) {
            cerr << "RegisterHub error: " << errmsg << endl;
            return 1;
        }
    }
    //first step construct the list of all hub /shield and devices connected
    YModule *module = YModule::FirstModule();
    while (module){
        string product = module->get_productName();
        string serial  = module->get_serialNumber();
        if (product == "YoctoHub-Shield") {
            shield.push_back(serial);
        } else if (product.substr(0,9) == "YoctoHub-")
        {
            hubs.push_back(serial);
        } else if (product != "VirtualHub"){
            devices.push_back(serial);
        }
        module = module->nextModule();
    }
    // first upgrades all Hubs...
    upgradeSerialList(hubs);
    // ... then all shield..
    upgradeSerialList(shield);
    // ... and finaly all devices
    upgradeSerialList(devices);
    cout << "All devices are now up to date" << endl;
    YAPI::FreeAPI();
    return 0;
}
Ejemplo n.º 4
0
int main(int argc, const char * argv[])
{
  string      errmsg;

  // Setup the API to use local USB devices
  if(yRegisterHub("usb", errmsg) != YAPI_SUCCESS) {
    cerr << "RegisterHub error: " << errmsg << endl;
    return 1;
  }

  cout << "Device list: " << endl;

  YModule *module = yFirstModule();
  while (module != NULL) {
    cout << module->get_serialNumber() << " ";
    cout << module->get_productName()  << endl;
    module = module->nextModule();
  }
  return 0;
}
Ejemplo n.º 5
0
int main(int argc, const char * argv[])
{
    string      errmsg;
    
    // Setup the API to use local USB devices
    if(yRegisterHub("usb", errmsg) != YAPI_SUCCESS) {
        cerr << "RegisterHub error: " << errmsg << endl;
        return 1;
    }
    
    if(argc < 2)
        usage(argv[0]);
    
    YModule *module = yFindModule(argv[1]);  // use serial or logical name
    
    if (module->isOnline()) {
        if (argc > 2) {
            if (string(argv[2]) == "ON")
                module->set_beacon(Y_BEACON_ON);
            else
                module->set_beacon(Y_BEACON_OFF);
        }
        cout << "serial:       " << module->get_serialNumber() << endl;
        cout << "logical name: " << module->get_logicalName() << endl;
        cout << "luminosity:   " << module->get_luminosity() << endl;
        cout << "beacon:       ";
        if (module->get_beacon()==Y_BEACON_ON)
            cout << "ON" << endl;
        else
            cout << "OFF" << endl;
        cout << "upTime:       " << module->get_upTime()/1000 << " sec" << endl;
        cout << "USB current:  " << module->get_usbCurrent() << " mA" << endl;
        cout << "Logs:"<< endl << module->get_lastLogs() << endl;
    } else {
        cout << argv[1] << " not connected (check identification and USB cable)"
        << endl;
    }
    return 0;
}
Ejemplo n.º 6
0
int main(int argc, char **argv)
{
    /**
     * The ros::init() function needs to see argc and argv so that it can perform
     * any ROS arguments and name remapping that were provided at the command line. For programmatic
     * remappings you can use a different version of init() which takes remappings
     * directly, but for most command-line programs, passing argc and argv is the easiest
     * way to do it.  The third argument to init() is the name of the node.
     *
     * You must call one of the versions of ros::init() before using any other
     * part of the ROS system.
     */
    ros::init(argc, argv, "yocto_PWM");

    /**
     * NodeHandle is the main access point to communications with the ROS system.
     * The first NodeHandle constructed will fully initialize this node, and the last
     * NodeHandle destructed will close down the node.
     */
    ros::NodeHandle n;

    /**
     * The advertise() function is how you tell ROS that you want to
     * publish on a given topic name. This invokes a call to the ROS
     * master node, which keeps a registry of who is publishing and who
     * is subscribing. After this advertise() call is made, the master
     * node will notify anyone who is trying to subscribe to this topic name,
     * and they will in turn negotiate a peer-to-peer connection with this
     * node.  advertise() returns a Publisher object which allows you to
     * publish messages on that topic through a call to publish().  Once
     * all copies of the returned Publisher object are destroyed, the topic
     * will be automatically unadvertised.
     *
     * The second parameter to advertise() is the size of the message queue
     * used for publishing messages.  If messages are published more quickly
     * than we can send them, the number here specifies how many messages to
     * buffer up before throwing some away.
     */
    ros::Publisher pub = n.advertise<yocto::PWM_info>("/yocto/pwm_info", 1000); //avisa que irá publicar no tópico /yocto/pwm_info

    ros::Rate loop_rate(10);

    string       errmsg;
    string       target1 = "YPWMRX01-37171";
    string       target2 = "YPWMRX01-43C43";
    YPwmInput   *pwm;
    YPwmInput   *pwm1;
    YPwmInput   *pwm2;
    YPwmInput   *pwm3;
    YPwmInput   *pwm4;
    YModule     *m;

    YAPI::DisableExceptions();

        // ROS_INFO("Node yocto rodando!\n");

    // Setup the API to use local USB devices
    if (YAPI::RegisterHub("usb", errmsg) != YAPI_SUCCESS) {
        cerr << "RegisterHub error: " << errmsg << endl;
        return 1;
    }

    // retreive any pwm input available
    pwm = YPwmInput::FindPwmInput(target1 + ".pwmInput1");
    if (pwm == NULL) {
        cerr << "No module connected (Check cable)" << endl;
        exit(1);
    }

    // we need to retreive both channels from the device.
    if (pwm->isOnline()) {
        m = pwm->get_module();
        pwm1 = YPwmInput::FindPwmInput(m->get_serialNumber() + ".pwmInput1");
        pwm2 = YPwmInput::FindPwmInput(m->get_serialNumber() + ".pwmInput2");
    } else {
            cerr << "No module connected (Check cable)" << endl;
            exit(1);
    }


    pwm = YPwmInput::FindPwmInput(target2 + ".pwmInput1");
    if (pwm == NULL) {
        cerr << "No module connected (Check cable)" << endl;
        exit(1);
    }

    // we need to retreive both channels from the device.
    if (pwm->isOnline()) {
        m = pwm->get_module();
        pwm3 = YPwmInput::FindPwmInput(m->get_serialNumber() + ".pwmInput1");
        pwm4 = YPwmInput::FindPwmInput(m->get_serialNumber() + ".pwmInput2");
    } else {
            cerr << "No module connected (Check cable)" << endl;
            exit(1);
    }





    yocto::PWM_info mtr;     //objeto da mensagem que será publicada
    while (ros::ok())
    {
        
        mtr.frequency_1     = pwm1->get_frequency();
        mtr.duty_cycle_1    = pwm1->get_dutyCycle();
        mtr.frequency_2     = pwm2->get_frequency();
        mtr.duty_cycle_2    = pwm2->get_dutyCycle();
        mtr.frequency_3     = pwm3->get_frequency();
        mtr.duty_cycle_3    = pwm3->get_dutyCycle();
        mtr.frequency_4     = pwm4->get_frequency();
        mtr.duty_cycle_4    = pwm4->get_dutyCycle();


         ROS_INFO("-----------------------------\n");
         ROS_INFO("Frequency:          %f", mtr.frequency_1);
         ROS_INFO("Duty Cycle 1:       %f", mtr.duty_cycle_1);
        // ROS_INFO("Frequency:        %f", mtr.frequency_2);
         ROS_INFO("Duty Cycle 2:       %f", mtr.duty_cycle_2);
        // ROS_INFO("Frequency:        %f", mtr.frequency_3);
         ROS_INFO("Duty Cycle 3:       %f", mtr.duty_cycle_3);
        // ROS_INFO("Frequency:        %f", mtr.frequency_4);
         ROS_INFO("Duty Cycle 4:       %f", mtr.duty_cycle_4);
   
        /**
        * The publish() function is how you send messages. The parameter
        * is the message object. The type of this object must agree with the type
        * given as a template parameter to the advertise<>() call, as was done
        * in the constructor above.
        */
        pub.publish(mtr);
        ros::spinOnce();
        loop_rate.sleep();
    }



    return 0;
}