übrigens: den Greifarm habe ich nun, einen Tag vor "abgabeschluß" der Wette fertig..
ich habe nur noch ein problem:
Code:
#include "RP6RobotBaseLib.h" // The RP6 Robot Base Library.
// Always needs to be included!
/*****************************************************************************/
// Defines:
// RP6 Base Servo Connection:
#define SERVO_OUT SCL // PINC1 XBUS Pin 12
// Servo movement limits (depending on servo type):
#define LEFT_TOUCH 950 // Left servo touch
#define RIGHT_TOUCH 154 // Right servo touch [max. 255]
#define PULSE_ADJUST 4
#define PULSE_REPETITION 19 // Pulse repetition frequency
#define MIDDLE_POSITION (RIGHT_TOUCH / 2) // Middle servo position
/*****************************************************************************/
// Functions:
/**
* INIT SERVO
*
* Call this once before using the servo task.
*
*/
void initSERVO(void)
{
DDRC |= SERVO_OUT; // SERVO_OUT -> OUTPUT
PORTC &= ~SERVO_OUT; // SERVO_OUT -> LO
startStopwatch1(); // Needed for 20ms pulse repetition
}
/**
* PULSE SERVO
*
* This is the servo pulse generation. This function
* must be called every 20ms (pulse repetition).
*
* position = 0 : Left touch
* position = RIGHT_TOUCH : Right touch
*
* ATTENTION: ! This function is BLOCKING all other activities for about 1 !
* ! to 2ms (depending on the value of position)!!! !
* ! If you generate a pulse every 20ms 5-10% of the processor's !
* ! calculating time is wasted by this kind of pulse generation. !
* ! If this is a problem for the rest of your program, you !
* ! cannot use this method. !
* ! You will need an interrupt-based solution instead. !
*
*/
void pulseSERVO(uint8_t position)
{
cli();
PORTC |= SERVO_OUT; // SERVO_OUT -> HI (pulse start)
delayCycles(LEFT_TOUCH);
while (position--) {
delayCycles(PULSE_ADJUST);
}
PORTC &= ~SERVO_OUT; // SERVO_OUT -> LO (pulse end)
sei();
}
/**
* SERVO TASK
*
* This is the servo demo task.
* The positioning demo shows the servo lever rapidly
* moving to the left touch, then slowly moving to
* the right touch and so on ...
*
*/
void task_SERVO(void)
{static uint8_t pos;
if (getStopwatch1() > PULSE_REPETITION) { // Pulse every ~20ms
pulseSERVO(pos); // Servo pulse [1..2ms]
// ---------------------------------------------------------------------
// Your test code for positioning the servo here:
//if (getStopwatch2() > 48) { // Change position every ~50ms
//pos=pos+5; // Next position to the right
//if (pos > RIGHT_TOUCH) {pos = 0;} // pos: 0..RIGHT_TOUCH
//setStopwatch2(0);
//}
// ---------------------------------------------------------------------
setStopwatch1(0);
}
}
/*****************************************************************************/
// Main function - The program starts here:
int main(void)
{
initRobotBase(); // Always call this first! The Processor will not work
// correctly otherwise.
// ---------------------------------------
// Write messages to the Serial Interface:
writeString_P("\n\n _______________________\n");
writeString_P(" \\| RP6 ROBOT SYSTEM |/\n");
writeString_P(" \\_-_-_-_-_-_-_-_-_-_/\n\n");
writeString_P("################\n");
writeString_P("<<RP6 Base>>\n");
writeString_P(" Servo - Test 1 \n");
writeString_P(" Version 1.00 \n");
writeString_P("################\n\n");
mSleep(2500);
setLEDs(0b111111); // Turn all LEDs on
mSleep(500); // delay 500ms
setLEDs(0b000000); // All LEDs off
initSERVO();
startStopwatch2(); // Used for the demo task
while(true)
{
task_SERVO();
task_RP6System();
}
return 0;
}
/******************************************************************************
* Additional info
* ****************************************************************************
* Changelog:
* - v. 1.0 (initial release) 03.10.2007 by D. Ottensmeyer
*
* ****************************************************************************
*/
/*****************************************************************************/
dieses programm benutze ich, um die Servos anzusteuern.
es funktioniert sozusagen so wie eine art rasensprenger: zuerst fährt er langsam zu der einen seite und dann bewegt sich der servo ruckartig zu der anderen seite.
wie muss man es umänderen, dass der servo einfach bis zum anschlag der rechten seite fährt (also für den greifarm)
wenn ich dieses problem gelöst habe kann ich auch gerne ein video posten.
LG Marcel
Lesezeichen