vielen dank Thorben, das von dir beschriebene ist eine andere funktion. Ich Suche ein entsprechendes pendant zu dem hier
Code:
void task_motionControl(void)
{
// Automatic motor overcurrent shutdown:
if(overcurrent_timer >= 50) { // every 5ms
overcurrent_timer = 0;
if(!overcurrent_timeout) {
if((adcMotorCurrentLeft > 770) || (adcMotorCurrentRight > 770)) {
overcurrent_errors++;
overcurrent_timeout = 10;
mleft_power = 0;
mright_power = 0;
left_i = 0;
right_i = 0;
motion_status.overcurrent = true;
return;
}
else
motion_status.overcurrent = false;
// Emergency shutdown if there are too many (default: 3) overcurrent
// events within ~20 seconds (100 * 200ms).
if(overcurrent_error_clear > 100) {
overcurrent_errors = 0;
overcurrent_error_clear = 0;
}
else if(overcurrent_errors > 2)
emergencyShutdown(OVERCURRENT);
}
// Detect if one of the encoders or motors does not work properly and stop
// all operations immediately if this is the case!
if((adcMotorCurrentLeft < 150) && (mleft_speed == 0)
&& (mleft_des_speed != 0) && (mleft_ptmp > 150))
emergencyShutdown(ENCODER_MALFUNCTION_LEFT);
if((adcMotorCurrentRight < 150) && (mright_speed == 0)
&& (mright_des_speed != 0) && (mright_ptmp > 150))
emergencyShutdown(ENCODER_MALFUNCTION_RIGHT);
}
// Motor Control
if(motor_control) { // Everytime after the speed has been measured. (default: 200ms)
if(!overcurrent_timeout) { // No overcurrent timeout? (default is to wait 2 seconds before new try)
if(overcurrent_errors) // Overcurrent errors?
overcurrent_error_clear++; // Yes, Timeout to clear all error events.
else
overcurrent_error_clear=0; // No, we set the timeout to zero.
// Move Distance left:
if(motion_status.move_R) {
if(mleft_dist >= preStop_R) { // Stop a bit before the desired distance for ..
mleft_des_speed = 0; // ... better accurancy.
left_i = 0;
mleft_power = 0;
motion_status.move_R = false;
}
else if(mleft_dist >= preDecelerate_R) { // Start to decelerate?
mleft_des_speed /= 2;
if(mleft_des_speed < 22) mleft_des_speed = 22;
}
}
// Move Distance right:
if(motion_status.move_L) {
if(mright_dist >= preStop_L) { // Stop a bit before the desired distance for ..
mright_des_speed = 0; // ... better accurancy.
right_i = 0;
mright_power = 0;
motion_status.move_L = false;
}
else if(mright_dist >= preDecelerate_L) { // Start to decelerate?
mright_des_speed /= 2;
if(mright_des_speed < 22) mright_des_speed = 22;
}
}
// ----------------------------------------
// The following settings are for users that want to tune the behaviour
// of the robot when changing direction --> make it faster or slower.
// Carefully read the comments!
// #define CHANGE_DIRECTION_SLOW // this is enabled by default when none of the other options is enabled.
#define CHANGE_DIRECTION_MEDIUM // Standard, keep it like this if you do not know what you are doing!
// Uncomment this if you want the Robot to change motor direction as fast as possible:
//#define CHANGE_DIRECTION_FAST
#ifdef CHANGE_DIRECTION_FAST
// Change direction -- FAST Version.
// This changes direction without any slowdown.
// Only use this mode if you need it as this will reduce
// lifetime of the motors and gears.
if(mleft_des_dir != mleft_dir || mright_des_dir != mright_dir) {
mright_ptmp = 0;
mleft_ptmp = 0;
mright_power=0;
mleft_power=0;
TCCR1A = 0;
setMotorDir(mleft_des_dir,mright_des_dir);
}
#else
#ifdef CHANGE_DIRECTION_MEDIUM
// Change direction -- Medium Version.
// This stops before changing the motor direction but is a bit faster
// than the original version.
if(mleft_des_dir != mleft_dir || mright_des_dir != mright_dir) {
if(mleft_des_speed || mright_des_speed) {
mleft_des_speed_tmp = mleft_des_speed; // store current speed
mright_des_speed_tmp = mright_des_speed;
mleft_des_speed = 0;
mright_des_speed = 0;
mright_power=0; // Soft PWM adjust to 0
mleft_power=0;
left_i = 0;
right_i = 0;
}
if(!TCCR1A) {
setMotorDir(mleft_des_dir,mright_des_dir);
mleft_des_speed = mleft_des_speed_tmp;
mright_des_speed = mright_des_speed_tmp;
left_i = mleft_des_speed / 2;
right_i = mright_des_speed / 2;
}
}
#else
// Change direction -- slow Version from the original library.
// Slowdown and stop before changing direction
// to improve gears and motors lifetime.
// This variant was the original Version, the current library has
// medium enabled by default.
if(mleft_des_dir != mleft_dir || mright_des_dir != mright_dir) {
if(mleft_des_speed || mright_des_speed) {
mleft_des_speed_tmp = mleft_des_speed; // store current speed
mright_des_speed_tmp = mright_des_speed;
mleft_des_speed = 0;
mright_des_speed = 0;
left_i /= 2;
right_i /= 2;
}
if(mright_speed <= 40 && mleft_speed <= 40) {
mright_power=0; // Soft PWM adjust to 0
mleft_power=0;
}
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;
}
}
#endif
#endif
// Left motor speed control:
int16_t error_left = mleft_des_speed - mleft_speed;
left_i = left_i + error_left;
if(left_i > MC_LEFT_IMAX) left_i = MC_LEFT_IMAX;
if(left_i < MC_LEFT_IMIN) left_i = MC_LEFT_IMIN;
if(mleft_speed == 0 && mleft_des_speed == 0)
left_i = 0;
mleft_power = left_i / 2;
if(mleft_power > 210) mleft_power = 210;
if(mleft_power < 0) mleft_power = 0;
// Right motor speed control:
int16_t error_right = mright_des_speed - mright_speed;
right_i = right_i + error_right;
if(right_i > MC_RIGHT_IMAX) right_i = MC_RIGHT_IMAX;
if(right_i < MC_RIGHT_IMIN) right_i = MC_RIGHT_IMIN;
if(mright_speed == 0 && mright_des_speed == 0)
right_i = 0;
mright_power = right_i / 2;
if(mright_power > 210) mright_power = 210;
if(mright_power < 0) mright_power = 0;
}
else
overcurrent_timeout--;
motor_control = false;
}
// Call event handlers if necessary:
if(motion_status_tmp != motion_status.byte)
{
motion_status_tmp = motion_status.byte;
MOTIONCONTROL_stateChangedHandler();
}
}
/**
* This function sets the desired speed value.
* The rest is done automatically. The speed is regulated to this speed value
* independent of Battery voltage, surface, weight of the robot and other things.
*
* You need to call task_motorSpeedControl(); frequently out of the main loop!
* otherwise this function will not work!
* Or use task_RP6System which includes this call.
*
* The function limits maximum speed to 200! This has been done because the maximum
* possible speed gets lower over time due to battery discharging (--> voltage drop).
* And the gears and motors will live longer if you don't stress them that much.
*
* Also 200 leaves a bit room to the maximum possible PWM value when you
* put additional load onto the Robot or drive up a ramp etc.
*
*/
was von der M32 aus aufgerufen werden kann.
Hat sich echt niemand mit den move/rotate und ähnlichen befehlen/funktionen und deren ausführung von der M32 aus beschäftigt?
Oder liegt das problem woanders?
Lesezeichen