Пример #1
0
void agent_learn(void) {
    // 既に学習済みならセンサーから値を取り込まない
    if(visible[curY][curX]) return;

    visible[curY][curX] = true;
    uint8_t sensor_data = sensor_get();
    for(int k = 0; k < 4; ++k) {
        // 後ろのセンサーは付いていないので
        if(k == 2) continue;

        int ndir = (dir + k)%4;
        // 壁があるとき
        if(gbi(sensor_data, k)) {
            wall[curY][curX][ndir] = true;
        }

        int ny = curY + dy[ndir];
        int nx = curX + dx[ndir];
        if(check_pos(ny, nx)) {
            if(gbi(sensor_data, k)) {
                wall[ny][nx][(ndir + 2)%4] = true;
            }
        }
    }
}
Пример #2
0
/*! Checks if the H-Bridge for motor1 is in shutdown mode due to a fault.
    Detectable fault conditions include overtemperature and shorted to battery.
	@return 0 = no fault or not in drive mode, non-zero = fault detected
*/
u08 motor1Faulted()
{
	//We can't detect a fault when the user is forcing the H-bridge to disable (stopped mode), so return false.
	if (gbi(DDRE, DDE4))
	{
		//DIAGA/DIAGB is set as an output, so we can't read the fault.
		return 0;
	}
	else
	{
		//Read the state of the input pin, low means a fault was detected.
		return !gbi(PINE, PINE4);
	}
}
Пример #3
0
/*
 * Check if given directory contains a GRASS installation
 */
bool QgsGrass::isValidGrassBaseDir( QString const gisBase )
{
  QgsDebugMsg( "isValidGrassBaseDir()" );
  // GRASS currently doesn't handle paths with blanks
  if ( gisBase.isEmpty() || gisBase.contains( " " ) )
  {
    return false;
  }

  /* TODO: G_is_gisbase() was added to GRASS 6.1 06-05-24,
           enable its use after some period (others do update) */
#if 0
  if ( QgsGrass::versionMajor() > 6 || QgsGrass::versionMinor() > 0 )
  {
    if ( G_is_gisbase( gisBase.toUtf8().constData() ) ) return true;
  }
  else
  {
#endif
    QFileInfo gbi( gisBase + "/etc/element_list" );
    if ( gbi.exists() ) return true;
#if 0
  }
#endif
  return false;
}
Пример #4
0
/*! Sets the data direction for all 10 digital pins, using the lower 10 bits of the argument.
    @param directions Bit 0 (LSB) matches digital0 ... bit 9 matches digital9.
    A high (1) sets the pin as an output. A low (0) sets the pin as an input.
    @see Use digitalDirection() if you only want to configure a single digital pin.
 */
void digitalDirections(const u16 directions)
{
	const u08 lower = (u08)directions;
	//set digital0 as output
	if (gbi(lower, 0))
		sbi(DDRB, DDB4);
	//else set digital0 as input
	else
		cbi(DDRB, DDB4);

	//set digital1 as output
	if (gbi(lower, 1))
		sbi(DDRB, DDB7);
	//else set digital1 as input
	else
		cbi(DDRB, DDB7);

	//set directions for digital2-digital9
	DDRA = (u08)(directions >> 2);
}
Пример #5
0
/*! Sets the pullup resistor options for all 10 digital pins, using the lower 10 bits of the argument.
    Pullup option will only be set for a pin if the pin is currently configured as an input.
    @param pullups Bit 0 (LSB) matches digital0 ... bit 9 matches digital9.
    A high (1) will enable the pullup. A low (0) will disable the pullup.
    @see Use digitalDirection() if you only want to configure a single digital pin.
*/
void digitalPullups(const u16 pullups)
{
	//digital0
	if (gbi(DDRB, DDB4) == 0)
	{
		if (gbi(pullups, 0))
			sbi(PORTB, PB4); //enable pullup
		else
			cbi(PORTB, PB4); //disable pullup
	}
	//digital1
	if (gbi(DDRB, DDB7) == 0)
	{
		if (gbi(pullups, 1))
			sbi(PORTB, PB7); //enable pullup
		else
			cbi(PORTB, PB7); //disable pullup
	}
	//digital2-digital9
	u08 i;
	const u08 pullups2 = (u08)(pullups >> 2);
	for (i = 0; i < 8; i++)
	{
		if (gbi(DDRA, i) == 0)
		{
			if (gbi(pullups2, i))
				sbi(PORTA, i); //enable pullup
			else
				cbi(PORTA, i); //disable pullup
		}
	}
}
Пример #6
0
// ################
// ## Pixel data ##
// ################
void ht1632c_flip(uint8_t *buffer)
{
	// Start writing display values from the beginning on
	ht1632c_begin();
	ht1632c_put(0b101, 3);
	ht1632c_put(0, 7);

	int8_t seg, row, col;
	for (seg = 0; seg < 4; seg++)
		for (row = 7; row >= 0; row--)
			for (col = 0; col < 8; col++)
				ht1632c_putbit(gbi(buffer[seg*8+col], row));

	ht1632c_end();
}
Пример #7
0
/*! Reads the status of the BTN1 button.
    @return 0 when the button is not pressed and 1 when the button is pressed.
    @see Use buttonWait() if you want to wait for a button press and release.
 */
u08 getButton1()
{
	return (gbi(PIND, PIND4) == 0);
}
Пример #8
0
		else if (num == 1)
			cbi(PORTB, PB7);
		else if (num == 0)
			cbi(PORTB, PB4);
	}
}

/*! Sets the values of all 10 digital outputs, by reading the lower 10 bits of the argument.
    If setting a constant value, it is recommended to express the argument in hex notation.
    @param outputs Set bits to 1 to turn on corresponding outputs, or 0 to turn off corresponding outputs.
    @see Use digitalOutput() if you only want to set a single digital pin.
 */
void digitalOutputs(const u16 outputs)
{
	PORTA = (u08)(outputs>>2);
	PORTB = (PORTB & 0x6F) | ((gbis((u08)outputs, 1) << PB7) | (gbi((u08)outputs, 0) << PB4));
}

/*! Returns the 10 digital inputs packed into the lower 10 bits.
    This number will be easier to read if displayed in hex, for example by printHex_u16().
    @return 1 bits for corresponding high inputs, 0 bits for corresponding low inputs.
    Bit 0 (LSB) matches digital0 ... bit 9 matches digital9.
    @see Use digitalInput() if you only want to read a single digital pin.
 */
u16 digitalInputs()
{
	return (u16)((PINA<<2) | (gbis(PINB, PINB7)<<1) | gbis(PINB, PINB4));
}

/*! Toggles the value of a digital pin from 0 to 1 or vice versa.
    Only makes sense to use this with a pin that is already set as an output.
Пример #9
0
//Checks the status of the BTN1 button.
//Returns 0 when the button is not pressed and 1 when the button is pressed.
u08 getButton1()
{
	return gbi(PIND, 4) == 0;
}
Пример #10
0
bool button_get(enum BUTTON b)
{
	return !gbi(BUTTON_PIN, b);
}
Пример #11
0
void ht1632c_put(uint8_t data, int8_t len)
{
	int8_t i;
	for (i = len-1; i >= 0; i--)
		ht1632c_putbit(gbi(data, i));
}