View unanswered posts | View active topics It is currently Fri Aug 01, 2014 8:24 pm






Reply to topic  [ 12 posts ] 
RobotC and IR seeker help 
Author Message
Rookie

Joined: Tue Jan 28, 2014 11:06 pm
Posts: 8
Post RobotC and IR seeker help
I am in need of help with a presumably (and hopefully) very easy program. I am part of a FTC robotics team and am having trouble with an autonomous program. I wish to write a program that has the robot drive forward turn 90 degrees, drive forward, turn once again then continue forward and stop. However I also wish to have it searching for the IR blaster thing. Once it registers 5, it needs to pause the simple drive program and run another task, once that task is completed, it needs to resume the first task and continue driving. I know this seems complicated but anyone who knows he FTC block party competition will under stand what is happening.

Basically this program: http://www.youtube.com/watch?v=Z4Jx1ivGKIk


Tue Jan 28, 2014 11:21 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC and IR seeker help
How about this forum thread?
viewtopic.php?f=52&t=7590


Wed Jan 29, 2014 2:54 am
Profile
Rookie

Joined: Tue Jan 28, 2014 11:06 pm
Posts: 8
Post Re: RobotC and IR seeker help
Our program isn't that complicated. It just needs to drive then once the sensor equals 5, pause driving and run another task. Then once that task finishes jump back into the original one.


Thu Jan 30, 2014 4:03 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3170
Location: Rotterdam, The Netherlands
Post Re: RobotC and IR seeker help
How about you show us what you have so far and we'll help you along? Does that sound reasonable?

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jan 31, 2014 2:40 am
Profile WWW
Rookie

Joined: Tue Jan 28, 2014 11:06 pm
Posts: 8
Post Re: RobotC and IR seeker help
That sounds great, here's one of the programs we've been working with, although they're all pretty much the same, aside from experimentation with using the IR signal power outputs (5 zones) from the HiTechnic seeker as opposed to the directional outputs (9 zones) that we're using in this program.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Hubs,  S2, HTMotor,  none,     none,     none)
#pragma config(Sensor, S3,     IRSeeker,       sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     motorBackLeft, tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorBackRight, tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     MotorFrontLeft, tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_2,     MotorFrontRight, tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     MotorArm1,     tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     MotorArm2,     tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_1,     motorBucket1,  tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_2,     motorFlagSpinner,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    srvArmLocker,         tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C4_2,    srvAuto,              tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C4_3,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C4_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_5,    Srv1,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C4_6,    Srv2,                 tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "hitechnic-irseeker-v2.h"

int y;

task main()
{
   y = 1;
   servo[srvAuto] = 128;
   servo[Srv1] = 62;
   servo[Srv2] = 178;
   while(true){
      while(SensorValue(IRSeeker) != 5)
      {
         motor[MotorFrontLeft] = 10;
         motor[MotorFrontRight] = 10;
         motor[motorBackLeft] = 10;
         motor[motorBackRight] = 10;
      }
      if(SensorValue(IRSeeker) == 5)
      {
         y = 0;
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(10);
         motor[MotorArm1] = 20;
         motor[MotorArm2] = 20;
         wait1Msec(500);
         motor[MotorArm1] = 0;
         motor[MotorArm2] = 0;
         wait1Msec(10);
         servo[srvAuto] = 0;
         wait1Msec(1000);
         servo[srvAuto] = 254;
         wait1Msec(1000);
         servo[srvAuto] = 128;
         wait1Msec(100);
         motor[MotorFrontLeft] = 10;
         motor[MotorFrontRight] = 10;
         motor[motorBackLeft] = 10;
         motor[motorBackRight] = 10;
      }
      wait1Msec(10000);
      motor[MotorFrontLeft] = 0;
      motor[MotorFrontRight] = 0;
      motor[motorBackLeft] = 0;
      motor[motorBackRight] = 0;
   }
}


We were also wondering about being able to pause a task (that would be driving forward) and running another task within the program that triggers when certain conditions are met (i.e. the seeker value = 5), then resuming the original task afterwards. We're using NXT bricks, I don't know whether or not that makes a difference.


Fri Jan 31, 2014 10:45 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC and IR seeker help
Task is not necessary. You just need to arrange the code such that it can monitor the right thing at the right time. First, write down the high level pseudo-code step by step on how the robot should behave.
0. Walk forward to seek the IR beacon.
1. Stop and dump the block.
2. Walk forward for 10 seconds to get out of the way.
3. Done, stop everything.

Rearranging your code and adding a state machine would yield the following:
Code:
int step = 0;

