What is an encoder in robotics

In a first test run, the robot will drive straight ahead for four seconds at 32 encoder ticks per second. During this time he covers a distance of approx. 80 cm and both bikes cover the same distance at the same speed.

Test run the robot
  • Click in SimpleIDE Editor on the button Open Project.
  • Open the file Test for Trim from the directory ... Documents / SimpleIDE / Learn / Examples / ActivityBot.
  • Slide the PWR switch to position 1, click on Load EEPROM & Run.
  • After the program has been loaded, slide the PWR switch to position 0 and disconnect the USB connection cable.
  • Hold down the reset button, slide the PWR switch to position 2 and place the robot on a hard, level floor.
  • Release the reset button and watch the robot move.

The robot should walk straight ahead for about 80cm. Due to the constant feedback from the encoder, which the robot uses to continuously adjust and correct its course, the movement is not absolutely straight.

The program Test for Trim.c

How does the program work?

Except the order break (8000) all other commands come from the library abdrive.

drive_trimSet (0, 0, 0)clears any trim settings that may have been entered previously.

drive_speed (32, 32)sets both wheels to a speed of 32 ticks (1/2 revolution) per second over a period of 8s. The command

drive_speed (0, 0)stops both servos.

What you should know

Updates- The ActivityBot updates the motor speed 50x per second via feedback from the encoder data. It compares how far the wheel should have turned and how far it actually turned.

Encoder ticksand distances - With each encoder tick, the wheel has moved 3.25mm forward. A tick is always the distance from a spoke to a hole or from a hole to a spoke. There are 32 spokes and 32 holes in each wheel, making a total of 64 encoder ticks per wheel revolution.

Ramping- Ramping means the gradual increase or decrease in speed so that the robot starts and ends driving maneuvers gently and does not start or stop abruptly.

Try this

If you want to drive down the route you have just traveled twice as fast, then try the following program.

Be faster
  • Click in SimpleIDE Editor on Save Project As and rename it Be faster.
  • Change the program code as shown in the program listing.
  • Set the PWR switch to position 1 and click on Load EEPROM & Run.
  • Set the PWR switch to 0 and disconnect the USB cable connection.
  • Place the robot on the floor while pressing the reset button. Set the PWR switch to 2 and let the robot drive.

program Be faster c

Now you come!

In the following program, the principle of ramping becomes clear and you can see it again from the movement of the robot. In a LOOP loop and with the help of a variable speed, the rotation rate of the wheels is first increased and later decreased.

Be faster
  • Click in SimpleIDE on Project and New and name it ramping.
  • Broadcast the program ramping.c into the editor of SimpleIDE and save it.
  • Click on Load EEPROM & Run.
  • Can you observe that the starting speed increases slowly and slowly decreases again when braking?

2 - cover distances

Of course it is possible to cover a certain distance by choosing a certain speed and setting the time. It gets complicated as soon as you build in rampings at start and stop. In the library abdrive there is a function drive_gotothat takes all of this into account. In addition, it controls the propulsion of each wheel in units of 3.25mm.

(Courtesy of Parallax Inc.)

3 - Straight lines, turns and encoder ticks

A wheel of the Propeller ActivityBot has 32 spokes and 32 spaces; that makes 64 ticks for the encoder. If the wheel turns 1/64 (this corresponds to a tick), it moves 3.25mm.

(Courtesy of Parallax Inc.)

Should he ActivityBot travel a certain distance s, then s in the unit mm must be divided by 3.25 mm in order to find out how many ticks have to be counted in the program.

The turning radius of a ActivityBots is typically 105.8mm.

(Courtesy of Parallax Inc.)

If the right wheel stops and only the left wheel rotates, then the distance the wheel runs corresponds to the circumference of the circle: 2 x Pi x r. In this case r is the radius of the circle; it corresponds to the distance between the two wheels: 105.8mm. The circumference is calculated as follows: 664.76 mm. A quarter turn would then correspond to a circumferential distance of 166.2 mm or 166.2 / 3.25 ticks = approx. 51 ticks.

(Courtesy of Parallax Inc.)

Test program

With this program the moves ActivityBot 256 ticks forward and then rotates 90 degrees to the right.

Test program
  • Click the button Open Project in the SimpleIDE Editor.
  • Open the file Forward Stop Face Right.side from the directory ... Documents \ SimpleIDE \ Learn \ Examples \ ActivityBot.
  • Set the PWR switch to position 1.
  • Click the button Load EEPROM & Run. The PWR switch must return to position 0 after charging.
  • Remove the USB cable from the board and set the ActivityBot on the ground. The PWR switch is in position 2.
  • Convince yourself that the ActivityBot moves four wheel revolutions forwards, stops and then turns to the right.

How does the program work?

Row 12

The ActivityBot drives forward 256 ticks (four wheel revolutions).

Line 14

The robot executes a 90 ° turn to the right.

4 - Set the speed

With the function drive_speed from the library abdrive each drive servo can be set to a specific speed (in encoder ticks per second). Positive signs stand for forward movements and negative signs for backward movements. If a wheel speed is set to 64 ticks, this corresponds to a full revolution per second. And we will drive_ramp Use the function and slowly brake the robot and allow it to start slowly.

(Courtesy of Parallax Inc.)

Sample program for speed control

In this example, the robot moves forward at a speed of 64 ticks / second for 200 ticks, then performs a 45 ° right turn by turning the left wheel at 32 ticks / second, and then moves for another 200+ ticks at a speed of 128 ticks / second.

Adjust the speed
  • Click in SimpleIDE Main program on the button Open Project.
  • Open the file Speeds for Navigation.side in the register ... Documents \ SimpleIDE \ Learn \ Examples \ ActivityBot.
  • Click the button Load EEPROM & Run.
  • Check whether the robot drives approx. 200 ticks (corresponds to more than 3 wheel revolutions) forwards, rotates to the right by 45 ° and continues to drive approx. 3.5 wheel revolutions again.

The program Speeds for navigation c

How does the program work?

The program starts with both servos rotating at 64 ticks / second for over 2 seconds. Makes a total of 128 ticks.

Drive_speed (26, 0) the left wheel turns at approx. 26 ticks / second while the right wheel stands still. This process takes 1 second; the left wheel rotates with 26 ticks, which corresponds to an angle of approx. 45 °.

Drive_speed (0, 0) lets both wheels stand still for a second. The subsequent last maneuver takes the same route as the first, only this time twice as fast (128 ticks / second instead of 64) but only one second instead of 2.