Hallo
Das ist nun wirklich totaler Schrott. Wir sollten uns mal wieder synchronisieren:
Ich:
Wie sieht denn dein aktuelles Programm aus? Ich könnte es mal mit meinem RP6 testen.
Du:
ich verwende das demoprogramm von Dirk aus diesem thread
Ich:
Suche ein Demoprogramm von Dirk in diesem Thread und finde das:
Code:
/*
* ****************************************************************************
* RP6 ROBOT SYSTEM - ROBOT BASE EXAMPLES
* ****************************************************************************
* Example: Simple Servo Example
* Author(s): D. Ottensmeyer
* ****************************************************************************
* Description:
* This example shows how to use a standard servo with RP6Library.
* There are much better solutions to do this job, but you may use
* this simple program to make some first experiments with servos.
* The servo is connected to PINC1 (SDA).
*
* ############################################################################
* The Robot does NOT move in this example! You can simply put it on a table
* next to your PC and you should connect it to the PC via the USB Interface!
* ############################################################################
* ****************************************************************************
*/
/*****************************************************************************/
// Includes:
#include "RP6RobotBaseLib.h" // The RP6 Robot Base Library.
// Always needs to be included!
/*****************************************************************************/
// Defines:
// RP6 Base Servo Connection:
#define SERVO_OUT SDA // PINC1 XBUS Pin 12
// Servo movement limits (depending on servo type):
#define LEFT_TOUCH 550 // Left servo touch
#define RIGHT_TOUCH 254 // Right servo touch [max. 255]
#define PULSE_ADJUST 4
#define PULSE_REPETITION 19 // Pulse repetition frequency
/*****************************************************************************/
// 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++; // 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
*
* ****************************************************************************
*/
/*****************************************************************************/
(Fundstelle in diesem Thread: https://www.roboternetz.de/phpBB2/vi...=318650#318650)
Dieses Demo habe ich dann ausprobiert, die Werte an mein Servo angepasst, nach möglichen Fehlern gesucht (wobei Dirk es ja drauf hat und weiß, wie man gut programmiert) und schließlich die entscheidenden Programmteile nochmals kommentiert.
Bin jetzt Schneeschippen.
Gruß
mic
Lesezeichen