motor command sequences. Most of my problem with
this code segment was coming up with an alias command
reference for the motor brake operations. I finally settled on
“S” for STOP and “H” for HALT as forward and reverse were
immediately intuitive:
case ‘F’:
dataLen = 0;
id = myid;
data[0] = nodeB;
++dataLen;
data[1] = mforward;
++dataLen;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
break;
case ‘R’:
dataLen = 0;
id = myid;
data[0] = nodeB;
++dataLen;
data[1] = mreverse;
++dataLen;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
break;
case ‘S’:
dataLen = 0;
id = myid;
data[0] = nodeB;
++dataLen;
data[1] = mforwardbrk;
++dataLen;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
break;
case ‘H’:
dataLen = 0;
id = myid;
data[0] = nodeB;
++dataLen;
data[1] = mreversebrk;
++dataLen;
while(!ECANSendMessage(id, data, dataLen,
ECAN_TX_STD_FRAME));
break;
That should do it for nodeA. Let’s hook everything
together and perform a smoke test.
Using my HI-TECH PICC- 18 C Compiler, I compiled the new
motor driver CAN application code for both nodes and loaded
them up with their respective hex files using a Microchip
MPLAB ICD2. I then connected nodeA to COM2 of my laptop.
I opened up a second Tera Term Pro session and connected the
nodeB RS-232 port to my laptop’s COM1. When I powered up
nodeA, I got the menu with my motor command additions on
the COM2 Tera Term Pro terminal emulator window. Powering
up nodeB sent the LED is off message and gave me the new
modified menu in a manner similar to Figure 1.
Since we’re on the march with our CAN application, I
decided to enter “F” as my first test command. I was very
pleased to see the result you see in Figure 7. In the
SOURCES
• HI-TECH Software ( www.htsoft.com) — HI-TECH PICC- 18
C Compiler
• Allegro Microsystems ( www.allegromicro.com) —
Allegro A3953SB
• Microchip ( www.microchip.com) — PIC18F2685; ECAN
Source Code Modules; MPLAB ICD2
meantime, nodeB was doing its thing, as well. Figure 8 was
nodeB’s response to the motor forward CAN message it
received from nodeA. Everything worked as designed. We
can now control both the nodeB LED and the A3953 motor
controller that nodeB is driving.
You CAN Do It
If the CAN bus is good enough for your Mercedes, it’s
good enough for your robot. I had a ton of fun rattling
around in the CAN and I think you will too. If you were in
the CAN with me last month, you’ve got enough CAN
knowledge under your belt to take the base CAN concepts I’ve
presented and apply CAN to your own robotic application.
I’m trying to round up some really slick miniature linear
actuators for our next meeting. If I get my hot little hands on
them before we talk again, we’ll stick them in a CAN. SV
SERVO 09.2007 61