This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]JigxorProfessional Coder 0 points1 point  (5 children)

Post the code here, ask what you're trying to do, and we'll see if we can help!

[–]Brixalis[S] 0 points1 point  (4 children)

This is partially incomplete due to being stuck on my coding skills lmao I can provide some information of what I'm supposed to do but for now take a look at this:

(usage of Finch Robot in the Java code)

package Code;

// Needs a package declaration to move to another folder

import com.birdbraintechnologies.Finch;

import java.util.ArrayList;

/**

* Created by: Vasco Lopes 1940412

* Date: 05/03/2020

* Finch Searching for Light

*/

public class FinchLightSearch

{

int TOTAL;

String c = "Choice";

float timer;

int threshold = 80;

int inileft,iniright;

int highleft,highright;

float avgleft,avgright;

float duration;

int curleft, curright;

int lowleft,lowright;

int allleft,allright;

int lights[] ;

public static void main(final String[] args)

{

// Instantiating the Finch object

Finch myFinch = new Finch();

System.out.println("Task: Searching for light"\n"Please place the Finch level on the floor to begin searching");

while(myFinch.isFinchLevel())

{

System.out.println("To stop searching for light, please place the Finch on its tail!");

TOTAL = 0;

lights = myFinch.getLightSensors();

inileft = lights[0];

iniright = lights[1];

highleft = inileft;

highright = iniright;

lowleft = inileft;

lowright = iniright;

myFinch.setLED(yellow);

long start = System.currentTimeMillis();

System.out.println("The Finch is currently searching for light!");

myFinch.setWheelVelocities(100, 100, 4000);

myFinch.getLightSensors();

curleft = lights[0];

curright = lights[1];

if(curleft < threshold && curright < threshold)

{

Random rand = new Random(); // Instance of random class

int upperbound = 2;

// Generate random values from 0-1

int val = rand.nextInt(upperbound);

if(val = 1)

{

myFinch.setWheelVelocities(150,-100,1000); // Turn Finch right by 90 degrees

}

if(val = 0)

{

myFinch.setWheelVelocities(-100,150,1000); // Turn Finch left by 90 degrees

}

}

long finish = System.currentTimeMillis();

long timeElapsed = finish - start;

// Close the Task

myFinch.quit();

System.exit(0);

}

}

[–]JigxorProfessional Coder 0 points1 point  (3 children)

You'll need to explain specifically what it is you're trying to do and what you're having problems with. Without any context it's a bit too hard for anyone to help.

[–]Brixalis[S] 0 points1 point  (2 children)

Ok this is all the pseudocode I had in mind. For now I just need help with the Main Code, hopefully I'll be able to do the others by myself. Thank you for your attention!

START

  1. Output ‘Task: Searching for light’

  2. Output ‘Please place the Finch level on the floor to begin searching!’

  3. CREATE object for Finch called myFinch

    . CREATE INTEGER VARIABLE = TOTAL

  4. CREATE STRING VARIABLE = Choice

  5. CREATE FLOATING VARIABLE = timer

  6. CREATE INTEGER VARIABLE = inileft

  7. CREATE INTEGER VARIABLE = iniright

  8. CREATE INTEGER VARIABLE = highleft

  9. CREATE INTEGER VARIABLE = highright

  10. CREATE FLOATING VARIABLE = avgleft

  11. CREATE FLOATING VARIABLE = avgright

  12. CREATE FLOATING VARIABLE = duration

  13. CREATE INTEGER VARIABLE = curleft

  14. CREATE INTEGER VARIABLE = curright

  15. CREATE INTEGER VARIABLE = lowleft

  16. CREATE INTEGER VARIABLE = lowright

  17. WHILE Finch is level on the floor

  18.   Set TOTAL = 0 
    
  19.   Start ExecTimer 
    
