1 of 57

2019 Botball Training

Week Two

Using a Drive Base and More C Programming

2 of 57

Training Schedule

We will meet from 7:00 - 9:30 PM every Friday from January 11 to February 1.

1/11: Introduction to Programming

1/18: Using a Drive Base and More C Programming

1/25: Using the iCreate

2/1: Advanced Topics

Please try to be on time for the training meetings and make sure to bring your own device!

3 of 57

Week One Recap

We went over:

  1. Botball Previous Year Video
  2. Syntax of C
  3. Program Control in C

4 of 57

Building Your First Robot

5 of 57

Your First Bot

The robot will include:

  1. 2 wheel drive base
  2. Wallaby controller mount
  3. Servo with arm attachment

6 of 57

Attaching the beam to the servo

7 of 57

Attaching the beam to the servo

8 of 57

Attaching the beam to the servo

9 of 57

Attaching the beam to the servo

10 of 57

Attaching the beam to the servo

11 of 57

Attaching the beam to the servo

12 of 57

Attaching the beam to the servo

13 of 57

Servo Mount, Caster Ball, and Motors

14 of 57

Putting the servo into the servo mount

15 of 57

Putting the servo into the servo mount

16 of 57

Putting the servo into the servo mount

17 of 57

Putting the servo into the servo mount

18 of 57

Putting the servo into the servo mount

19 of 57

Screwing the beams onto the chassis

20 of 57

Screwing the beams onto the chassis

21 of 57

Attaching more beams onto the chassis

22 of 57

Attaching more beams onto the chassis

23 of 57

Attaching more beams onto the chassis

24 of 57

Attaching more beams onto the chassis

25 of 57

Attaching more beams onto the chassis

26 of 57

Attaching more beams onto the chassis

27 of 57

Attaching more beams onto the chassis

28 of 57

Attaching more beams onto the chassis

29 of 57

Attaching the Wallaby onto the beams

30 of 57

Attaching the Wallaby onto the beams

31 of 57

Attaching the Wallaby onto the beams

32 of 57

Connect

Battery

33 of 57

Connect

Wires

Make sure the motor wires are both plugged in the same direction

Servo should be plugged in with the yellow cable closest to the screen

34 of 57

Done!

35 of 57

Programming

Motors and Servos

36 of 57

Motors

  • Can spin indefinitely
  • The Wallaby has four motor ports
  • Can mount wheels on motors or arms if necessary
  • Move at a certain speed

37 of 57

Motors

Motor ports

38 of 57

Motor Functions

  • off(< motor# >)
    • Turns off a single motor
  • ao()
    • Turns off all motors
  • motor(< motor# >, < power >)
    • Power ranges from -100 to 100
  • mav(< motor# >, < speed >)
    • mav means “move at velocity”
    • speed ranges from -1000 to 1000 and is measured in ticks per second, where 1 revolution equals about 1100 ticks.
  • msleep(< time >)
    • Sleeps for the number of time number of milliseconds

39 of 57

motor() vs. mav()

  • The motor() command gives a certain amount of power to the motor
  • The mav() command tries to make the motor move at a certain speed, taking readings from how far the motor has moved so far
    • If something gets in the way of a wheel that’s moving with mav() the motor will try to speed up to compensate.
  • 1000 ticks/sec (mav) vs 100% power (motor)

40 of 57

More Motor Commands

  • As a motor runs, the Wallaby keeps track of its current position in ticks.

  • get_motor_position_counter(< motor# >)
    • Returns current position in ticks for the specified motor

  • clear_motor_position_counter(< motor# >)
    • Resets the counter of the specified motor to 0 (zero)
    • The current value of a counter for a motor can be seen on the Motors screen on the Wallaby

41 of 57

Motor Screen

  • There is a screen for motors on the Wallaby. Click the “Motors and Sensors” button, then the “Motors” button.

  • Try to move the motor around by dragging the dial to different values

  • Operate the motors carefully

42 of 57

Servos

Servo ports

43 of 57

Servos

  • Range of about 180 degrees
  • Four servo ports
  • Used for claws, arms, and other mechanisms that require precise movement
  • Go to a position
  • Wires are Brown, Red, and Yellow
  • Servo cable should be plugged in with yellow wire closest to the screen!

44 of 57

Motors vs. Servos

  • Motors and servos are what the robot uses to interact with its surroundings
  • Servos have limited range, and are only able to turn about half a revolutions
    • However, they are able to hold their position easily
  • They go to a specified position within that range.
  • Servos are used to power claws and arms which must go to a certain absolute position each time and do not need full rotations

45 of 57

How to use a servo

  • Before using a servo, you will need to enable it using the enable_servo(<servo#>)function. It takes one integer argument: the servo port you wish to enable.
  • You can enable all servos at once using the enable_servos() function. This takes no arguments.
  • When you’re done with a servo, disable it with disable_servo(<servo#>) or disable_servos().

46 of 57

More Servo Commands

  • set_servo_position(< servo# >, < position >)
    • The possible range of positions is from 0 to 2047.
    • Rotates specified servo to < position >.
    • You can set a position before enabling; if you don’t it defaults to 1024, the middle.
  • get_servo_position(< servo# >)
    • Provides the current goal position of the specified servo.
      • It returns where it was last set to go, not the current real-world position.
    • Works only when servos are enabled.

47 of 57

Servo Screen

  • Similar to the motor test screen, there is a corresponding one for servos, click the “Motors and Sensors” button, then click the “Servos” button

  • Try moving the servo, but be careful to not strain anything.

48 of 57

Servos

  • The servo has set positions, so sometimes the desired positions may not be in its range of motion.
  • In order to get it to have the proper positions, remove the arm and set the servo position to 0.
  • Once the servo position is at 0, put the arm back on in its upmost position.

49 of 57

Exercise 1

Your program must:

  1. Drive forward
  2. Raise the arm
  3. Drive backward
  4. Lower the arm

Remember to run the robot on the ground!

Useful commands:

  • msleep(< time >)
  • mav(< motor# >, < speed >)
  • set_servo_position(< servo# >, < position >)

50 of 57

Solution for Exercise 1

int main() {

mav(0, 1000); // drive forward

mav(1, 1000);

msleep(2000);

mav(0, 0); // stop motors

mav(1, 0);

set_servo_position(0, 600); // move arm up

msleep(1000); // wait for servo to move

mav(0, -1000); // drive backward

mav(1, -1000);

msleep(2000);

mav(0, 0); // stop motors

mav(1, 0);

set_servo_position(0, 0); // move arm down

msleep(1000);

}

51 of 57

Exercise 2

Your program must:

  • Drive forward
  • Perform a smooth 90 degree arc-turn.

Consider using a for-loop.

52 of 57

Solution for Exercise 2

int main() {

mav(0, 1000);

mav(1, 1000);

msleep(2000);

clear_motor_position_counter(0);

mav(0, 1000);

mav(1, 400);

while (get_motor_position_counter(0) < 7000) {

msleep(50);

}

mav(0, 0);

mav(1, 0);

}

Adjust until 90 degrees!

53 of 57

Exercise 3

(Harder)

Create a function slow_servo with the following specs.

void slow_servo(int port, int position);

  1. The function takes in 2 arguments: the servo port number and the servo position that you want to set.
  2. Hint: Use a loop with set_servo_position to move toward the desired position in small increments, and use msleep()to pad the time in between.

54 of 57

Solution for Exercise 3

void slow_servo(int port, int position) {

enable_servo(port);

float i;

int interval = (position - get_servo_position(port)) / 100; // compute small movements to increment with

for(i = 0; i < 100; i++) {

set_servo_position(port, get_servo_position(port) + interval);

msleep(20);

}

disable_servo(port);

}

55 of 57

Summary

Today we covered:

  • Building
    • Attaching a servo
  • Programming
    • Motors and Servos
    • Advanced robot movement

56 of 57

Closing Thoughts

Next week, we will cover using sensors on the Wallaby and driving the iCreate.

If you would like to learn more about the C language in the meantime, take a look at these resources:

  1. learn-c.org
  2. cprogramming.com
  3. These slides (which will be emailed to you)

Code Solutions are posted at: https://tinyurl.com/botballtraining

More botball functions (old but most are the same):

https://tinyurl.com/botballfunctions

57 of 57

See you next week!