Programming the K-9 Robot in EasyC

4-29-16 – So after I got the basic K-9 body assembled, the task to program it began.  I did some basic stuff in the Vex Easy C programming language about a year ago and I forgot almost everything I knew.  I did remember the basic looping structure of autonomous programs and how to activate motors.  I had no idea how to program the ultrasonic sensor, but I told myself that if anyone could figure it out, I could (#giftedhack).

I had two programs in mind.  One would be a program where K-9 could patrol the classroom, encounter an obstacle, twitch his ears for a second, back up, rotate and go in another direction.  Another was what I call a “watchdog” program, where K-9 stays still and waits until something passes in front of the ultrasonic sensor, then he moves forward to scare off the “intruder”.

I wasn’t even sure how to plug in the ultrasonic sensor into the Vex Cortex.  Another online search found that you could plug it into any two digital ports as long as the output is lower than the input.  In the Easy C software, there is a sample test program for this sensor.  I plugged in the sensors as directed in this sample program (to digital ports 1 and 11) and the sensor worked correctly.

My K-9 robot has three motors.  The left, right and ears motors are plugged into motor ports 5, 2 and 6 respectively and are referred to in the sample programs below.

Now it was just a matter of writing out exactly what I wanted K-9 to do.  I experimented with some of the wait times to make the movements as I envisioned them.  (I also managed to snap off the 3-D printed tail in the process of the robot rolling around and running into things.  A little electric tape mended it, and gave it some needed flexibility!) Here is the “Patrol” program as it is written today:

K-9 Patrol Program with Sonic Sensor EasyC

The comments detail exactly what each line does.

The “Watchdog” program was easy after this one.  I just deleted a few lines and adjusted the position of a few commands:

K-9 Watchdog Program EasyC

Now I can send K-9 around the classroom to patrol and interact with students, or I can park him in front of my office and he can keep those pesky students out.

I don’t think I am quite finished with the programming part yet.  I can write commands to digital ports to make the eyes blink, and I am thinking about buying a Vex speaker so K-9 can talk.   Another thought would be put both the Patrol and Watchdog programs on the Cortex and make the user throw a switch to select one or the other.  There is probably a way to program the remote controller to select any “run mode” I can program.

Finally, I had an idea to print up a sign for the room saying “Beware of K-9 Unit”.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s