void goHome()
{ 
  static int g_loop = 0;
  int power = 30;

  g_loop++;
  g_dist[1] = getPing(1);
  g_dist[2] = getPing(2);
  g_dist[3] = getPing(3);

  if (g_loop == 1 || g_dist[2] < 5 ) 
  {
    Stop();
    delay(500);
    return;
  }

  if(g_dist[2] > 70)
  {
    moveAngle(power, 0 , 180 );
  }
  else if(g_dist[1] >= 40 && g_dist[3] >= 40)
  {
    Stop();
  }
  else if(g_dist[1] > g_dist[3])
  {
    moveAngle(power , 0 , 270 );
  }
  else
  {
    moveAngle(power , 0 , 90);
  }
}
// 超音波センサのチェック.PingあるいはSeedo studioの超音波センサしか使えない.
void checkPing()
{
  int dist[PING_NUM] = {
    999, 999, 999, 999                                                };

  // measure the ultra sonic sensor
  for (int i = 0; i < PING_NUM; i++)
  {
    g_dist[i] = getPing(i);
  }

  if (g_use_lcd == 1)
  {
    slcd.setCursor(0,0);
    slcd.print("Pg:");
    for (int j = 0; j < 2; j++)
    {
      slcd.print(g_dist[j], DEC);
      slcd.print(" ");
    }
    slcd.setCursor(0,1);
    for (int j = 2; j < PING_NUM; j++)
    {
      slcd.print(g_dist[j], DEC);
      slcd.print(" ");
    }
  }
}
std::string Player::toString() {

	std::stringstream tmp;

	tmp << getUserName() << "[" << getClientId() << "] : ";
	tmp << "Ping: " << getPing() << " ";
	tmp << "Ship info: " << ship.toString();

	return tmp.str();

}
void Player::toPacket(sf::Packet* packet) {

	// Extract player info
	*packet << getClientId();
	*packet << getUserName();
	*packet << getPing();

	// Extract ship info
	ship.toPacket(packet);

}
void goHome()
{ 
  g_dist[1] = getPing(1);
  g_dist[2] = getPing(2);
  g_dist[3] = getPing(3);
  if(g_dist[2] > 70)
  {
    moveAngle4ch( 60, 0 , 180 );
  }
  else if(g_dist[1] >= 40 && g_dist[3] >= 40)
  {
    motor4ch(0,0,0,0);
  }
  else if(g_dist[1] > g_dist[3])
  {
    moveAngle4ch( 20 , 0 , 270 );
  }
  else
  {
    moveAngle4ch( 20 , 0 , 90);
  }
}
Exemple #6
0
BSONObj MongosType::toBSON() const {
    BSONObjBuilder builder;

    if (_name)
        builder.append(name.name(), getName());
    if (_ping)
        builder.append(ping.name(), getPing());
    if (_uptime)
        builder.append(uptime.name(), getUptime());
    if (_waiting)
        builder.append(waiting.name(), getWaiting());
    if (_mongoVersion)
        builder.append(mongoVersion.name(), getMongoVersion());
    if (_configVersion)
        builder.append(configVersion.name(), getConfigVersion());

    return builder.obj();
}
Exemple #7
0
MainWindow::MainWindow(QWidget *parent):QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    companyWebAddress ="explorer http://www.oschina.net/p/qtsharp";

    pingNet ="Ping www.baidu.com";   //实现ping值的实时测量
    getPing();
    QTimer *pingTimer=new QTimer(this);//此段作用是用一个定时器,每隔5s,查看一次当前ping值。
    connect(pingTimer,SIGNAL(timeout()),this,SLOT(pingTimeOut()));
    pingTimer->start(5000);

    bool ok=false;                      //定义声明一个服务器实体。
    getHostInformation();
    port=this->ui->editPort->text().toInt(&ok,10);
    tcpserver=new TcpServer(this,port);         //将server中的有用变量都复制到本函数中。
    robotHash=tcpserver->getRobotIDHash();
    robotNumberOnLine=tcpserver->getRobotNumber();
    showClientMessage();

    connect(tcpserver,SIGNAL(receiveDataSource(ProtocolFromClient2Server)),this,SLOT(receiveData(ProtocolFromClient2Server)));//接收数据槽函数。
    connect(this,SIGNAL(sendDataSource(QString,int)),this,SLOT(sendData(QString,int)));//发送数据槽函数。
}
void Forward()
{
  static int g_loop = 0;
  int power   = 60;  // power
  int power2  = 60;  // turn power
  getMaxball();
  PID();

  if (g_diff > 45 || g_diff < -45) turn(g_pid); 
  else
  { 
    g_integral = 0;
    if(g_no == 0) 
    {
      if(g_ball[0] > 300)
      {  
        g_dist[0] = getPing(0);
        g_dist[1] = getPing(1);
        g_dist[3] = getPing(3);
        if(g_dist[1] >= 35 && g_dist[2] >= 35)
        { 
          kick();
          moveAngle(power , 0 , 0);
        } 
        else if (g_dist[0] < 12)
        {
          if(g_dist[1] < 40)
          {
            turn(power2);
            delay(125);
          }
          else if (g_dist[3] < 40)
          { 
            turn(-power2);
            delay(125);
          } 
        }

      }
      else moveAngle(power , 0 , 0 );
    } 
    else if(g_no == 1)
    { 
      g_dist[1] = getPing(1);
      if (g_dist[1] < 10) moveAngle (power , 0 , 0);
      else if(g_ball[1] > 300)  moveAngle(power , 0 , 270 );
      else moveAngle(power , 0 , 315);
    } 
    else if(g_no == 2)
    {
      if(g_ball[2] > 300) moveAngle(power , 0 , 180);
      else moveAngle(power , 0 , 270);
    }
    else if(g_no == 3 ) 
    {
      moveAngle(power , 0 , 135 );
    }
    else if(g_no == 4 ) 
    {
      g_dist[1] = getPing(1);
      g_dist[3] = getPing(3);
      if (g_dist[1] > g_dist[3]) moveAngle(power , 0 , 270 );
      else moveAngle(60 , 0 , 90 );
    }
    else if (g_no == 5)
    { 
      if (g_ball[5] > 300) moveAngle(power , 0 , 225 );
      else moveAngle( 78 , 0 , 135);
    }
    else if (g_no == 6)
    {
      moveAngle(power , 0 , 180 );
    }
    else if(g_no == 7) 
    {
      g_dist[3] = getPing(3);
      if (g_dist[3] < 10) moveAngle (power , 0 , 0);
      else if (g_ball[7] > 300) moveAngle(power , 0 , 90 );
      else moveAngle(power , 0 , 45);
    }
    else goHome();
  }
  g_loop++;
}
Exemple #9
0
/*
* 用定时器做的一个5s固定查询ping值。
*/
void MainWindow::pingTimeOut()
{
    getPing();
}
void Forward()
{
  static int g_loop = 0;
  getMaxball();
  PID();

  if (g_diff > 45 || g_diff < -45) turn(20); 
  else
  { 
    g_integral == 0;
    if(g_no == 0) 
    {
      if(g_ball[0] > 300)
      {  
        g_dist[0] = getPing(0);
        g_dist[1] = getPing(1);
        g_dist[3] = getPing(3);
        if(g_dist[1] >= 35 && g_dist[2] >= 35)
        { 
          kick();
          moveAngle4ch( 78 , 0 , 0);
        } 
        else if (g_dist[0] < 12)
        {
          if(g_dist[1] < 40)
          {
            turn(80);
            delay(100);
          }
          else if (g_dist[3] < 40)
          { 
            turn(-80);
            delay(100);
          } 
        }

      }
      else moveAngle4ch( 78 , 0 , 0 );
    } 
    else if(g_no == 1)
    { 
      g_dist[1] = getPing(1);
      if (g_dist[1] < 10) moveAngle4ch (78 , 0 , 0);
      else if(g_ball[1] > 500)  moveAngle4ch( 78 , 0 , 255 );
      else moveAngle4ch( 78 , 0 , 315);
    } 
    else if(g_no == 2)
    {
      if(g_ball[2] > 500) moveAngle4ch( 78 , 0 , 180);

      else moveAngle4ch( 78 , 0 , 270);
    }
    else if(g_no == 3 ) 
    {
      moveAngle4ch( 78 , 0 , 135 );
    }


    else if(g_no == 4 ) 
    {
      g_dist[1] = getPing(1);
      g_dist[3] = getPing(3);
      if (g_dist[1] > g_dist[3]) moveAngle4ch( 78 , 0 , 270 );

      else moveAngle4ch(78 , 0 , 90 );
    }
    else if(g_no == 5)
    { 
      if (g_ball[5] > 500) moveAngle4ch( 78 , 0 , 255 );

      else moveAngle4ch( 78 , 0 , 135);
    }
    else if(g_no == 6) 
    {
      if(g_ball[6] > 500) moveAngle4ch( 78 , 0 , 180 );
      else moveAngle4ch(78, 0 ,90);
    }
    else if(g_no == 7) 
    {
      g_dist[3] = getPing(3);
      if (g_dist[3] < 10) moveAngle4ch (78 , 0 , 0);
      else if (g_ball[7] > 500) moveAngle4ch( 78 , 0 , 105);
      else moveAngle4ch ( 78 , 0 , 45);
    }
    else goHome();
  }
  g_loop++;
}
int ClientNetwork::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: packetReceived(); break;
        case 1: packetCorrupted(); break;
        case 2: pingUpdated((*reinterpret_cast< quint32(*)>(_a[1]))); break;
        case 3: chatReceived((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[4]))); break;
        case 4: serverInformationsChanged((*reinterpret_cast< ServerInformations(*)>(_a[1]))); break;
        case 5: clientIDChanged((*reinterpret_cast< CLID(*)>(_a[1]))); break;
        case 6: nicknameChanged((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 7: error((*reinterpret_cast< ENUM_TYPE(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 8: clientVoted((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break;
        case 9: newGameMaster((*reinterpret_cast< CLID(*)>(_a[1]))); break;
        case 10: serverName((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 11: motdChanged((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 12: gameLaunched(); break;
        case 13: narrationChanged((*reinterpret_cast< QString(*)>(_a[1]))); break;
        case 14: mapChanged((*reinterpret_cast< MapPtr(*)>(_a[1]))); break;
        case 15: mapFlare((*reinterpret_cast< QPoint(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break;
        case 16: scriptToGMMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 17: scriptToOwnerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 18: scriptActionMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 19: scriptToPlayerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 20: scriptMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 21: scriptError((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 22: updateEntities((*reinterpret_cast< const QList<EntityInformations>(*)>(_a[1]))); break;
        case 23: updateEntity((*reinterpret_cast< const EntityInformations(*)>(_a[1]))); break;
        case 24: entityDeleted((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 25: scriptReceived((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 26: ressourcesUpdated((*reinterpret_cast< const QMap<QString,RSID>(*)>(_a[1]))); break;
        case 27: connectionEtablished(); break;
        case 28: connectionLost(); break;
        case 29: diceRolled((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2])),(*reinterpret_cast< quint16(*)>(_a[3]))); break;
        case 30: sanctionned((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3]))); break;
        case 31: clientJoined((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 32: clientLeft((*reinterpret_cast< CLID(*)>(_a[1]))); break;
        case 33: playSound((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 34: syncLibs((*reinterpret_cast< QList<SoundLibInformations>(*)>(_a[1]))); break;
        case 35: syncLanguagesList((*reinterpret_cast< QList<QPair<QString,QString> >(*)>(_a[1]))); break;
        case 36: syncDictionariesList((*reinterpret_cast< QStringList(*)>(_a[1]))); break;
        case 37: syncScriptList((*reinterpret_cast< QStringList(*)>(_a[1]))); break;
        case 38: updateCharacterList((*reinterpret_cast< const QStringList(*)>(_a[1]))); break;
        case 39: send((*reinterpret_cast< Packet*(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 40: send((*reinterpret_cast< Packet*(*)>(_a[1]))); break;
        case 41: send((*reinterpret_cast< Packet(*)>(_a[1]))); break;
        case 42: send((*reinterpret_cast< qint32(*)>(_a[1])),(*reinterpret_cast< const QByteArray(*)>(_a[2]))); break;
        case 43: ping(); break;
        case 44: { qint32 _r = getPing();
            if (_a[0]) *reinterpret_cast< qint32*>(_a[0]) = _r; }  break;
        case 45: { QString _r = serverIP();
            if (_a[0]) *reinterpret_cast< QString*>(_a[0]) = _r; }  break;
        case 46: { quint16 _r = serverPort();
            if (_a[0]) *reinterpret_cast< quint16*>(_a[0]) = _r; }  break;
        case 47: flush(); break;
        case 48: connection(); break;
        case 49: disconnection(); break;
        case 50: { bool _r = setServer((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 51: connected(); break;
        case 52: disconnected(); break;
        case 53: dataReceived(); break;
        case 54: socketError((*reinterpret_cast< QAbstractSocket::SocketError(*)>(_a[1]))); break;
        case 55: operatePacket((*reinterpret_cast< Packet*(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 56;
    }
    return _id;
}
int main()
{
  //simpleterm_close(); //close default terminal, I want to use those pins
                      //if the default uart (Universal Asynchronous Recieve and Transmitting
                      // pins are not being used, this isn't needed
                      
  startComs(RX_PIN, TX_PIN, BAUD, 1000); //this will go to the bluetooth module eventually
//  startSensor(PING_PIN, LEFT_WHISKER, RIGHT_WHISKER);
  
  int speed = 20; //intial speed 20 ticks/s
  
  int n = 0;
  while(1)       //repeat until power loss                             
  {
    int command = rxCommand();
    switch(command) //wait for a control byte
    {
      case 'e':
        txInt32(n); //sending incrementing numbers
        n+=10000; 
        break;
      
      case 'b':
        txInt32(rxInt32()*2); //double received number
        break;  
      
      case '?': //send 42
        txInt32(42);
        break;
        
      case '0':
        startSensor(PING_PIN, LEFT_WHISKER, RIGHT_WHISKER);
        break;

      case 'z': //run function "startWander"
        startWander();
        break;
        
      case 'x': //run function "stopWander"
        stopWander();
        drive_speed(0,0);
        break;
        
      case 'f': //send sensor data
        print("p %d\tpc %d\tpi %d\twl %d\twr %d\ttl %d\ttr %d\n",getPing(), getPingcm(), getPingin(), getWhiskerL(), getWhiskerR(), getTicksL(), getTicksR());
        break;
     
      case 'v':
        txInt32(getTicksL());        
        txInt32(getTicksR());        
        txInt32(getPing());        
        txInt32(getWhiskerL());        
        txInt32(getWhiskerR());
        break;
        
      case 'h': //recieve drive speed from computer
        drive_speed(rxInt32(),rxInt32());
        break;
     
      case 'p':
        __builtin_propeller_clkset(0x80); //reboot
        break;

      case 'q': //stop movement
        drive_speed(0,0);
        break;
        
      case 'w': //move forward
        drive_speed(speed,speed);
        break;
      
      case 'a': //pivot left
        drive_speed(-speed,speed);
        break;
        
      case 's': //move backward
        drive_speed(-speed,-speed);
        break;
        
      case 'd': //pivot right
        drive_speed(speed,-speed);
        break;
      
      case 't': //toggle turbo mode up to 70 ticks/s
        if (speed>50) speed = 20; else speed =70;
        break;
        
      case 'j': //computer input for rotation
        drive_goto(rxInt32(),rxInt32());
        break;  
        
      case 'i': // print 
        print("X = %.2f, Y = %.2f, Th = %.1f\n", (double) getXcm(), (double) getYcm(), (double) getThdeg());
        break;
        
      case 'k': //kalibrate
        while(getThdeg()<90)
        {
          drive_speed(-speed,speed);
        }
        drive_speed(0,0);
        break;          
        
      case -1:    //case when timed out
        txInt32(314);
        break;
        
      default:    //unknown command
        txInt32(2718);
        txInt32(command);
        //print(command);
        print("\n%d\n",command);
    }        
    
    //Note: The computer can sometimes miss bytes 
    //when the bytes are coming really fast 
  }
}