Getting Started | Lesson 1 | Lesson 2 | Lesson 3 | Lesson 4 | Lesson 5 | Hardware

Lesson 4 - Dissecting MotorBoardTop

MotorBoardTop is the most important application if you plan on changing any of the hardware (designing your own motorboard or using a platform other than the Mini-Z). Below, a graphical view of MotorBoardTop is shown that was generated using Graphviz (click on the image to see the large view).

Changing the Communication Channel (I2C v. UART)

The preferred communication channel between the Motorboard and Mica mote is through I2C because it is fast and uses it's own clock (the motes do not have to agree on a speed indpendently as for UART). However, because pull-up resistors are not included on the Motorboard or Mica mote, the standard means for communication is UART. If these pull-up resistors are available in the future, it is straightforward to modify MotorBoardTop to use I2C instead of the UART as shown below.

Modifying the MotorBoardTop Configuration

This is similar to what was learned in Lesson 2. The file looks like
	configuration MotorBoardTop {
	implementation {
	  components 	Main, MotorBoardTopM, UARTMotorPacket as Packet, 
			MotorTestC, HPLMotor1, HPLMotor2, MZServo, HPLAccelC, 
	  Main.StdControl -> MotorBoardTopM;
	  MotorBoardTopM.CommControl -> Packet;
	  MotorBoardTopM.Receive -> Packet;
	  MotorBoardTopM.Send -> Packet;
	  MotorBoardTopM.MotorTest -> MotorTestC;
	  MotorBoardTopM.Leds -> LedsC;
	  MotorBoardTopM.Motor1 -> HPLMotor1;
	  MotorBoardTopM.Motor2 -> HPLMotor2;
	  MotorBoardTopM.Servo -> MZServo;
	  MotorBoardTopM.ServoCalibration -> MZServo;
	  MotorBoardTopM.MotorAccel -> HPLAccelC;
To use I2CMotorPacket instead of UARTMotorPacket, it is only necessary to change the component that is included:
	configuration MotorBoardTop {
	implementation {
	  components 	Main, MotorBoardTopM, I2CMotorPacket as Packet, 
			MotorTestC, HPLMotor1, HPLMotor2, MZServo, HPLAccelC, 
The top-level picture then looks like this (notice UARTMotorPacket has changed to I2CMotorPacket):

Using a Different Platform

This section is a little confusing at the moment and probably will remain so until somebody actually does this. Please email if you plan to change hardware platforms.

Currently the Robot interface used from the Mica mote allows you to set the speed, turn angle, and direction of the CotsBot. If a tracked vehicle is used however, an interface that allows you to set the forward speed and turning velocity might be preferred. Or instead, you could directly set the speed of each motor.

In this case a couple components will need to be modified.

Robot Interface

The first modification might be to modify the interface in contrib/cotsbots/tos/interfaces. You could create additional commands to set the forward speed and turning velocity (v and w). By simply modifiying, you will not need to change any of the included applications for the Mica Mote.

Adding Commands to MotorBoard Include File

Any new commands you add to the Robot interface should be included in contrib/cotsbots/tos/lib/MotorBoard.h. Motorboard.h includes constants that you can use in interpreting commands sent to and from the Motorboard. You might want to add something like

Receive Event in MotorBoardTop and EvalCommand Task

When a message is received by the MotorBoard, it is filtered up to the Receive event in MotorBoardTopM which posts the EvalCommand task. In order to implement other commands you've added such as MOTOR_SET_TURN_VELOCITY, you will need to implement these commands in the EvalCommand task. You might also wish to implement the standard SET_SPEED, SET_TURN, and SET_DIRECTION messages in a different way. For example, the current Mini-Z platform sets the direction by changing the direction of Motor1.
	  call Motor1.setDir(bufferPtr->data[0]);
To do the same thing on a differential drive platform, you might instead use
	  call Motor1.setDir(bufferPtr->data[0]);
	  call Motor2.setDir(bufferPtr->data[0]);

Tweaking the Hardware Components

It is also possible to tweak certain hardware components located in contrib/cotsbots/tos/platform/atmega8. If you'd like the PWM for the motors to run faster, modify HPLMotor(1/2).nc. If you'd like to modify the control loop for the Mini-Z servo, try changing You may also add your own hardware components if using a different platform. Some RC cars use a solenoid instead of proportional steering and you could write an component to operate the solenoid. If you add a speedometer sensor, you might want to modify the motor components so that the speed is controlled appropriately. The sky is the limit here...

Go to Lesson 5