Skip to content
This repository has been archived by the owner on Apr 18, 2020. It is now read-only.

Create the block "GoToCruizCore(x,y)" #13

Open
jabrena opened this issue Oct 13, 2016 · 15 comments
Open

Create the block "GoToCruizCore(x,y)" #13

jabrena opened this issue Oct 13, 2016 · 15 comments
Assignees
Milestone

Comments

@jabrena
Copy link
Member

jabrena commented Oct 13, 2016

It is necessary to create a Block which it accept a final point as an Input Parameter. Internally, the block use current pose to calculate:

  • Angle to rotate
  • Distance to travel

The idea is to execute the following example:
http://www.lejos.org/rcx/tutorial/navigation/index.html

class Testbot {

   public static void main(String [] args) {
      Motor.A.setPower(7);
      Motor.C.setPower(5);

      TimingNavigator n = new TimingNavigator(Motor.C, Motor.A, 5.475f, 4.03f);
      n.rotate(360);
      n.gotoPoint(100,0);
      n.gotoPoint(100,100);
      n.gotoPoint(0,100);
      n.gotoPoint(0,0);
   }
}
@jabrena jabrena added this to the v0.2.0 milestone Oct 13, 2016
@jabrena jabrena self-assigned this Oct 13, 2016
@jabrena jabrena modified the milestones: v0.4.0, v0.2.0 Oct 14, 2016
@jabrena jabrena changed the title Create the block "GoTo(x,y)" Create the block "GoTo(x,y)CruizCore" Oct 15, 2016
@jabrena jabrena changed the title Create the block "GoTo(x,y)CruizCore" Create the block "GoToCruizCore(x,y)" Oct 15, 2016
jabrena added a commit that referenced this issue Oct 16, 2016
Adding Block to Update Point2
Adding Block to Get Point from Pose
Adding Private block to calculate distance/angle for GoTo
Adding Prototype for new Block GoTo
Adding Block to Show a Point
Solved the problem with Pose Array
#22
#21
#20
#19
#13
#15
#13
@jabrena
Copy link
Member Author

jabrena commented Oct 16, 2016

Comparing 2 ways to calculate the distance:

LeJOS RCX:
https://sourceforge.net/p/lejos/rcx/code/HEAD/tree/trunk/lejos/src/java/classes/josx/robotics/RotationNavigator.java

// Calculate distance to travel:
      float distance;
      if(y1 != 0)
         distance = y1/(float)Math.sin(angle);
      else
         distance = x1/(float)Math.cos(angle);

Atmel NanoVM
https://github.com/kosch/NanoVM/blob/master/nanovm-examples/src/main/java/ctbot/utils/NaviGoalRoughlyPos.java

float dist = Math.sqrt(dx*dx+dy*dy);

@jabrena
Copy link
Member Author

jabrena commented Oct 16, 2016

It is necessary to check some cases, example: atan2(50,0);
for cases when y = 0, the robot should not have to rotate 0.xxx it is a error based on Math accuracy using Math.Pi with 4 decimals and operations in general.
It is necessary to adjust for that case the algorithm.

jabrena added a commit that referenced this issue Oct 16, 2016
Adding a new Atan2 Block implementation based on the ideas from Volkan Salma
Adding a TestSuite to test the implementation in relation to MDN Reference for Math.atan2
#17
Adding a Block to convert Radians to Degrees
#25

[Core]
Finishing GoToCruizCoreXY. It is necessary to debug some Pose update from every Movement.
#13
@jabrena
Copy link
Member Author

jabrena commented Oct 16, 2016

Some notes about to calculate the distance:
http://robotics.stackexchange.com/questions/7928/robot-path-planning

destinationHeading = atan2((yt-yc), (xt-xc)); //calculate turning angle
destinationHeading = destinationHeading * 180/3.1415; //convert to degrees
turnAngle = destinationHeading - currentHeading;

if (turnAngle > 180) {
  turnAngle = turnAngle-360;
}

if (turnAngle < -180) {
  turnAngle = turnAngle+360;
}

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

https://github.com/Luncher/path-animation/blob/master/lib/soya_core.js
radian = Math.atan2(ny - target.y, nx - target.x);

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

https://github.com/DragicD/funlearner/blob/develop/literatura/Section%201%20-%20Classic%20Game%20Steps/6-rtsGame/rtsGame-step4/js/Unit.js
/* //// this approach would work, and finds the angle if we need it for image rotation
var deltaX = this.gotoX-this.x; ////
var deltaY = this.gotoY-this.y; ////
var moveAng = Math.atan2(deltaY, deltaX); ////
var moveX = UNIT_PIXELS_MOVE_RATE * Math.cos(moveAng); ////
var moveY = UNIT_PIXELS_MOVE_RATE * Math.sin(moveAng); ////
*/

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

http://www.gamefromscratch.com/post/2012/11/18/GameDev-math-recipes-Rotating-to-face-a-point.aspx

        var angle = Math.atan2(stage.mouseY - jetSprite.y, stage.mouseX - jetSprite.x );
        angle = angle * (180/Math.PI);
        // The following if statement is optional and converts our angle from being
        // -180 to +180 degrees to 0-360 degrees.  It is completely optional
        if(angle < 0)
        {
            angle = 360 - (-angle);
        }
        // Atan2 results have 0 degrees point down the positive X axis, while our image is pointed up.
        // Therefore we simply add 90 degrees to the rotation to orient our image
        // If 0 degrees is to the right on your image, you do not need to add 90
        rotation =90 + angle;

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

http://dev.bennage.com/blog/2013/03/05/game-dev-03/

function getAngle(x,y,orientation){
// alias (and pre-compute) the angle of 
// a full circle (360°, but in radians)
var fullCircle = Math.PI * 2;

// what's the different between our orientation
            // and the angle we want to face in order to 
            // move directly at our target
            var angle = Math.atan2(y, x);
            var delta = angle - orientation;
            var delta_abs = Math.abs(delta);

            // if the different is more than 180°, convert
            // the angle a corresponding negative value
            if (delta_abs > Math.PI) {
                delta = delta_abs - fullCircle;
            }

            // if the angle is already correct,
            // don't bother adjusting
            if (delta !== 0) {
                // do we turn left or right?
                var direction = delta / delta_abs;
                // update our orientation
                orientation += (direction * Math.min(delta_abs, delta_abs));
            }
            // constrain orientation to reasonable bounds
            orientation %= fullCircle;

return orientation;
}

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

var diffAngle:Number = Math.atan2(Math.sin(angleTo – currentAngle), Math.cos(angleTo – currentAngle));
var diffAngle:Number = Math.min(Math.abs(Math.abs(angleTo – currentAngle) – 2*Math.PI), Math.abs(angleTo – currentAngle))
http://blog.open-design.be/2009/06/02/find-the-shortest-rotation-angle-between-two-angles/

@jabrena
Copy link
Member Author

jabrena commented Oct 17, 2016

@jabrena jabrena modified the milestones: v0.5.0, v0.4.0 Nov 6, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant