Step 7: Program the Trakr
////////////////////////////////////////////
//trakrmotorcontrol program for Spy Video TRAKR
//Program scans to see if button A was
//pressed on TRAKR remote and sets GPC0 high
//and GPC1 low to send current through motor
//in forward direction //
//If button B is pressed, it sets GPC0 low
//and GPC1 high to send current through
//motor in reverse direction.
///////////////////////////////////////////
#include "svt.h" //include Official API
#include "JAPI.h" //include "Secret sauce" API
#define GPC0 (1<<0) //bitmask for pin GPC0 = 00000001
#define GPC1 (1<<1) //bitmask for pin GPC1 = 00000010
#define GPC2 (1<<2) //bitmask for pin GPC2 = 00000100
#define GPC3 (1<<3) //bitmask for pin GPC3 = 00001000
#define GPC4 (1<<4) //bitmask for pin GPC4 = 00010000
#define GPC5 (1<<5) //bitmask for pin GPC5 = 00100000
#define GPC6 (1<<6) //bitmask for pin GPC6 = 01000000
#define GPC7 (1<<7) //bitmask for pin GPC7 = 10000000
int keyState; //define "keystate" as integer
void Start()
{
JAPI_SetIoOutputMode(GPC0+GPC1);//Set output mode for pins GPC0 and GPC1
}
bool Run()
{
keyState=GetRemoteKeys(); //TRAKR remote control key pressed
//assign to keystate
if (keyState > 0)
{ //if keystate is greater than 0
if(keyState&KEY_INPUT1)
{ //Button A pressed (motor forward)
JAPI_SetIoHigh(GPC0);//Set GPC0 pin high (3.3v)
} else {
JAPI_SetIoLow(GPC0); //Switch off pin GPC0
}
if(keyState&KEY_INPUT2)
{ //Button B pressed (motor reverse)
JAPI_SetIoHigh(GPC1);//Set GPC1 pin high (3.3v)
} else {
JAPI_SetIoLow(GPC1); //Switch off pin GPC1
}
if(keyState&KEY_HOME)
{ //if Home button pressed
return false; //this will end the loop
}
}
return true; //loop will repeat until false
}
void End()
{ //Program end - switch off both pins
JAPI_SetIoLow(GPC0+GPC1);
}
Make file:
# Makefile for TRAKR Toy
# Trakr Project
TRACKR_PATH = C:/Trackr
PROGRAM_NAME = trakrmotorcontrol
PRETTY_NAME = trakrmotorcontrol
OUTPUT_PATH = ./Intermediate
OUTPUT_NAME = $(OUTPUT_PATH)/$(PROGRAM_NAME).elf
INTERNALS_PATH = ../Internals
SOURCES = app.c
S_OBJECTS = $(OUTPUT_PATH)/app.o
OBJECTS = $(S_OBJECTS) $(INTERNALS_PATH)/trakr.a
SHELL = sh
CC = arm-elf-gcc
AS = arm-elf-as
BIN = arm-elf-ld
LD = arm-elf-ld
TOPMEMORY=0xFFE7C000
CFLAGS = -O0 -I../Internals/Include -I../Internals -Wall -gstabs+
TARGET_FLAG = -mcpu=arm926ejs -mapcs-32 -mlittle-endian -specs=specs.semi
LDFLAGS = -T ../Internals/WJ_APP_8M.ld -Wl,--defsym -Wl,__stack_base=$(TOPMEMORY) -Wl,-Map -Wl,$(basename $@).map -nostartfiles -static
all: prebuild $(OUTPUT_NAME) postbuild
$(OUTPUT_NAME): $(OBJECTS)
@echo "Linking... "
@echo "Creating file $@..."
@$(CC) -u _start -o $@ $(INTERNALS_PATH)/trakr_start.a $(OBJECTS) $(TARGET_FLAG) $(LDFLAGS)
$(OUTPUT_PATH)/app.o:app.c Makefile
@echo "Compiling $<"
@$(CC) -c -o "$@" "$<" $(TARGET_FLAG) $(CFLAGS)
.PHONY: clean prebuild postbuild
clean:
$(RM) -f $(PROGRAM_NAME).bin
$(RM) -f "$(PRETTY_NAME).bin"
$(RM) -f $(OUTPUT_PATH)/app.o
$(RM) -f $(OUTPUT_NAME)
$(RM) -f $(MKDEPFILE)
postbuild:
arm-elf-objcopy -O binary $(OUTPUT_NAME) "$(PRETTY_NAME).bin"
@if [ -d "E:/" ] ; then \
cp "$(PRETTY_NAME).bin" e:/APPS/ ; \
fi
prebuild:
# End of Makefile
When you compile the above code with the above make file, this will create a Trakr App file called "trakrmotorcontrol.bin" and the file will need to be copied to the Trakr. Make sure the Trakr is switched off and connect it to your computer using the yellow USB cable that came with the Trakr. Copy trakrmotorcontrol.bin to the APPS folder inside the Trakr folder. Disconnect the Trakr from your computer and switch the Trakr on. Switch the Trakr remote on, click the home button, and select trakrmotorcontrol from the menu. Use the Trakr's remote contol to drive the Trakr to the object you want to grab. Aim the Lego claw attachment to close in around the object you want to grab and press button A on the remote control to grab the object. With to object held in the claw, drive the Trakr to the location you want to bring the object and press button B on the remote to open the claw and release the object.
Congratulations! In this Instructable you learned how to add a Lego claw attachment to the Spy Vidoe Trakr. You learned how to download and install the C language compiler for the Trakr. You learned how to install jumper pins on the Trakr's circuit board to control external devices such as the Lego claw attachment. You learned how to add a common ground and 9 volt power tap for your Trakr hacking projects. You learned how to build a versatile cargo deck for the Trakr out of Lego. You learned how to build the Lego claw attachment. You learned how to connect the Lego claw to the Trakr. Finally you learned how to program the Trakr to operate your Lego claw attachment.
Remove these ads by
Signing Up

























Not Nice
















Visit Our Store »
Go Pro Today »



