I want to write a code for my Ev3 robot with two motors. I want it to be able to go a certain distance, in this case forward until the motors have turned a maximum of 2500 degress for four seconds. Then I want the robot to go back the same distance. But the problem is that sometimes only one motor spins while the other does nothing and sometimes a motor will continue to spin long after it has returned to its original position. I wonder if there is any way I can improve the code I have. I have tried it on several different Ev3 equitment so it is most likely not a hardware problem. Any help would be appreciated :)
b = Brick('ioType','usb');
b.outputStepSpeed(0,Device.MotorA,60,0,2500,0,Device.Brake);
b.outputStepSpeed(0,Device.MotorD,60,0,2500,0,Device.Brake);
pause(4)
b.outputStop(0,Device.MotorA,Device.Brake);
b.outputStop(0,Device.MotorD,Device.Brake);
tacho = b.outputGetCount(0,Device.MotorA);
disp(['> Tachometer: ' num2str(tacho)]);
b.outputClrCount(0,Device.MotorA);
b.outputClrCount(0,Device.MotorD);
pause(0)
b.outputStepSpeed(0,Device.MotorA,-60,0,tacho,0,Device.Brake);
b.outputStepSpeed(0,Device.MotorD,-60,0,tacho,0,Device.Brake);
pause(4)
b.outputStop(0,Device.MotorA,Device.Brake);
b.outputStop(0,Device.MotorD,Device.Brake);
tacho =
b.outputGetCount(0,Device.MotorA);
disp(['> Tachometer: ' num2str(tacho)]);
b.outputClrCount(0,Device.MotorA);
b.outputClrCount(0,Device.MotorD);
clear
do check if your ports are correct and if they are connected. Do also know that not all EV3 motors are manufactured perfectly the same which means some can be stronger, making it almost impossible to move straight. Using a gyro might help out in this case.
Do comment if you need further help!
Related
I want to use 'process modelling library' to mimic vessel movement from one point to another (because 'road traffic library' cannot realistically reflect the ship movement).
However, I am stuck at defining a way for speed control and keeping a safe distance between two vessels. What I want to achieve is the speed of each vessel (agent) should be restricted in a threshold [MaxSpeed,MinSpeed], and all the vessels should keep a safe distance/time with the vessels in front or behind. For example, if a vessel with speed 15 knots catches the vessel with speed 10 knots, it will change the speed to 10 knots before reaching the required safe distance/time.
Currently, what I am thinking is to set the agent speed at 'Source' block or 'MoveTo' block, and create a function to avoid collision. Does anybody know how the function will look like? I am very appreciate if any idea or comments, thanks!
Even though depending on your model there may be smart ways of doing this, I will show you a generic inefficient way of doing this in a very simplified way without deceleration or any fancy stuff.
It's a good idea to first set up a node in front of your boat as a safety distance:
I also added an event that will check if other boats are getting too close to the boat itself... so in the event you can have code like this that runs every minute for example:
for(Boat c : main.boats){
if(unsafeDistance.contains(c.getX()-getX(),c.getY()-getY())){
setSpeed(c.getSpeed());
break;
}
}
This code checks if there is any boat inside the safety node, and if there is one, the boat will instantaneously change its speed to the speed of the boat in front of it.
This code is ugly and inefficient, but if you want something better, you need to think about it yourself using the characteristics of your situation in order to make it better... but this solution should work using moveTo blocks from the Process modeling library.
I'm trying to make a simplified version of crazy taxi . For the first step i need to make an infinite ground . I'VE searched online but couldn't find any examples .
Can i find any example of how to do this ?
https://www.youtube.com/watch?v=rhTPxrJICVg&list=PLLH3mUGkfFCXQcNBz_FZDpqJfQlupTznd
N3K makes an infinite runner in Subway Surfers style, meaning ground coming from the back and going towards the camera.
The above link is to his tutorial series.
This is a very broad question I try to give a very simplified answer to get you going.
To create endless road you need some sort of procedural function that generates corners for your track. If you do not need to backtrack you can cook something up yourself like (in X distance turn X degrees to the right). If you do need to backtrack you need something like perlin/simplex noise that always generates the same value based on 1 or more other values. You could use total distance to get the curve in the road.
You simply keep generating the world on the fly and unload pieces of the world you don't need any more. If the player can alter the world like destroying street furniture or leaving skitmarks you need to implement a chunk system. When you backtrack and generate a cerain part of the world with your procedural function you can have permanent changes the player made in that specific part by saving and loading to the chunk. Much like Minecraft does it actually.
This could be a really broad question, but if you can help me with ideas, it would be a great help to me.
I am trying to implement basic path finding algorithm in matlab. I have to create a map where the robot can navigate and also avoid obstacles and reach destination. I have the algorithm fine with me. But am struggling with the gui as I haven't used much of Gui in matlab.
This is the following idea I had.
I created a plot and just defined 4 coods for each obstacle, destination as a circle and a start point. But am stuck when I think how I can detect whether the robot has hit an obstacle or not. One way is to create the equation of line and try to see if the point ever comes to lie on it. But the movement is based ona random generated variable. Thus it is possible for the robot to cross the line and get inside the polygon.
My apologies for bein too elaborate, but can you please tell me the best way to implement this in matlab? It is mandatory to do this in matlab. Please suggest me a better and easy way to program it. Thanks in advance.
If your obstacles are all polygons you could try to use the ray casting algorithm described on the following wikipedia site.
Point in polygon algorithm
With this you should be able to determine if the robot position lies within an obstacle, or you could determine if the next movement will bring the robot into contact with the obstacle.
If you are looking for a simple algorithm that can take care of obstacles inherently i would suggest the potential fields algorithm (can get stuck in certain cases)
Potential Fields
else you can also try the A* algorithm, which is better in my opinion; Good description of A*
After some sample projects, I have started with my first game in cocos 2d and box 2d where objects fall from a parachute and you kill them using slingshot. Now i'm stuck # couple of things for a while:
Collision Issue:
Using Box 2d i have made collision with objects. However when i add a counter to get a count of my collision i doesn't work. Counter increases even though the percentile is moved out of the screen.Don't know how to get rid of this.
I'm trying to get random rotation to my sprites which fall from above, Like a parachute experience. Now all of then rotate # a same angle.
Lastly i need to get rid of the surrounding sprites when collision happens. Ex: When the percentile collides with a falling object, in a radius of 2.5 cms the other sprites should also disappear.
I Badly need help and suggestions, hence all the 3 questions # once :-). I have provided the link for my project so that you can look # the source code. Desperately looking for your help guys!!!
Download Source Code:
http://jumbofiles.com/6fn5mmpnq1q8/Karthik.zip.html
Budding Developer,
Karthik
You have a pretty good tutorial here: http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12
I think that one can solve your problems :)
You can get the best tutorial for the particular requirement you have described over here.....
The link for that is as follows
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
The tutorial is of 2 parts and describes the code briefly.. The code of that is described and you can get good amount of help from there.
ques 1 + 3: you need read link which share by Mikael and Marine
ques 2: in cocos2d, if you want get random value, you can use support function (such as: rand(), random(), CCRANDOM_0_1() ....)... i think, you need set rotation value for object. i dont know your problem, you need explain it (link is "File Not Found or Deleted / Disabled due to inactivity or DMCA")
I want to ask you How can I make simulation of car crash ?
On the internet I found http://www.gamedev.net/reference/articles/article1459.asp .
I think about using finite-element-method, but now I think it is too difficult for me :/
Do you know any good, not too accurate and not very hard-to-learn methods to simulate collision of two bodies ( two cubic cars ) with deforming?
My first idea was to made these cars with some number of rigid bodies, and connect them, but I don't know if it is good idea :/
Try reading this paper for starters. This and the references therein should point you in the right direction, more or less.