View unanswered posts | View active topics It is currently Wed Dec 11, 2019 8:35 pm






Reply to topic  [ 3 posts ] 
EV3: stop sequence while it runs 
Author Message
Rookie

Joined: Fri Jun 26, 2015 7:40 am
Posts: 5
Post EV3: stop sequence while it runs
Hello,

I try to program a robot. The robot should follow a little controlled car. Therefore I wrote a sequence, in which the robot drives some detours. Everytime the US-Sensor gives a signal to EV3-brick, the sequence has to stop and repeat at the beginning (the robot can only watch in one direction, therefore the detours). Everytime the US-Sensor gives a defined value to EV3-brick, the sequence has to stop and start a catch-mechanism.


Maybe the code helps you to understand my problem

Code:
#pragma config(StandardModel, "EV3_REMBOT")

#define CURVE_LEFT false
#define CURVE_RIGHT true
#define CATCH_DISTANCE 10

bool bProgramRuns = true,
     bCarSearchTrigger = true;


int drive_curve(int iTime, int iKurvenschaerfe, bool bDirection) {

  if(bDirection) {

    setMotorSpeed(motorB, 100);
    setMotorSpeed(motorC, 100 - iKurvenschaerfe);

  } else {

    setMotorSpeed(motorB, 100 - iKurvenschaerfe);
    setMotorSpeed(motorC, 100);

  }

  sleep(iTime);

  return 0;

}


int schlenker_fahren() {

  drive_curve(1000, 10, CURVE_RIGHT);
  drive_curve(2000, 15, CURVE_LEFT);
  drive_curve(3000, 20, CURVE_RIGHT);

  return 0;

}


task main() {

  while(bProgramRuns) {

    if(bCarSearchTrigger) {

      schlenker_fahren();
      bCarSearchTrigger = false;

    } else {

      setMotorSpeed(motorB, 100);
      setMotorSpeed(motorC, -100);
      sleep(5000);

    }

  }

//  return 0;

}


I need to control the US-Sensor every moment while "schlenker_fahren()" (english translation is 'drive_detours') runs. Has anyone an idea?

EggiMaster


Wed Jul 01, 2015 4:35 am
Profile
Rookie

Joined: Fri Jun 26, 2015 7:40 am
Posts: 5
Post Re: EV3: stop sequence while it runs
Is it possible to use sensors, while the motors are running? The robot needs to correct the motorsettings, while the robot chases the controlled cars. The sensor-signals are the trigger. Or do I have to stop the motors first, check the sensor-signals, if necessary change the motor-settings and start the motors again? That seems to be insufficient to interact with a dynamic environment.

Edit: I found a thread ("Multitasking [sticky] - When and When Not to Multitask") in this forum for my problem. Thank you.


Fri Jul 03, 2015 5:24 am
Profile
Rookie

Joined: Wed Dec 03, 2014 5:57 pm
Posts: 22
Post Re: EV3: stop sequence while it runs
Hi,
If I understand your question correctly, here is a section of code that may help.
My robot is a line following robot. As it goes along the line, it is checking 2 sensors.
First the sonar sensor, to see if it should slow down or stop, and second, a light
sensor to see if it is still on the edge of the line.

Code:
task line_follower_pro()
{
    //  From ideas in the NXT-G program LineFollowPro, at http://www.nxtprograms.com/line_follower.
    //  I could not find the author's name.
    //  The following code will track the left side of a black line on a very
    //  light background.

    unsigned char closeness;
    unsigned char new_speed_subscript;

    short proximity_power_reduction;
    short proximity_gain_reduction;
    short pause_btw_words;
    short pause_btw_phrases;


    pause_btw_words = 100;
    pause_btw_phrases = 400;
    closeness = 80;
    new_speed_subscript = 4;


    while(TRUE)
    {
        if (do_line_follow == TRUE)
        {

            //  Check if we are closing on car ahead.
            closeness = SensorValue(SONAR_SENSOR);
            if (closeness < 10)
            {
                proximity_power_reduction = proximity_power_factor - closeness;
                proximity_gain_reduction = proximity_gain_factor - closeness;
            }
            else
            {
                proximity_power_reduction = 0;
                proximity_gain_reduction = 0;
            }

            //  Check on position relative to black line
            current_reflected_light_intensity = SensorValue(BW_SENSOR);
            wander = reflected_light_mid - current_reflected_light_intensity;
            deviation = wander * (bc_gain - proximity_gain_reduction);
            correction = deviation / reflected_light_range;
            b_power = bc_power - proximity_power_reduction + correction;
            c_power = bc_power - proximity_power_reduction - correction;
         setMotorSpeed(motorB, b_power);
         setMotorSpeed(motorC, c_power);

            //  Repeat check on position relative to black line, before checking
            //  again for any car ahead.
            current_reflected_light_intensity = SensorValue(BW_SENSOR);
            wander = reflected_light_mid - current_reflected_light_intensity;
            deviation = wander * (bc_gain - proximity_gain_reduction);
            correction = deviation / reflected_light_range;
            b_power = bc_power - proximity_power_reduction + correction;
            c_power = bc_power - proximity_power_reduction - correction;
         setMotorSpeed(motorB, b_power);
         setMotorSpeed(motorC, c_power);

            current_todo_queue_length = ((next_open_slot_idx +
              ROADWAY_TODO_QUEUE_LENGTH) -
              next_todo_idx ) % ROADWAY_TODO_QUEUE_LENGTH;
            if (current_todo_queue_length > 0)
            {
                do_line_follow = FALSE;
            }
        }

        else


I've attached a .zip file with the complete program, so you can check some details
if that might help. Unless your robot is traveling very fast, the EV3 has time to check
the sensors, and make any adjustments to the speed of the motors before the robot
has traveled 1/8 to 1/4 inch.

Howard


Attachments:
File comment: .zip file of code for line following
robot, that uses sonar sensor to
stop before hitting object.

CKLW_09B1_Test_Pad_EV.zip [12.49 KiB]
Downloaded 318 times
Wed Jul 08, 2015 8:37 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.