View unanswered posts | View active topics It is currently Wed Oct 01, 2014 2:34 pm






Reply to topic  [ 8 posts ] 
How to run dual programs 
Author Message
Rookie

Joined: Wed Nov 30, 2011 10:46 pm
Posts: 4
Post How to run dual programs
Hi, I have been trying to run dual programs in one for the past forever. and was wondering if you guy's could help me figure out what's wrong with the coding.
Code:
#pragma config(Sensor, S1,     lightSensor,         sensorLightActive)
#pragma config(Motor,  motorA,          motor,         tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          motor,         tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

void followLine()
{
  while(SensorValue(lightSensor) < 45)
  {
    motor[motorB] = 100;
    motor[motorC] = 100;
  }

  {
  motor[motorB] = 0;
  motor[motorC] = 0;
  wait1Msec(3000);
  followLine();
  }
}

task main()
{
 
 {
   motor[motorA] = 100;
   motor[motorB] = 100;
   wait1Msec(1000);
 }
 
 {
   motor[motorA] = 20;
   motor[motorB] = 80;
   wait1Msec(1000);
 }
 
 {
  motor[motorA] = 50;
  motor[motorB] = 50;
  wait1Msec(1000);
 }
 
 {
  motor[motorA] = 10;
  motor[motorB] = 80;
  wait1Msec(1000);
 }
 
 {
  motor[motorA] = 100;
  motor[motorB] = 100;
  wait1Msec(2000);
 }
 
 {
  motor[motorA] = -100;
  motor[motorB] = -100;
  wait1Msec(1000);
 }
 
 {
  motor[motorA] = 0;
  motor[motorB] = 0;
 
 }
 

 
}


Wed Nov 30, 2011 10:49 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: How to run dual programs
What exactly do you want to do? What dual programs do you want to run? What happens as of now vs. what did you expect to happen? The more information that you provide, the more help that you'll be able to receive.

_________________
sudo rm -rf /


Wed Nov 30, 2011 11:01 pm
Profile
Rookie

Joined: Wed Nov 30, 2011 10:46 pm
Posts: 4
Post Re: How to run dual programs
I want it to run the code under the task main() first. Then i want it to start the code I have under void followLine()


Wed Nov 30, 2011 11:05 pm
Profile
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: How to run dual programs
The command for running a function is:
Code:
followline();
You just put the name and then the parameters(if any). It's that simple!!

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Wed Nov 30, 2011 11:10 pm
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: How to run dual programs
to run you function simply put the function call in the main task after your code. In your particular case though, your function will not work because it uses recursion, and ROBOTC does not support recursion as of now. However, I see no need for you to use recursion in this case. Just put a while(true) loop around the code that you want to execute.

_________________
sudo rm -rf /


Wed Nov 30, 2011 11:11 pm
Profile
Rookie

Joined: Wed Nov 30, 2011 10:46 pm
Posts: 4
Post Re: How to run dual programs
@Magicode, Can you give me and example of what you're saying? a Coding Example.


Wed Nov 30, 2011 11:15 pm
Profile
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: How to run dual programs
Like this:
Code:
#pragma config(Sensor, S1,     lightSensor,         sensorLightActive)
#pragma config(Motor,  motorA,          motor,         tmotorNormal, PIDControl, encoder)
#pragma config(Motor,  motorB,          motor,         tmotorNormal, PIDControl, encoder)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

void followLine()
{
  while(true){
  while(SensorValue(lightSensor) < 45)
  {
    motor[motorB] = 100;
    motor[motorC] = 100;
  }

  {
  motor[motorB] = 0;
  motor[motorC] = 0;
  wait1Msec(3000);
  }
}
}

task main()
{
 
{
   motor[motorA] = 100;
   motor[motorB] = 100;
   wait1Msec(1000);
}

{
   motor[motorA] = 20;
   motor[motorB] = 80;
   wait1Msec(1000);
}

{
  motor[motorA] = 50;
  motor[motorB] = 50;
  wait1Msec(1000);
}

{
  motor[motorA] = 10;
  motor[motorB] = 80;
  wait1Msec(1000);
}

{
  motor[motorA] = 100;
  motor[motorB] = 100;
  wait1Msec(2000);
}

{
  motor[motorA] = -100;
  motor[motorB] = -100;
  wait1Msec(1000);
}

{
  motor[motorA] = 0;
  motor[motorB] = 0;
 
}

followLine();
 
}


_________________
sudo rm -rf /


Wed Nov 30, 2011 11:18 pm
Profile
Rookie

Joined: Wed Nov 30, 2011 10:46 pm
Posts: 4
Post Re: How to run dual programs
Thank you. It works. I have to make some tweaks. but it's running just fine.


Wed Nov 30, 2011 11:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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.