View unanswered posts | View active topics It is currently Sat Jul 26, 2014 12:03 am






Reply to topic  [ 6 posts ] 
How to stop IR Seeking using Sonar 
Author Message
Rookie

Joined: Wed Dec 04, 2013 1:47 am
Posts: 3
Post How to stop IR Seeking using Sonar
I'm working on a simple IR program for the Block Party in which the bot drives up to to pendulum and stops, before depositing a block into the basket. I am new to IR Seeking. The seeking program I wrote works fine when finding the beacon, but when it stops at the beacon it turns back and forth continuously. I am aware that my program needs a stopping condition. How could I implement feature this using the Sonar sensor?

Thanks


Wed Dec 04, 2013 2:02 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: How to stop IR Seeking using Sonar
Are you using PID control? It sounds like it is oscillating. Please post your code so we can help you.


Wed Dec 04, 2013 2:16 am
Profile
Rookie

Joined: Wed Dec 04, 2013 1:47 am
Posts: 3
Post Re: How to stop IR Seeking using Sonar
Code:
#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Hubs,  S2, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S3,     IR,             sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     motorL,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorR,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     motorF,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S1_C2_2,     motorG,        tmotorTetrix, openLoop, reversed)
#pragma config(Motor,  mtr_S2_C1_1,     motorH,        tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C1_2,     motorI,        tmotorTetrix, openLoop)
#pragma config(Servo,  srvo_S2_C2_1,    servo1,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_2,    servo2,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_3,    servo3,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_4,    servo4,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_5,    servo5,               tServoNone)
#pragma config(Servo,  srvo_S2_C2_6,    servo6,               tServoNone)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  while(true)
  {
    if(SensorValue[IR] == 5)
    {
      motor[motorD] = 25;
      motor[motorE] = 25;
    }

    if(SensorValue[IR] > 5)
    {
      motor[motorD] = -20;
      motor[motorE] = 20;
    }

    if(SensorValue[IR] < 5)
    {
      motor[motorD] = 20;
      motor[motorE] = -20;
    }
  }
}


Wed Dec 04, 2013 6:32 pm
Profile
Professor
User avatar

Joined: Sat May 18, 2013 1:24 pm
Posts: 272
Location: Olympia, WA
Post Re: How to stop IR Seeking using Sonar
First of all, it would be a lot less confusing if you used `motorL` and `motorR` in your code. ;)

You need to add a sonar sensor to your #pragma configs, and then read the value of the sonar every iteration of your while loop. If the sonar value is less than some number, you can `break;` out of your loop and the program will continue executing whatever's left after your "while" loop. Alternatively, you could read the sonar value into a variable, and then put your condition into your while statement:
Code:
while (SensorValue[sonar]>k_distance)

In this case, the robot would keep doing whatever was inside the loop, until the sonar returns a value less than `k_distance`, at which point the program would execute whatever code is left after your "while" loop.

_________________
FTC Team 6424, the 'Oly Cow - Chief programmer.
FRC Team 4450, Olympia Robotics Federation (ORF).

and also quadrotors. Quadrotors!


Wed Dec 04, 2013 9:26 pm
Profile
Rookie

Joined: Wed Dec 04, 2013 1:47 am
Posts: 3
Post Re: How to stop IR Seeking using Sonar
Thanks! Ive got another question: Is there a way to get a more specific value from the IR Seeker than 5? When I run the program, the two beacon positions already show up in section 5, so the robot drives forward from the start and corrects itself when it is too late, stopping at a bad angle. Ideally I'd like the bot to stop in front of the beacon, but the sections are too wide. Is there a way to get a specific value more directly in front of the Seeker rather than the broad "5"?

Thanks!


Wed Dec 04, 2013 11:14 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: How to stop IR Seeking using Sonar
Please read this thread.
http://robotc.net/forums/viewtopic.php?f=52&t=2780


Thu Dec 05, 2013 3:36 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 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.