Author |
Message |
Tabias Pittman
Rookie
Joined: Wed Nov 30, 2011 10:46 pm Posts: 4
|
 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 |
|
 |
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 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 |
|
 |
Tabias Pittman
Rookie
Joined: Wed Nov 30, 2011 10:46 pm Posts: 4
|
 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 |
|
 |
NeXT-Generation
Senior Roboticist
Joined: Wed Sep 28, 2011 10:13 pm Posts: 630 Location: If I told you, I'd have to kill you.
|
 Re: How to run dual programs
The command for running a function is: 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 |
|
 |
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 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 |
|
 |
Tabias Pittman
Rookie
Joined: Wed Nov 30, 2011 10:46 pm Posts: 4
|
 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 |
|
 |
magicode
Moderator
Joined: Tue Sep 14, 2010 9:19 pm Posts: 496
|
 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 |
|
 |
Tabias Pittman
Rookie
Joined: Wed Nov 30, 2011 10:46 pm Posts: 4
|
 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 |
|
|