Hallo
kann man ein Motor vorwärts und eine rückwärts laufen lassen, aber mit bestimmter Geschwindigkeit. Also z.B. moveAtSpeed(80, -90) ??
mfG
Philip ;)
Druckbare Version
Hallo
kann man ein Motor vorwärts und eine rückwärts laufen lassen, aber mit bestimmter Geschwindigkeit. Also z.B. moveAtSpeed(80, -90) ??
mfG
Philip ;)
Hallo
So vielleicht:
(ungetestet, Basis der Funktionen aus der RP6-Library)Code:// Die Drehrichtungen werden in RP6RobotBaseLib.h definiert:
// Direction:
// #define FWD 0
// #define BWD 1
// #define LEFT 2
// #define RIGHT 3
// moveAtSpeed() mit Drehrichtungsangabe als dritter Parameter
void moveAtSpeed2(uint8_t desired_speed_left, uint8_t desired_speed_right, uint8_t dir)
{
moveAtSpeed(desired_speed_left, desired_speed_right);
changeDirection(dir);
}
// rotoate() mit zwei unterschiedlichen Geschwindigkeiten (mit Weganpassung der Seiten)
void rotate2(uint8_t desired_speed_left, uint8_t desired_speed_right, uint8_t dir, uint16_t angle, uint8_t blocking)
{
uint16_t distance, distance_left, distanceright;
motion_status.move_L = true;
motion_status.move_R = true;
distance = (uint16_t) (((uint32_t)(ROTATION_FACTOR) * (uint16_t)angle)/100);
distance += distance; // Gesamtweg verteilen
distance_left = distance * desired_speed_left / (desired_speed_left + desired_speed_right);
distance_right = distance - distance_left;
preDecelerate_L = distance_left - 100;
preDecelerate_R = distance_right - 100;
preStop_L = distance_left;
preStop_R = distance_right;
if(distance_left < 40) {
distance_left = 40;
preStop_L = 20;
preDecelerate_L = 10;
}
if(distance_right < 40) {
distance_right = 40;
preStop_R = 20;
preDecelerate_R = 10;
}
moveAtSpeed(desired_speed_left, desired_speed_right);
changeDirection(dir);
mleft_dist = 0;
mright_dist = 0;
distanceToMove_L = distance_left;
distanceToMove_R = distance_right;
motion_status_tmp = motion_status.byte;
MOTIONCONTROL_stateChangedHandler();
if(blocking)
while(!isMovementComplete())
task_RP6System();
}
Gruß
mic
hm.... der Compiler mekert das viele Variablen undeclared sind. Geht es auch so: moveAtSpeed3(speed_links, speed_rechts, dir_links, dir_rechts); ???
Hallo
uint16_t distance, distance_left, distanceright;
Hier fehlt der Unterstrich in distanceright.
Bringt moveAtSpeed3() einen Vorteil? Es gibt doch nur vier Kombinationen.
GrußCode:// Richtung: 0 = Vorwärts, 1 = Rückwärts
moveAtSpeed3(uint8_t desired_speed_left, uint8_t desired_speed_right, uint8_t dir_left, uint8_t dir_right)
{
moveAtSpeed(desired_speed_left, desired_speed_right);
setMotorDir(uint8_t dir_left, uint8_t dir_right); // Kommentar in der Lib beachten!
}
mic
das mit setMotorDir ist genau das was ich gesucht hab, aber:
undefined reference to `setMotorDir'
Möglicherweise wurde die Funktion rausgeschmissen:
Code:/**
* Sets the rotation direction of both motors.
*
* DO NOT CHANGE THE DIRECTION OF THE MOTORS WHILE THEY
* ARE RUNNING AT HIGH SPEEDS!!!
* It will not instantly damage the motors/gears, but they will
* wear out much faster if you do it at high speeds - better wait
* until speed has slowed down - and change direction AFTER this.
*
* -------------------------------------------------------------
* IT IS A BETTER IDEA NOT TO USE THIS FUNCTION AT ALL!
* Use moveAtSpeed together with task_motionControl instead.
* YOU CAN NOT USE setMotorPower AND setMotorDir WHEN YOU USE
* task_motionControl! This will not work!
* -------------------------------------------------------------
*
* task_motionControl also ensures that the direction is changed
* slowly and only after the motors have stopped!
*
* Example:
* // DO NOT perform these commands directly after each
* // other in your programs - this is just a LIST of possible
* // combinations:
* setMotorDir(FWD,FWD); // Move forwards
* setMotorDir(BWD,FWD); // Rotate right
* setMotorDir(FWD,BWD); // Rotate left
* setMotorDir(BWD,BWD); // Move backwards
*
*/
void setMotorDir(uint8_t left_dir, uint8_t right_dir)
{
mleft_dir = left_dir;
mright_dir = right_dir;
mleft_des_dir = left_dir;
mright_des_dir = right_dir;
if(left_dir)
PORTC |= DIR_L;
else
PORTC &= ~DIR_L;
if(right_dir)
PORTC |= DIR_R;
else
PORTC &= ~DIR_R;
}
Der Compiler meckert:
PC.c:24: error: 'DIR_R' undeclared (first use in this function)
PC.c:20: error: 'DIR_L' undeclared (first use in this function)
PC.c:18: error: 'mright_des_dir' undeclared (first use in this function)
PC.c:17: error: 'mleft_des_dir' undeclared (first use in this function)
PC.c:16: error: 'mright_dir' undeclared (first use in this function)
PC.c:15: error: 'mleft_dir' undeclared (first use in this function)
ich benutze die M32.
Irgendwie klemmt's heute extrem. Bindest du die Library ein?
#include "RP6RobotBaseLib.h"
In task_motionControl() wird bei Stillstand die Richtung ausgewählt:
Code:if(!TCCR1A) // Is the PWM module turned off?
{ // Yes, change direction and restore old speed:
setMotorDir(mleft_des_dir,mright_des_dir);
mleft_des_speed = mleft_des_speed_tmp;
mright_des_speed = mright_des_speed_tmp;
left_i = 0;
right_i = 0;
}
"ich benutze die M32." Aua
Ne, das klappt nicht. Ich hab's mal eingebaut, allerdings ungetestet und deshalb ohne Gewähr:
Dazu muss man allerdings einen neuen Befehl einbauen in RP6Base_I2CSlave.c, RP6Control_I2CMasterLib.c und RP6Control_I2CMasterLib.h und eine neue Hex-Datei für den RP6 erzeugen.Code:#include "RP6ControlLib.h"
//#include "RP6ControlServoLib.h"
#include "RP6uart.h"
#include "RP6I2CmasterTWI.h"
#include "RP6Control_I2CMasterLib.h"
void moveAtSpeed3(uint8_t desired_speed_left, uint8_t desired_speed_right, uint8_t dir_left, uint8_t dir_right)
{
moveAtSpeed(desired_speed_left, desired_speed_right);
setMotorDir(dir_left, dir_right); // neue Funktion
}
int main(void)
{
initRP6Control();
moveAtSpeed3(150,150,1,0);
while(1)
{
}
return 0;
}
Danke für deine bemühungen aber leider:
RP6Control_I2CMasterLib.c:347: error: 'CMD_SET_MOTOR_DIR' undeclared (first use in this function)
RP6Control_I2CMasterLib.c:347: error: (Each undeclared identifier is reported only once
RP6Control_I2CMasterLib.c:347: error: for each function it appears in.)
Zeile 347:
I2CTWI_transmit4Bytes(I2C_RP6_BASE_ADR, 0, CMD_SET_MOTOR_DIR, dir_left, dir_right );
Das Kommando 'CMD_SET_MOTOR_DIR' wird in der neuen Datei RP6Control_I2CMasterLib.h definiert. Das .txt muss man entfernen und vermutlich ein make all ausführen.
#define CMD_POWER_OFF 0
#define CMD_POWER_ON 1
#define CMD_CONFIG 2
#define CMD_SETLEDS 3
#define CMD_STOP 4
#define CMD_MOVE_AT_SPEED 5
#define CMD_CHANGE_DIR 6
#define CMD_MOVE 7
#define CMD_ROTATE 8
#define CMD_SET_ACS_POWER 9
#define CMD_SEND_RC5 10
#define CMD_SET_WDT 11
#define CMD_SET_WDT_RQ 12
#define CMD_SET_MOTOR_DIR 13 // mic 16.10.2011
#define ACS_PWR_OFF 0
#define ACS_PWR_LOW 1
#define ACS_PWR_MED 2
#define ACS_PWR_HIGH 3
Kompilierung erfolgreich beendet.
Aber das Programm startet nicht
FUNKTIONIERT !!!! mic du bist ein genie ;->
Du meinst jetzt aber nicht mein kleines Dummyprogramm oben? Das diente nur als Kompiliertest und hat keine echte Funktion.Zitat:
Aber das Programm startet nicht
Ich vermute mal, dass du auch ein eigenes m32-Programm hast in das du die neue Funktion einbauen kannst. Wie schon geschrieben must du auch die RP6-Slave-Datei austauschen, neu kompilieren und auf den RP6 laden.
Prima. :)
Es gibt auch changeDirection in der normalen Lib - die Richtung von einem Motor wechseln geht da einfach indem man
zwischen FWD und LEFT oder FWD und RIGHT oder ähnlich hin und her wechselt
(FWD und LEFT usw. sind ja nur leichter zu verstehende Namen dafür in welche Richtung sich die Motoren nun drehen sollen damit man direkt weiss in welche Richtung sich der ganze Roboter bewegen wird... ).
MfG,
SlyD