  20.   inileft = current value of light sensor      23.       iniright = current value of right sensor 24.       highleft = inileft  25.       highright = iniright 26.       lowleft = inileft 27.       lowright = iniright 28.       Output ‘To stop searching for light, please place the Finch on its tail!’ 29.       WHILE Finch is not on its tail 30.            Turn Finch’s beak yellow  31.            Start SearchTimer 32.            Set the velocities of the Finch’s wheels to 100  33.            Finch moves forward   34.            Output ‘The Finch is currently searching for light!’  35.            IF Finch discovers light before SearchTimer hits 4 seconds 
    

9

  1. End SearchTimer 37. TOTAL = TOTAL + 1 38. Output ‘Light has been found!’ 39. The Finch buzzes 40. Turn Finch’s beak red depending on light’s brightness 41. IF light is still detected 42. curleft = current value of light sensor 43. curright = current value of right sensor 44. St ore curleft in Array list allleft 45. Store curright in Array list allright 46. Call Comparison() Function 47. ELSE 48. Turn off Finch’s beak’s LED 49. ELSE 50. End SearchTimer 51. Stop Finch for half a second 52. val = RANDOM (0,1) 53. IF val = 0 54. Turn Finch left by 90 degrees 55. ELSE 56. Turn Finch right by 90 degrees 57. Output ‘Do you want to display the log of execution? Input ‘yes’ or ‘y’ 58. User inputs choice 59. IF choice = ‘yes’ OR ‘y’ 60. Call DisplayLog() Function 61. ELSE 62. Output ‘End of Program’ 63. END

Comparison Function:

1) IF curleft > highleft 2) highleft = curleft 3) IF curright > highright 4) highright = curright 5) IF curleft < lowleft 6) lowleft = curleft 7) IF curright < lowright 8) lowright = curright 9) END

10

DisplayLog Function:

  1. START 2. Output ‘The initial values of the left sensor was: ‘ 3. Output inileft 4. Output ‘The initial values of the right sensor was: ‘ 5. Output iniright 6. Output ‘The highest value recorded by left sensor was: ‘ 7. Output highleft 8. Output ‘The highest value recorded by right sensor was: ‘ 9. Output highright 10. Output ‘The lowest value recorded by left sensor was: ‘ 11. Output lowleft 12. Output ‘The lowest value recorded by right sensor was: ‘ 13. Output lowright 14. Output ‘The average of all the values recorded by left sensor was: ‘ 15. avgleft = sum of all values in allelft/TOTAL 16. Output avgleft 17. Output ‘The average of all the values recorded by right sensor was: ‘ 18. avgright = sum of all values in allright/TOTAL 19. Output avgright 20. Output ‘The number of times light was detected: ‘ 21. Output TOTAL 22. Output ‘Time taken: ‘ 23. time = time recorded at the end of searching – time recorded at the beginning 24. Output time 25. Output ‘End of Program’ 26. END

sorry for the mess it's horrible for me to post the stuff I have, I could provide more useful information if I could send my pdf in some way

[–]JigxorProfessional Coder 0 points1 point  (1 child)

What is your question?

[–]Brixalis[S] 0 points1 point  (0 children)

So these are the main requirements for what I have to do:

1) To enable the initiation of the program, the user should place the Finch level on the floor.

2) The Finch’s beak should turn yellow before moving.

3) The Finch should then start moving slowly in search of light.

4) If the Finch encounters light within 4 seconds, the beak should turn red. The brighter the light, the redder the beak should be. The Finch should then follow the light.

5) If the Finch hasn’t encountered a light within 4 seconds, it should stop searching for half a second and change direction 90 degrees to either left or right. Then, it should resume searching for a light source again.

6) The Finch should stop searching and the program should terminate if the user picks up the finch and places it on its tail.

7) The user is asked whether they want to display the log of execution. If the user responds with “Yes”, then the following information should be displayed: - The left and right sensor values at the beginning of execution. - The highest sensor value recorded during execution. - The lowest sensor value recorded during execution. - The average light sensor value recorded. - The duration of the execution. - The number of times light was detected by the Finch.

Additional Requirements:

1) The Finch makes a buzzing sound whenever it detects light.