Is there a way to get the distance and the direction of the nearest detected obstacle?
I have tried with this "Navigation/AvoidanceNavigator/ObstacleDetected" event, but it never triggers event if I position the robot next to the wall and tell him to go 5 meters long in the wall direction.
There's no API for the "nearest obstacle, but the ALMotion/MoveFailed event may be what you want - it will tell you where the obstacle is and why it failed.
During navigation you can use the ObstacleDetected event to notify you of obstacles. The position i given in robotframe.
You will get the x,y coordinates so you will have to calculate distance yourself.
Related
i need help in understanding rotation values in webots. How do I calculate and set them?
I want my robot to rotate in direction of the certain object.
For example, if the ball is rolling around the robot, the robot tries to get the position of the ball and rotate to it, so that the robot is always facing the ball.
Does anybody have an idea how can I do it?
My thoughts on coding it:
Get position of the ball
Get position of the robot
Calculate the angle between them
Rotate the robot by calculated angle
Thanks in advance!
You don't have to calculate the angle, it is enough to find the position of the ball in a 2D image plane. If the ball is left from the image center the robot should rotate left and if the ball is right from the image center the robot should rotate right.
You can find an example here:
https://github.com/lukicdarkoo/webots-example-visual-tracking
and you can see the result here:
https://lukicdarkoo.github.io/webots-example-visual-tracking/
I'm working on an exercise at the Exercism website, and I'm a little stuck on how to begin this one. I don't want any detailed answers; I'm just looking for a push in the right direction for how to begin. When given a set of (x, y) coordinates, I'd like to know if there is any particular Python module, function, etc. that can help me figure out where that point falls on a grid, especially in relation to a circle on the grid with center (0, 0).
I hope that was a bit more specific for what I'm looking for! I'm not having any particular problem writing the program (yet!), but I don't know how to even begin because I'm not sure if I need to write a function from scratch that will figure out all of the above, or if Python already has something that can help with this particular task.
Thanks!
Write a function that returns the earned points in a single toss of a Darts game.
Darts is a game where players throw darts to a target.
In our particular instance of the game, the target rewards with 4 different amounts of points, depending on where the dart lands:
If the dart lands outside the target, player earns no points (0 points).
If the dart lands in the outer circle of the target, player earns 1 point.
If the dart lands in the middle circle of the target, player earns 5 points.
If the dart lands in the inner circle of the target, player earns 10 points.
The outer circle has a radius of 10 units (This is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1. Of course, they are all centered to the same point (That is, the circles are concentric) defined by the coordinates (0, 0).
Write a function that given a point in the target (defined by its real cartesian coordinates x and y), returns the correct amount earned by a dart landing in that point.
One way to approach this is to use the Pythagorean theorem to compute the distance between the dart and the center.
r = math.sqrt(x*x+y*y)
This will give you the distance between the dart and the center of the target.
I'm making a game with Pygame, and now I stuck on how to process collision between player and wall. This is 2D RPG with cells, where some of them are walls. You look on world from top, like in Pacman.
So, I know that i can get list of collisions by pygame.spritecollide() and it will return me list of objects that player collides. I can get "collide rectangle" by player.rect.clip(wall.rect), but how I can get player back from the wall?
So, I had many ideas. The first was push player back in opposite direction, but if player goes, as example, both right and bottom directions and collide with vertical wall right of itself, player stucks, because it is needed to push only left, but not up.
The second idea was implement diagonally moving like one left and one bottom. But in this way we don't now, how move first: left or bottom, and order becomes the most important factor.
So, I don't know what algorithm I should use.
If you know the location of the centre of the cell and the location of the player you can calculate the x distance and the y distance from the wall at that point in time. Would it be possible at that point to take the absolute value of each distance and then take the largest value as the direction to push the player in.
e.g. The player collides with the right of the wall so the distance from the centre of the wall in the y direction should be less than the distance in x.
Therefore you know that the player collided with the left or the right of the wall and not the top, this means the push should be to the right or the left.
If the player's movement is stored as in the form [x, y] then knowing whether to push left or right isn't important since flipping the direction of movement in the x axis gives the correct result.
The push should therefore be in the x direction in this example
e.g. player.vel_x = -player.vel_x.
This would leave the movement in the y axis unchanged so hopefully wouldn't result in the problem you mentioned.
Does that help?
I am thinking about the simplest way of rotating an object in coordination system which looks like this:
0
-90 90
-180/180
I need to rotate an object until it reaches a given angle. It has to support rotation in both directions. I receive information about the object's current rotation. I have to create a while loop condition when it should stop rotating. It cannot be simple equality statement as the information I receive is not that precise.
EDIT:
The object is a drone which sends me data about its current rotation along z-axis. I rotate it by sending a request to rotate in a given direction. Based on information about its current rotation and the angle by which I want him to rotate (plus the direction of rotation), I need to set up a condition when it should stop rotating and send an apropriate requst.
Theoretically, you would need to have another variable that took the direction of rotation (clockwise or anti-clockwise). If the direction was clockwise, you would have angles assigned 0, 90, 180, 270 in clockwise direction. Same for anticlockwise.
Your while loop would be for angle < given angle, since with the variables being assigned values based on the direction of rotation you wouldn't have to worry about +/- values for the angles.
This is probably a really basic answer and not what you were hoping for, but I hope it helped a little!
So I have a program where a ball subject to gravity bounces off of lines created by a user with mouse clicks. These lines are normally sloped. My collision bounces work perfectly EXCEPT in the case where ball does approximately this:
->O ------
My code works by finding the normal vector of the line such that the scalar product of the incident velocity vec of the ball and the normal of the line is negative (this means the vector have opposite directions).
Then I decompose the velocity into terms parallel and perpendicular to the normal,
and the reverse the direction of the parallel component.
During the edge case described above ball moves basically along the line. How can I account for this? Any advice?>
Possible Solutions:
Instead of using a single 1D 'line', you could construct a 2D rectangle (that is as this as you want/need it to be) --- composed of 4 separate 'lines'. I.e. you can have collisions with any of the 4 faces of the rectangle object. Would that work?
Do some sort of corner collision -- if the ball is 'hits' the start or end of a line, have it bounce off appropriately. I think the way this would be done is as follows:
i. Collision occurs if the corner falls within the radius of the ball.
ii. Define a line between the corner and the center of the ball.
iii. Reverse the component of the ball's velocity along this line.