ME 333 Introduction to Mechatronics
Lab 1

This first lab introduces you to the e-puck mobile robot as an example mechatronic system controlled by a Microchip PIC, in this case a dsPIC30F6014A. The primary purpose of this lab is to deconstruct a particular mechatronic system, to see some of the kinds of things you should be able to do by the end of the course. You can find information about the e-puck at the mechatronics wiki page here. All the information you need for this lab (particularly data sheets for various parts) can be found there, or on the lab handout. Don't bother printing this.

1. Getting to Know the e-puck

Turn on the e-puck. Launch the Bluetooth connection wizard by clicking on the Bluetooth icon on the Windows taskbar. Select the Bluetooth device that has your e-puck's sticker number and take note of the connection port (typically it's COM40). A connection icon labeled "e-puck_xxxx" should appear now; right-click on it to make the connection. If an authentication PIN number is requested, enter the sticker number.

Start the program EpuckMonitor.exe, in C:\e-puck\tool\e-puck_monitor. This is a GUI interface that allows you to interact with the e-puck. Select the COM port corresponding to your Bluetooth connection; you should now see the GUI receiving data from the e-puck. (If the program fails to communicate with the e-puck, even after one or two restarts, you may have to download the sercom.hex program to the e-puck; the procedure is explained below.) Switch on the e-puck and connect to the e-puck on the COM port given by the TA. Try out some of the functions of the e-puck: drive it around, take pictures, turn the LED's on and off, use the speaker, test the functioning of the microphones, and pick up the e-puck to see the orientation determined by the robot's accelerometer. Can you identify the location of the three microphones? See the change in response of the IR proximity sensors when you put an object (or your hand) nearby.

Downloading the sercom.hex program to the e-puck:
Launch the "tiny bootloader" (C:\e-puck\tinybld195\tinybldWin.exe). Browse to the file C:\e-puck\e-puck\program\advance_sercom\sercom.hex. Make sure your comm speed is set to 115200 and the port is set to the COM port on which you have a Bluetooth connection. Click on Write Flash, then reset your e-puck by pressing the blue button on top. The bootloader should now find the e-puck and download your program.

After you are comfortable using EpuckMonitor, move on to the next step.

2. e-puck Hardware

Print out this webpage if you don't already have a copy, one per group, and use it for your answer sheet. On the picture at the top of this page, identify the following parts: Take out the 3.6 V Li Ion battery and identify the dsPIC30F6014A.

Answer the following questions:

  1. The two wheels are driven by stepper motors. The stepper motors, without gearing, have 20 (full) steps per motor revolution. How many steps are there per wheel revolution?


  2. Each stepper motor consists of two separate "windings" or "phases." By changing the current flow through these windings, we step the motor. For example, for a particular winding, + indicates current flow in one direction and - indicates a flow in the opposite direction. Then there are four possible combinations: ++, +-, --, -+. By stepping through this sequence forward or backward, the motor steps forward or backward. Question: What is the resistance of each winding in the e-puck's stepper motors? If each stepper is powered by the battery's 3.6V, and both windings are energized, how much power is the stepper consuming? Considering that there are two steppers, and the battery's storage capacity is 1400 mAh, what is the longest the e-puck can be powered by the battery if both motors are always energized (and assuming no other power consumption)?












  3. What voltage is powering the PIC? What chip is providing this regulated voltage?


  4. As the accelerometer is used in the e-puck, what is the range of accelerations that it can sense (in g's)?


  5. The dsPIC30F6014A in the e-puck is a 16-bit microcontroller (unlike the 8-bit 18F4520 we will use later in the course). What does this mean?


  6. How much flash program memory does the PIC have? How about RAM (for data)?


  7. Many of the PIC's pins can be used in different ways, depending on how the PIC is configured in software. How many analog inputs does the PIC have? How many of these are used as analog inputs by the e-puck software?


  8. Which pins of the PIC are used for driving the stepper motors? Which pins are used to read the accelerometer? Which pins are used to receive data from the camera?





3. Programming the e-puck

Follow the instructions provided here (also in C:\e-puck\program\NUtest\NUtest.c) to create your own MPLAB project. If you are successful, you will now be able to control the e-puck using hyperterminal on your PC.
  1. Experiment with the various commands. Check if you can see a thresholded black and white image of black X on a white piece of paper held in front of the camera (see the comments in the program). What threshold value gives a good image?


  2. Try the X command, coupled with the V and W commands, to see how precise the "dead reckoning" positioning of the robot is. Drive the robot to the four corners of a 20 cm square. Now modify the program so the robot rotates and translates more slowly when you use the X command, recompile the program, and load it onto the robot. Demonstrate to the TA and have the TA sign your answer sheet.


  3. Now we will use the MPLAB editor to examine files in your project. The "Find in Files" command is especially useful to locate specific words in several files at a time. We will get an idea of what is happening in the header file libary\motor_led\e_epuck_ports.h and the initialization routine e_init_port() in library\motor_led\e_init_port.c.

    Look at e_epuck_ports.h.

    Look for "MOTOR1_PHA" and "MOTOR1_PHA_DIR" in e_init_port().

  4. The final task is to understand in detail how the V, W, and X commands work. This means understanding the library functions they use, in particular functions in library\motor_led\advance_one_timer\e_agenda_NU.{c,h} and e_motors_NU.{c,h}. Among other things, these functions allow us to set a speed for each of the motors, then have those speeds be implemented by an interrupt service routine (ISR) indefinitely, without us having to keep sending commands to move the motors in our main program.

    At the beginning of the program, NUtest.c calls e_start_agendas_processing() (in e_agenda_NU.c), which sets up an ISR called every 0.5 ms. Then it calls e_init_motors() (in e_motors_NU.c), which creates two processes, with names run_left_motor and run_right_motor, to be considered each time the ISR is called. Each of these processes is of type "Agenda," defined in e_agenda_NU.h, and they are created by the e_activate_agenda() call. The function e_activate_agenda() creates a new "Agenda" and puts it at the beginning of a "linked list" of Agenda's, where "agenda_list" is a "pointer" to the beginning of the linked list of Agendas. (If you have never programmed in C before, you may not be familiar with the terms "linked list" and "pointer." Ask questions and learn from the TA or your labmates.) The actual ISR is the last function in e_agenda_NU.c.

Wrapping Up

Load the program C:\e-puck\program\advance_sercom\sercom.hex on your e-puck, so it can again be used with the EpuckMonitor.exe program. Turn in your group's answer sheet to the TA.