Software > Software

Dual sensors differential drive?

<< < (2/3) > >>

Admin:
you are very close, try this:

Left Motor = SensLeft * KC + General_Speed
Right Motor = SensRight * KC + General_Speed

or this:

Right Motor = SensLeft * KC + General_Speed
Left Motor = SensRight * KC + General_Speed

check this out:
http://www.societyofrobots.com/programming_fuzzy_logic.shtml

Hydro:
The problem with what you gave is that I simply don't think it will try to center itself in between the 2 surrounding walls.
Or am I wrong?


Also, if I want to use the "last error" method again, it should be something like this, right?
global variable -> unsigned int lastLeftError = 0, lastRightError = 0;
...
LeftMotor = LeftSens * KC + General_Speed - lastLeftError * KC2
RightMotor = RightSens * KC + General_Speed - lastRightError * KC2

Admin:
Hmmmm I feel stupid, ignore my previous advice . . . it wont actually work . . .

Im not sure why you dont want IF statements . . . I think what you dont want is case based, right?

So there are two ways to drive between the walls:
1) if the distance between both walls are always equal, then put both IR sensors on only one side of your robot (the right side in this example).

//if too far from wall, turn right
if distance_to_wall_threshold_far > (sense_top+sense_bottom)/2
then left_motor = ((sense_top+sense_bottom)/2 + distance_to_wall_far)*constant + general_speed
and  right_motor = (distance_to_wall_far - (sense_top+sense_bottom)/2)*constant + general_speed

//if too close to wall, turn left
if distance_to_wall_threshold_close < (sense_top+sense_bottom)/2
then left_motor = (distance_to_wall_close - (sense_top+sense_bottom)/2)*constant + general_speed
and  right_motor = ((sense_top+sense_bottom)/2 + distance_to_wall_close)*constant + general_speed

//else go straight
left_motor = general_speed
right_motor = general_speed

there are many other ways to do that above code

2) if the center location between walls is unpredictable, you cannot use just two sharp IR to center your robot. its impossible. unless of course if your robot does mapping, you can predict where the center is. or if you mount your sharp IR on a scanning servo.

Hydro:
I don't see why you can't center you robot.
I mean, you know the robot's width, and you have 2 IR sensors on both sides of the robot.
Your aim is basically to reach a point where both IR read the same value...

However, the distance is known and constant, but I want to follow both walls, hence why I have 2 IRs, one on each side.
That might explain why I thought:
RightMotor = (SensLeft - SensRight) * KC + General_Speed.
LeftMotor = (SensRight - SensLeft) * KC + General_Speed.

Because, if both sensors return about same distance from the wall, the KC will be nullified, and I'll be left with the General_Speed alone, on both engines. If the right sensor returns a larger value then the left one, then the RightMotor will decrease, and LeftMotor increase - the robot continues forward, but drives towards the right wall.
Same for the left wall...


What about the lastError one?

Admin:

--- Quote ---I don't see why you can't center you robot.
I mean, you know the robot's width, and you have 2 IR sensors on both sides of the robot.
Your aim is basically to reach a point where both IR read the same value...
--- End quote ---
Picture it for a second. If there are IR on both sides of the robot, how would your robot know if it is pointing 30 degrees or -30 degrees? It cant with that setup.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version