while (true)
{
    switch (step)
    {
        case 0:
            // Step 0: Walk forward to seek IR beacon.
            if (SensorValue[IRSeeker] != 5)
            {
                //
                // Keep walking until we are aligned with the IR beacon.
                //
                motor[MotorFrontLeft] = 10;
                motor[MotorFrontRight] = 10;
                motor[motorBackLeft] = 10;
                motor[motorBackRight] = 10;
            }
            else
            {
                // Found IR beacon, move on to the next step.
                step++;
            }
            break;

        case 1:
            // Step 1: Stop and dump the block.

            // Stop walking.
            motor[MotorFrontLeft] = 0;
            motor[MotorFrontRight] = 0;
            motor[motorBackLeft] = 0;
            motor[motorBackRight] = 0;
            wait1Msec(10);

            // Dump the block.
            motor[MotorArm1] = 20;
            motor[MotorArm2] = 20;
            wait1Msec(500);
            motor[MotorArm1] = 0;
            motor[MotorArm2] = 0;
            wait1Msec(10);
            servo[srvAuto] = 0;
            wait1Msec(1000);
            servo[srvAuto] = 254;
            wait1Msec(1000);
            servo[srvAuto] = 128;
            wait1Msec(100);

            // Prepare and move on to the next step.
            ClearTimer(T1);
            step++;
            break;

        case 2:
            // Step 2: Walk forward for 10 seconds to get out of the way.
            if (time1[T1] < 10000)
            {
                motor[MotorFrontLeft] = 10;
                motor[MotorFrontRight] = 10;
                motor[motorBackLeft] = 10;
                motor[motorBackRight] = 10;
            }
            else
            {
                step++;
            }
            break;

        case 3:
            // Step 3: Done, stop everything.
            motor[MotorFrontLeft] = 0;
            motor[MotorFrontRight] = 0;
            motor[motorBackLeft] = 0;
            motor[motorBackRight] = 0;
            break;
    }

    wait1Msec(20);
}

For step 1 (dumping the block), we could break it down to more steps and using timer T1 instead of using wait1Msec(). Generally, we don't use any loops nor any wait1Msec statements in the state machine so the state machine can monitor multiple sensors/events if necessary. I will leave that for you as an exercise.


Fri Jan 31, 2014 3:18 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3170
Location: Rotterdam, The Netherlands
Post Re: RobotC and IR seeker help
You don't need to include my irseeker driver if you're using the built-in one :)

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Fri Jan 31, 2014 4:47 pm
Profile WWW
Rookie

Joined: Tue Jan 28, 2014 11:06 pm
Posts: 8
Post Re: RobotC and IR seeker help
Thanks, This seems to work better than what we had; however, I still have no idea how to make then all stop in the same position before the task completes. Here's what we have now and it only works because it very slowly pushes against the wall.

Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Hubs,  S2, HTMotor,  none,     none,     none)
#pragma config(Sensor, S3,     IRSeeker,       sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     motorBackLeft, tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorBackRight, tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     MotorFrontLeft, tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_2,     MotorFrontRight, tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     MotorArm1,     tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     MotorArm2,     tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_1,     motorBucket1,  tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_2,     motorFlagSpinner, tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    srvArmLocker,         tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C4_2,    srvAuto,              tServoContinuousRotation)
#pragma config(Servo,  srvo_S1_C4_3,    servo1,               tServoStandard)
#pragma config(Servo,  srvo_S1_C4_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S1_C4_5,    Srv1,                 tServoStandard)
#pragma config(Servo,  srvo_S1_C4_6,    Srv2,                 tServoStandard)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   int step = 0;

   while (true)
   {
      switch (step)
      {
      case 0:
         // Step 0: Walk forward to seek IR beacon.
         if (SensorValue[IRSeeker] != 5)
         {
            //
            // Keep walking until we are aligned with the IR beacon.
            //
            motor[MotorFrontLeft] = 10;
            motor[MotorFrontRight] = 10;
            motor[motorBackLeft] = 10;
            motor[motorBackRight] = 10;
         }
         else
         {
            // Found IR beacon, move on to the next step.
            step++;
         }
         break;

      case 1:
         // Step 1: Stop and dump the block.

         // Stop walking.
         motor[MotorFrontLeft] = 10;
         motor[MotorFrontRight] = 10;
         motor[motorBackLeft] = 10;
         motor[motorBackRight] = 10;
         wait1Msec(1350);
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(10);

         // Dump the block.
         motor[MotorArm1] = 20;
         motor[MotorArm2] = 20;
         wait1Msec(600);
         motor[MotorArm1] = 0;
         motor[MotorArm2] = 0;
         wait1Msec(10);
         servo[srvAuto] = 0;
         wait1Msec(1000);
         servo[srvAuto] = 254;
         wait1Msec(1000);
         servo[srvAuto] = 128;
         wait1Msec(100);

         // Prepare and move on to the next step.
         ClearTimer(T1);
         step++;
         break;

      case 2:
         // Step 2: Walk forward for 10 seconds to get out of the way.
         if (time1[T1] < 8300)
         {
            motor[MotorFrontLeft] = 10;
            motor[MotorFrontRight] = 10;
            motor[motorBackLeft] = 10;
            motor[motorBackRight] = 10;
         }
         else
         {
            step++;
         }
         break;

      case 3:
         // Step 3: Stop, then drive onto the ramp.
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(100);
         motor[MotorFrontLeft] = -60;
         motor[MotorFrontRight] = 60;
         motor[motorBackLeft] = -60;
         motor[motorBackRight] = 60;
         wait1Msec(200);
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(100);
         motor[MotorFrontLeft] = -60;
         motor[MotorFrontRight] = 60;
         motor[motorBackLeft] = -60;
         motor[motorBackRight] = 60;
         wait1Msec(1000);
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(100);
         motor[MotorFrontLeft] = 50;
         motor[MotorFrontRight] = 50;
         motor[motorBackLeft] = 50;
         motor[motorBackRight] = 50;
         wait1Msec(1700);
         motor[MotorFrontLeft] = -60;
         motor[MotorFrontRight] = 60;
         motor[motorBackLeft] = -60;
         motor[motorBackRight] = 60;
         wait1Msec(1000);
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(100);
         motor[MotorFrontLeft] = 50;
         motor[MotorFrontRight] = 50;
         motor[motorBackLeft] = 50;
         motor[motorBackRight] = 50;
         wait1Msec(2500);
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(100);
         step++;
         break;

         case 4: // End and clean up.
         motor[MotorFrontLeft] = 0;
         motor[MotorFrontRight] = 0;
         motor[motorBackLeft] = 0;
         motor[motorBackRight] = 0;
         wait1Msec(10);
         servo[srvAuto] = 254;
         wait1Msec(100);
         servo[srvAuto] = 128;
         StopTask(main);
      }
      wait1Msec(20);
   }
}


