1 of 28

2019 Botball Training

Week Three

Using the iCreate

2 of 28

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 28

Week Two Recap

We went over:

  1. Using a Drive Base
  2. Syntax of C
  3. Program Control in C

4 of 28

Using the iCreate

5 of 28

Ground Rules

  • Do NOT click the “clean” button at the center of the robot after turning it on
  • Don’t let the robot drive off the table
  • Hold the robot by the base
  • Have fun

6 of 28

What is the iCreate?

  • A Roomba without a vacuum cleaner (and some other modifications)
  • It is a very stable, very reliable base to build everything on top of - use it!
    • It is much faster as well!
  • The Wallaby controller runs your programs and then sends commands through the cable to the iCreate

7 of 28

Important iCreate Functions

  • create_connect()
    • This allows your Wallaby controller to start talking to the iCreate. If it fails, make sure the iCreate is turned on and plugged all the way in.
  • create_disconnect()
    • This will end communication safely. If you don’t call this at the end of your program, you will need to reboot the iCreate before you can connect to it again.

8 of 28

Important iCreate Functions

  • create_drive_direct(int left_speed, int right_speed)
    • This command moves the right wheel at a certain speed and left wheel at a certain speed
    • Speed is specified as an integer from -500 to 500
  • create_stop()
    • This command stops all movement.

9 of 28

iCreate Documentation

A full list of functions that can be used with the Create can be found here:

http://files.kipr.org/wallaby/wallaby_doc/create_8h.html

The iCreate Documentation can be found here: https://www.adafruit.com/datasheets/create_2_Open_Interface_Spec.pdf

10 of 28

Try moving the Create!

  • Start with a create_connect()
  • For now, just use msleep() to separate various create_drive_direct() commands.
  • End with a create_stop() and then a create_disconnect()
  • Tip: start at speeds around 200
    • The Create moves a lot faster than the Wallaby robots
    • Remember to run your robots on the ground

11 of 28

Try moving the Create!

int main()

{

create_connect();

create_drive_direct(200, 200);

msleep(500);

create_drive_direct(-200, -200);

msleep(500);

create_stop();

create_disconnect();

return 0;

}

Move forward at 200 speed for 0.5 seconds.

Move backward at 200 speed for 0.5 seconds.

12 of 28

Turning

  • You can use create_drive_direct() for turning as well
    • Pass in different values the right wheel speed and left wheel speed so the robot arcs
  • KIPR also provides several rotation functions for the Create
    • create_spin_CW(int speed)
      • Spins clockwise at the specified speed
    • create_spin_CCW(int speed)
      • Spins counterclockwise at the specified speed

13 of 28

Sensors

14 of 28

What are Sensors?

  • Two types: Digital and Analog
  • Improves precision for movement
    • For example, the robot could move until a tophat sensor sees the line.
  • ET, Touch, Lever Touch, Top-hat, Light, etc.
  • Ten digital ports, six analog ports

15 of 28

Analog vs. Digital

  • Analog sensors can return anything in a range of values while digital sensors return 0 or 1
  • There are ten digital ports on the left and six analog ports on the right
  • Some examples of analog sensors are light sensors, tophat sensors, and ET sensors.
  • Some examples of digital sensors are touch sensors and lever sensors.

16 of 28

Sensors

Sensor ports

17 of 28

Sensor Commands

  • int analog(int port)
    • Returns an integer from 0-4095 based on the sensor’s environment
  • int digital(int port)
    • Returns 0 or 1
      • Similar to the a, b, and c button functions, this returns 1 if the sensor is pressed and 0 if the sensor is not pressed

18 of 28

iCreate Exercises

19 of 28

Exercise 1

Your program must:

  1. Drive forward until the iCreate bumper is touched
  2. Challenge: Then drive backwards for the same distance that it just travelled forward.

Getting the bumper sensor for the create:

get_create_lbump()

get_create_rbump()

Remember to run the robot on the ground!

20 of 28

Solution for Exercise 1

int main()

{

create_connect();

int tme = 0;

create_drive_direct(150, 150);

while (!get_create_lbump() && !get_create_rbump()) {

msleep(50); // wait until touch is pressed

tme += 50;

}

create_drive_direct(-150, -150);

msleep(tme);

create_stop();

create_disconnect();

}

21 of 28

Exercise 2

Your program must:

  • Drive in a perfect square.
  • Stop when completed.

Remember to run the robot on the ground!

22 of 28

Solution for Exercise 2

int main()

{

create_connect();

int i;

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

create_drive_direct(150, 150);

msleep(1000);

create_drive_direct(150, -150);

msleep(600);

}

create_stop();

create_disconnect();

}

23 of 28

Exercise 3

Your program must:

  • Drive until either the iCreate bumper is pressed OR 5 seconds pass, and stop the robot.
  • Print which case was triggered.

Remember to run the robot on the ground!

24 of 28

Solution for Exercise 3

int main()

{

create_connect();

create_drive_direct(150, 150);

int time_passed = 0;

int conditions_satisfied = 0;

while (!conditions_satisfied) {

if (get_create_lbump() || get_create_rbump()) {

conditions_satisfied = 1;

printf(“Touch Sensor Pressed!\n”);

} else if (time_passed > 5000) {

conditions_satisfied = 1;

printf(“Five Seconds Passed!\n”);

}

time_passed += 20;

msleep(20);

}

create_stop();

create_disconnect();

}

25 of 28

Exercise 4

Menus are a versatile and robust option for selecting different programs to run.

Your program must:

  • Use A, B, and C buttons to make one of 3 selections.
  • Menu has 3 options:
    1. Go forward until bumper touched
    2. Go forward for 5 seconds
    3. Drive in a square

Remember to run the robot on the ground!

26 of 28

Solution for Exercise 4

int main() {

create_connect();

int condition;

while (!a_button() && !b_button() && !c_button()) {

if (a_button()) {

condition = 1;

} else if (b_button()) {

condition = 2;

} else if (c_button()) {

condition = 3;

break;

}

msleep(20);

}

create_drive_direct(150, 150);

int time_passed = 0;

while (

!(condition == 1 && (get_create_lbump() || get_create_rbump())) &&

!(condition == 2 && analog(0) < 1000) &&

!(condition == 3 && time_passed > 5000)) {

time_passed += 20;

msleep(20);

}

create_stop();

create_disconnect();

}

27 of 28

Closing Thoughts

Next week, we will cover advanced topics including game strategy and complex robot movement.

Please leave the robot on the desk with the charger.

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

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

https://tinyurl.com/botballfunctions

28 of 28

See you next week!