so ich war heute 2stunden beim roboter und nun tuts... naja zumindest vom mechanischem her. ich stelle euch mein programm mit rein, falls es euch interessiert. das funktioniert nämlich so: ich habe als grundlage ersteinmal das beispielprogramm 'acs' genommen und immer wenn der linke bumper gedrückt wird, werden die pfeile geschoßen :
Code:
// Includes:
#include "RP6RobotBaseLib.h" // Always needs to be included!
/*****************************************************************************/
/**
* This function works similar to the ACS function and gets called everytime the
* Bumpers are hit (the Bumpers need to be pressed down for at least 100ms to make
* sure that it is registered by the program!)
*/
void bumpersStateChanged(void)
{
writeString_P("Bumpers state changed! BPL: ");
if(bumper_left) // Left Bumper
{
writeChar('o');
schuss();
}
else
writeChar(' ');
writeString_P(" | BPR: ");
if(bumper_right) // Right Bumper
writeChar('o');
else
writeChar(' ');
writeChar('\n');
}
void schuss(void){
writeChar('s');
if(PORTA == 0)
PORTA = 1;
else
PORTA = 0;
}
/*****************************************************************************/
// Main - The program starts here:
int main(void)
{
initRobotBase(); // Always call this first! The Processor will not work
// correctly otherwise.
// Write Message to UART:
writeString_P("\nRP6 ACS - Testprogram\n");
writeString_P("_____________________\n\n");
setLEDs(0b111111);
mSleep(1000);
setLEDs(0b001001);
// ---------------------------
// Register Event Handlers:
// Set Bumpers state changed event handler:
BUMPERS_setStateChangedHandler(bumpersStateChanged);
// ---------------------------
powerON(); // Activate all important Systems and turn power LED on.
// You always need to perform this command before you can
// use the ACS!
// Usually some of the RP6 Systems like the encoders, the ACS
// (and thus also IRCOMM reception),
// the current sensors and the power on LED are turned off to
// save Battery power (saves about 10mA).
// You can use powerOFF() to disable all those systems.
// ---------------------------
setACSPwrMed(); // Set ACS to medium power/range
// These are the __alternative__ settings:
// setACSPwrLow(); // Low power
// setACSPwrHigh(); // High Power
// and of course you can use:
// setACSPwrOff(); to turn it off completely!
// You can uncomment (= remove the "//" in front of a line) ONE of these
// lines and test how it affects the maximum range of the ACS and which
// Obstacles it can detect.
// ---------------------------
// selbst geschriebener Abschuss
DDRA = 1; // ADC0 auf Ausgang
// Main loop
while(true)
{
// This very very important function:
task_RP6System();
// handles a lot of things for you. For this example, it controls the
// ACS and sets the obstacle_right and obstacle_left values if it detects
// an obstacle. If you registered an event handler (s. above), it calls this
// event handler automatically as soon as one of these two values changes.
// Nearly the same applies for the bumpers - you can check the state
// of each bumper with bumper_left and bumper_right and everytime the
// state changes the event handler is called automatically.
// In some of the next examples you will see that this function also
// controls the motors and some motion functionality.
// But be careful with delay functions or other things that take a long
// time (gets problematic if there are delays greater than 50ms) if you
// use this! The delays may disturb the automatic control of all those
// systems mentioned above.
// Why do we need such a function?
// Well, several things that the MEGA32 needs to take care about are not
// that easy to understand (look at the task_ACS function
// and some of the other functions in the RP6RobotBaseLib.c!)
// and this makes it a lot easier for you!
// The only thing you really need to take care about is to call
// task_RP6System frequently! Then you will not have big problems usually.
}
return 0;
}
problem dabei ist immoment nur, dass wenn ich einmal den linken bumper drücke, dann schießt die kanone so lange, bis ich nochmal auf den linken bumper drücke. doch eigentlich soll es ja so sein, dass wenn man den bumper einmal berührt, dass er dann einen pfeil schießt. und wenn man ihn dann noch mal berührt, soll noch ein pfeil rausgeschoßen werden... wo liegt der fehler?
Lesezeichen