All I could think of using is a proximity sensor but it seems unnecessary. Is there a timer option that kills the task at a particular point every time.

Thanks


Thu Feb 06, 2014 4:06 pm
Profile
Novice
User avatar

Joined: Sat Aug 31, 2013 9:15 am
Posts: 98
Post Re: RobotC and IR seeker help
If I'm understanding you correctly, the problem you are having is that your robot will keep executing code when you want it to be done. Is that correct? To stop your program from executing the last step over and over again, you can put step++ at the end of it. Although, I'm still not sure why your motors would still be moving. It's your drive wheels that keep going, correct? :?:

_________________
Burning Lights Programming
FTC Team 6100 Chariots of Fire - Programmer (2012-2013)
FTC Team 7468 Blue Chariots of Fire - Programmer (2013-2014)
Check out our team website at http://cof7468.weebly.com/.


Thu Feb 06, 2014 7:15 pm
Profile
Rookie

Joined: Tue Jan 28, 2014 11:06 pm
Posts: 8
Post Re: RobotC and IR seeker help
What I'm trying to say is, after the IR sensor senses the beacon, it stops driving and runs the second set. The issue is there are four possible locations in a line for the basket (as you probably know), we need the robot to stop in the same place no matter where the beacon is located. The part of the code is in case 2. We need this to be different depending on where the beacon is located. I hope this makes sense.


Thu Feb 06, 2014 7:33 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: RobotC and IR seeker help
Again, the answer is in the thread:
viewtopic.php?f=52&t=7590

Instead of using time, you need to read the encoders to determine how far you have walked so far and how far you need to go further to clear the pendulum. If you don't have encoders on your wheels, then it is a little tougher. One way to do it is to use time to determine how long you have been walking to the IR beacon so you know how much longer you need to walk to clear the pendulum. But note that timed drive is very inaccurate and not very repeatable.


Thu Feb 06, 2014 8:41 pm
Profile
Rookie

Joined: Tue Jan 28, 2014 11:06 pm
Posts: 8
Post Re: RobotC and IR seeker help
Hi, thank you all a lot, our IR is now working almost entirely (just a few last tweaks are needed). We do, however, have one more minor problem. It doesn't actually affect functionality (usually) and probably belongs in a different forums, but maybe someone on this one has seen something like it before. When running a round with the Samantha Field Control System (Samo FCS), after the teleop period has concluded, our FCS always stops responding for about 20 seconds, then gives the message "Unrecoverable error attempting to open Matchlog.csv" within the program. After clicking the only option, "Okay," the FCS disconnects our robot, but we're able to reconnect and run another round easily. This is simply an annoyance, and if nobody has encountered something like this before, it doesn't really matter enough to deserve significant effort, but any help would be appreciated. We tried contacting the developer of the software, and they didn't get back to us. Thanks!


Fri Feb 07, 2014 5:22 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.