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