Robot Arm (the assignment)

×

Error message

Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in menu_set_active_trail() (line 2396 of /homepages/8/d424690692/htdocs/clickandbuilds/Drupal/Drupal7/includes/menu.inc).
There are many ways to get input using eseecode. The first and most simple is using the instruction input(). You can use input without any parameters, or with one of the following types: "char", "word", "number", "line". This types are self-explanatories. If you don't put any parameters the input instruction tries to guess if the next set of characters (before a white space) is either a word or a number. As an example you can check this code that reads two numbers and outputs the sum. The instruction to write numbers in the output section is output.
     
       var a
       var b
       a=input()
       b=input()
       output(a+b)
     
    

There is another way to get input from the user, and this is mainly through our set of window instructions. This instructions allow us to create buttons and input boxes to be able to "react" to the user commands. When you create a new window, a new tab will appear next to the debug tab. Try reading through this example and remember that in the instructions manual you have every eSeeCode term well defined and with more examples. As an important note, the instructions that need to be executed by the button have to go with quotation marks.

     
      windowUse('Test')
      windowTextCreate('Test', 'Title', 'This is a test ', 10, -40, 140)
      windowTextCreate('Test', 'Direction', 'Direction:', 10, -10, 50)
      windowButtonCreate('Test', 'decAngle', '+', 10, 10, "turnLeft(10)", 30, 20)
      windowButtonCreate('Test', 'incAngle', '-', 60, 10, "turnRight(10)", 30, 20)
     
    

Before starting to study the distance between a point and a line, we have to check on how to compute the distance between 2 points. To be able to do it we will use Pythagorean theorem.

In the following example we have created a function that, given the coordinates of the points (a,b) and (c,d), returns the value of the distance. To use something we just learned we will be reading the input from the I/O tab.

     
      function distance(a, b, c, d) {
	return getSquareRoot((c - a) * (c - a) + (d - b) * (d - b))
      }

      var a = input()
      var b = input()
      var c = input()
      var d = input()
      setColor('black')
      lineAt(a, b, c, d)
      setColor('blue')
      lineAt(a, b, a, d)
      lineAt(a, d, c, d)
      writeAt(Math.abs(c - a), (a + c) / 2, d - 15)
      writeAt(Math.abs(d - b), a + 15, (b + d) / 2)
      output(distance(a, b, c, d))

     
    

When considering the distance between a point and a segment of a line the algorithm complicates. We could compute this distance using mathematics and vectors. The idea would be to find the point in the line with shortest distance and then check if it lies inside our segment.

The technique we will use is based in simulation.

Imagine we have to find the distance between a point (130,80) and the segment between (0,0) and (200, 200).

What we will do is use the coordinate system in eSeeCode. As the segment has a 45 degree angle with the x-axis, we will turn this quantity and then move. At each step we will compute the distance between that point and the point (20,30). To get the coordinates of the point where the guide is we can use the instruction getX() and getY().

For this example we will output the minimum distance between the point and the segment.

     
       function distance(a, b, c, d) {
	   return getSquareRoot((c - a) * (c - a) + (d - b) * (d - b))
        }

        goTo(130, 80)
        arc(5)
        goToCenter()
        turnLeft(45)
        var dist = distance(0, 0, 130, 80)
        repeat (200) {
	     forward(1)
             if (dist < distance(getX(), getY(), 130, 80)) {
		dist = distance(getX(), getY(), 130, 80)
             }
        }
        output(dist)

     
    

In this project we have decided to simulate a robotic arm. This arm has two parts that can be moved by changing their angles. We have included an object that should put a restriction on the arm movement. Although you have the code for almost all the project, you have to complete it. Whenever you see a comment //Fill this , it means we took something out from that part. Try to think what needs to be written there and try it. Don't worry, you can execute the program as many times as you need.

Soon we will put the solution to this assignment! Stay tuned!