also,
das ist "mein" programm (move_bsp9_control.c)
Code:
// Includes:
#include "RP6ControlLib.h" // The RP6 Control Library.
// Always needs to be included!
//#include "servo.h"
#include "RP6I2CmasterTWI.h" // I2C Master Library
/*****************************************************************************/
/*****************************************************************************/
// Include our new "RP6 Control I2C Master library":
#include "RP6Control_I2CMasterLib.h"
/*****************************************************************************/
//uint8_t c; //char für servosteuerung
/**
* Timed Watchdog display only - the other heartbeat function
* does not work in this example as we use blocked moving functions here.
*/
void watchDogRequest(void)
{
static uint8_t heartbeat2 = false;
if(heartbeat2)
{
clearPosLCD(0, 14, 1);
heartbeat2 = false;
}
else
{
setCursorPosLCD(0, 14);
writeStringLCD_P("#");
heartbeat2 = true;
}
}
/*****************************************************************************/
// I2C Requests:
/**
* The I2C_requestedDataReady Event Handler
*/
void I2C_requestedDataReady(uint8_t dataRequestID)
{
checkRP6Status(dataRequestID);
}
/*****************************************************************************/
// I2C Error handler
/**
* This function gets called automatically if there was an I2C Error like
* the slave sent a "not acknowledge" (NACK, error codes e.g. 0x20 or 0x30).
*/
void I2C_transmissionError(uint8_t errorState)
{
writeString_P("\nI2C ERROR - TWI STATE: 0x");
writeInteger(errorState, HEX);
writeChar('\n');
}
/*****************************************************************************/
// Main function - The program starts here:
int main(void)
{
initRP6Control();
initLCD();
writeString_P("\n\nRP6 CONTROL M32 I2C Master Example Program!\n");
writeString_P("\nMoving...\n");
// ---------------------------------------
WDT_setRequestHandler(watchDogRequest);
// ---------------------------------------
// Init TWI Interface:
I2CTWI_initMaster(100);
I2CTWI_setRequestedDataReadyHandler(I2C_requestedDataReady);
I2CTWI_setTransmissionErrorHandler(I2C_transmissionError);
sound(180,80,25);
sound(220,80,25);
setLEDs(0b1111);
showScreenLCD("################", "################");
mSleep(500);
showScreenLCD("I2C-Master", "Movement...");
mSleep(1000);
setLEDs(0b0000);
// ---------------------------------------
I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_ACS_POWER, ACS_PWR_MED);
I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_WDT, true);
I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_WDT_RQ, true);
while(true)
{
setLEDs(0b1001);
showScreenLCD("MOVE", "FWD");
move(60, FWD, DIST_MM(300), BLOCKING);
servo_I_left();
/* uint8_t c=0; //char für servosteuerung
for(c=0; c<50; c++)
{
PORTC |= IO_PC7; // Impulsstart servo I
sleep(5); // 1 = 0.1ms warten = Servoposition 1
PORTC &= ~IO_PC7; // Impulsende
sleep(150); //50ms warten
}
*/
setLEDs(0b1000);
showScreenLCD("ROTATE", "LEFT");
rotate(50, LEFT, 180, BLOCKING);
servo_I_right();
/* uint8_t c; //char für servosteuerung
for(c=0; c<50; c++)
{
PORTC |= IO_PC7; // Impulsstart servo I
sleep(25); // 1 = 0.1ms warten = Servoposition 1
PORTC &= ~IO_PC7; // Impulsende
sleep(150); //50ms warten
}
*/
setLEDs(0b1001);
showScreenLCD("MOVE", "FWD");
move(60, FWD, DIST_MM(300), BLOCKING);
servo_I_zero();
/* uint8_t c; //char für servosteuerung
for(c=0; c<50; c++)
{
PORTC |= IO_PC7; // Impulsstart servo I
sleep(15); // 1 = 0.1ms warten = Servoposition 1
PORTC &= ~IO_PC7; // Impulsende
sleep(150); //50ms warten
}
*/
setLEDs(0b0001);
showScreenLCD("ROTATE", "RIGHT");
rotate(50, RIGHT, 180, BLOCKING);
}
return 0;
}
hier die servo.c:
Code:
// Includes:
#include "servo.h" // servosteuerung
#include "RP6Control.h" // General RP6 Robot Base definitions
#include "RP6uart.h" // RP6 UART function lib
#include "RP6Config.h" // Configuration for RP6BaseLibrary - Constants for
// speed and distance calculation etc.
#include <avr/sleep.h> // Power saving functions
#include <util/delay.h> // Some delay loops
#include "RP6ControlLib.h" // The RP6 Control Library.
// Always needs to be included!
#include "RP6I2CmasterTWI.h" // I2C Master Library
#include "RP6Control_I2CMasterLib.h"
/*****************************************************************************/
/*********************servo I links*****************************/
void servo_I_left(void) // servo I auf den linken anschlag
{
// DDRC |= IO_PC7;
// PORTC &= ~IO_PC7;
uint8_t c=0; //char für servosteuerung
for(c=0; c<50; c++)
{
PORTC |= IO_PC7; // Impulsstart servo I
sleep(5); // 1 = 0.1ms warten = Servoposition 1
PORTC &= ~IO_PC7; // Impulsende
sleep(150); //50ms warten
}
}
/********************servo I mitte******************************/
void servo_I_zero(void) // servo I auf die mitte
{
// DDRC |= IO_PC7;
// PORTC &= ~IO_PC7;
uint8_t c; //char für servosteuerung
for(c=0; c<50; c++)
{
PORTC |= IO_PC7; // Impulsstart servo I
sleep(15); // 1 = 0.1ms warten = Servoposition 1
PORTC &= ~IO_PC7; // Impulsende
sleep(150); //50ms warten
}
}
/*********************servo I rechts****************************/
void servo_I_right(void) // servo I auf den rechten anschlag
{
uint8_t c; //char für servosteuerung
for(c=0; c<50; c++)
{
PORTC |= IO_PC7; // Impulsstart servo I
sleep(25); // 1 = 0.1ms warten = Servoposition 1
PORTC &= ~IO_PC7; // Impulsende
sleep(150); //50ms warten
}
}
/*********************servo II links****************************/
void servo_II_left(void) // servo II auf den linken anschlag
{}
/*********************servo II mitte****************************/
void servo_II_zero(void) // servo auf die mitte
{}
/*********************servo II rechts***************************/
void servo_II_right(void) // servo III auf den rechten anschlag
{}
/*********************servo III links***************************/
void servo_III_left(void) // servo III auf den linken anschlag
{}
/*********************servo III mitte***************************/
void servo_III_zero(void) // servo III auf die mitte
{}
/*********************servo III rechts**************************/
void servo_III_right(void) // servo III auf den rechten anschlag
{}
und hier die servo.h:
Code:
#ifndef SERVO_H_
#define SERVO_H_
/*****************************************************************************/
// Includes:
#include "RP6Control.h" // General RP6 Robot Base definitions
#include "RP6uart.h" // RP6 UART function lib
#include "RP6Config.h" // Configuration for RP6BaseLibrary - Constants for
// speed and distance calculation etc.
#include <avr/sleep.h> // Power saving functions
#include <util/delay.h> // Some delay loops
/*****************************************************************************/
/*********************servo I links*****************************/
void servo_I_left(void); // servo I auf den linken anschlag
/********************servo I mitte******************************/
void servo_I_zero(void); // servo I auf die mitte
/*********************servo I rechts****************************/
void servo_I_right(void); // servo I auf den rechten anschlag
/*********************servo II links****************************/
void servo_II_left(void); // servo II auf den linken anschlag
/*********************servo II mitte****************************/
void servo_II_zero(void); // servo auf die mitte
/*********************servo II rechts***************************/
void servo_II_right(void); // servo III auf den rechten anschlag
/*********************servo III links***************************/
void servo_III_left(void); // servo III auf den linken anschlag
/*********************servo III mitte***************************/
void servo_III_zero(void); // servo III auf die mitte
/*********************servo III rechts**************************/
void servo_III_right(void); // servo III auf den rechten anschlag
/***************************************************************/
#endif
Lesezeichen