Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma config(StandardModel, "EV3_REMBOT")
- //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
- /*
- This program takes advantage of the multitasking features of RobotC.
- A task is very similar to a function except for that it will run in parallel with the other code
- I will be checking my emails semi-frequently during the IPT period so reply with any issues your having
- */
- /*
- Setting up variables, sonar and time will be removed later
- food is 1000 so I can test other stuff without running out.
- All global variables must be declared here
- */
- int food = 1000;
- int sonar = getUSDistance(S4);
- int time;
- /* This task is to setup the 1 sec timer to reduce food by 1
- AFAIK this shouldn't need changes */
- task timer()
- {
- while(true)
- {
- wait1Msec(1000);
- food = food - 1;
- if (food < 1)
- {
- stopAllTasks();
- }
- }
- }
- /* Checks if it is touching Alien */
- task touch()
- {
- while(true)
- {
- if (getTouchValue(S1) == 1)
- {
- food = food + 10
- /* Play sound here. Idk how to do it so ask someone */
- }
- }
- }
- /* Reads colours on the ground. */
- task colour()
- {
- while(true)
- {
- /*
- Change this to something that measures reflected light instead of colour names
- something like getColorHue(nDeviceIndex)
- Also change the turnLeft to about 180 degrees.
- */
- /*
- if (getColorName(S3) == 'Black')
- {
- turnLeft(1, rotations, 50);
- }
- if (getColorName(S3) == 'White')
- {
- food = food + 5
- }
- */
- }
- }
- /* Main task */
- task main()
- {
- startTask(timer);
- startTask(touch);
- /*
- startTask(colour);
- Uncomment this when you have fixed up colour
- */
- while(true)
- {
- /* This is where stuff gets kinda weird, could probably be heavily optimised/changed */
- /* In the testing software the Sonar would output 250 whenever it couldn't find anything
- You may need to adjust this if that is not the case on the real robot */
- if (getUSDistance(S4) == 250)
- {
- /* Starts timer to ensure it doesn't endlessly spin searching */
- clearTimer(T1);
- while(getUSDistance(S4) == 250)
- {
- /* Var is for debug, can be removed safely */
- time = time1[T1];
- /* Checks if it has been two seconds, if it has the robot will aimlessly drive in an attempt to get food */
- if (time1[T1] > 2000)
- {
- clearTimer(T1);
- motor(motorB) = 50;
- motor(motorC) = 50;
- wait1Msec(1000);
- motor(motorB) = 0;
- motor(motorC) = 0;
- }
- motor(motorB) = 100;
- }
- /* This will only run once the robot has found something, drives forward */
- motor(motorB) = 50;
- motor(motorC) = 50;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement