Exemple #1
0
/*
  This function set the cursor position.

  Stack:
  1: the instance table
  2: the accessed key
  3: the new index
 */
int		lui_input_set_index(lua_State *L)
{
  INPUT		*i;
  int		 n;

  luasoul_checkclass(L, 1, INPUT_CLASS, i); /* fill i */
  luasoul_checkint(L, 3, n);
  /* lua 'array' start a 1 */
  set_current_position(i, n - 1);
  return 0;
}
    virtual void Init(RobotInfo ri, NavInfo ni){
        tec_s_.Init(ri);
		tec_p_.Init();
		tec_r_.Init();
        speed_ = 40;
		local_status_ = P_REACHING;
        s_time_ = clock.now();
		tecType_ = TEC_P;
    	SeesawAng = ni.pos.Ang;
    	TimerStart(15000);
        set_current_position(pos, ni);
        edge_dir = Technic::LEFT;
    }
Exemple #3
0
/*
  input:addch(ch)
  put a wide character
*/
int		lui_addch_input(lua_State *L)
{
  INPUT		*i;
  wchar_t	*wstr;
  size_t	len;
  cchar_t	ch;

  luasoul_checkclass(L, 1, INPUT_CLASS, i); /* get input */
  luasoul_checklwcstr(L, 2, wstr, len);	    /* get wstring */

  /* FIXME: correct attributs to setcchar() ? */
  if (setcchar(&ch, wstr, WA_NORMAL, 0, NULL) == OK
      && wins_wch(i->pad, &ch) == OK)
    {
      /* man setcchar()
	 ...contain at most one spacing character, which must be the first */
      len = (size_t) wcwidth(*wstr);
      if (len != (size_t) -1 && len) /* don't move for 0 width */
	set_current_position(i, get_current_position(i) + len);
    }

  return 0;
}
Exemple #4
0
/*
  This function return the content of the buffer.

  Stack:
  1: the instance table
  2: the accessed key
  FIXME: use win_wchnstr, handle multiple lines ?
*/
int		lui_input_get_buff(lua_State *L)
{
  INPUT		*i;
  int		 pos;
  wchar_t	*buff;
  int		 len;


  luasoul_checkclass(L, 1, INPUT_CLASS, i); /* get input */
  pos = get_current_position(i);	    /* save cursor position */

  /* assume i->height == 1 */
  len = i->width * i->off;
  buff = malloc((len + 1) * sizeof(*buff));
  len = mvwinnwstr(i->pad, 0, 0, buff, len);
  while (iswspace(buff[--len]))	/* remove leading space characters */
    {}
  buff[len + 1] = L'\0';
  luasoul_pushwstring(L, buff);

  set_current_position(i, pos);	/* restore cursor position */
  return 1;
}
    virtual bool Run(RobotInfo ri, NavInfo ni, EventFlag evf, RobotCmd& cmd ){

        bool stay_mission = true;
		
		switch (local_status_){
        case P_REACHING: //シーソーに近づく
            speed_ = 10;
            if( evf.is_SetEvent(Robot::EVENT_GYRO)){
                evf.Set(Robot::EVENT_GYRO, false);
                Robot::Instance().Beep();
                set_current_position(pos, ni);
				local_status_ = S_APPROACH_BACK;

                // 助走するために少し下がる
                tec_s_.Init(ri);
                tecType_ = TEC_S;
                speed_ = -30;
            }
            break;

        case S_APPROACH_BACK:
            if( get_distance(pos, ni) > 100*100){
                set_current_position(pos, ni);
                Robot::Instance().Beep();
                local_status_ = S_STAGING;

                // 一気に登る
                tec_s_.Init(ri);
                tecType_ = TEC_S;
                speed_ = 100;
            }
            break;

        case S_STAGING: // 一気にシーソーへ登る
            if( get_distance(pos, ni) > 180*180){
                set_current_position(pos, ni);
                Robot::Instance().Beep(Robot::B);
                local_status_ = P_RECOVER_ON_SEESAW;
                    
                // とりあえずシーソー上でラインに復帰
                tecType_ = TEC_P;
                tec_p_.Init();
                speed_ = 10;
            }
            break;

        case P_RECOVER_ON_SEESAW: // とりあえずシーソー上でラインに復帰
            if( get_distance(pos, ni) > 200*200 ){
                set_current_position(pos, ni);
                Robot::Instance().Beep();
                local_status_ = S_GET_OFF; //左にそれながらシーソーを降りる
                tec_s_.Init(ri);
                tecType_ = TEC_S;
                speed_ = 40;
            }
            break;

            case S_GET_OFF:
                if(get_distance(pos, ni) > 250*250){
                    Robot::Instance().Beep(Robot::B);
                    local_status_ = S_RECOVER_ON_GROUND;

                    // ラインに復帰を試みる
                    tec_s_.Init(ri);
                    tecType_ = TEC_S;
                    speed_ = 10;

                }
                break;

            case S_RECOVER_ON_GROUND:
                /* 終了条件 */
                if(evf.is_SetEvent(Robot::EVENT_LIGHT_BLACK)){
                    set_current_position(pos, ni);
                    local_status_ = P_FOR_NEXT_MISSION;
                    Robot::Instance().Beep(Robot::G);
                    tecType_ = TEC_P;
                    tec_p_.Init();
                    speed_ = 20;
                    TimerStart(10000);
                }
                break;

            case P_FOR_NEXT_MISSION: // 最後に安定するまでライントレースして完全復帰する
                /* ミッション終了の条件 */
                if(get_distance(pos, ni) > 200*200){
                    Robot::Instance().Beep(Robot::E);
                    stay_mission = false;                 
                }
                break;
                
            default:
                stay_mission = true;
                break;
        } // end of switch-case(local_status_)


		/* 走行計算 */
		if(tecType_ == TEC_S){
			cmd = tec_s_.Calclate(speed_,
                              ri.rot_encoderL_val,
                              ri.rot_encoderR_val
                              );
			if(local_status_ == S_GET_OFF){
				cmd.param2 =- 3; // 左側へ降りる
			}
			if(local_status_ == S_RECOVER_ON_GROUND){
				cmd.param2 =+ 3; // 右側のラインへ復帰する
			}

		}else if(tecType_ == TEC_P){
			cmd = tec_p_.Calclate(ri.light_sensor_val, speed_, edge_dir);
			// if(local_status_ == S_STAGING || local_status_ == P_RECOVER_ON_SEESAW){
			// 	cmd.param2 = (S16)((F32)cmd.param2 * 0.7);
			// }
		}else if(tecType_ == TEC_R){
			cmd = tec_r_.Calclate(speed_, rotate_, dir_);
		}else if(tecType_ == TEC_T){
            // しっぽの設定はcase内で設定するよ
		}else{}
        
        return stay_mission;
    }