return returncode;
}
SCREENSHOT 2. This is an
MPLAB IDE Watch window
view of the recv_buff array
contents and the status
message bytes I chose to parse
and retain. As you can see by
the value of rc, everything
worked as designed.
Note that the read_control_table
function incorporates our core send_
packet and get_packet functions to
retrieve the Dynamixel AX- 12+’s Control
Table contents. Here’s the code I used to
fill the recv_buff bytes you see in Screenshot 3:
parm_len = 3;
break;
//***********************************************
//*MAIN MAIN MAIN MAIN MAIN
//***********************************************
void main()
{
init();
cleaner();
rc = read_control_table(0x01);
++scratch8; // debugger break point
}
I didn’t show you all of the status message bytes in
Screenshot 3. However, you can look at the LENGTH byte
at offset 3 to get an idea as to how many bytes follow it.
The 0x34 LENGTH byte tells us that 52 bytes including the
checksum and ERROR byte follow the LENGTH byte. Add
the LENGTH byte, the ID byte, and the pair of sync
characters to the 52 bytes in the digital packet and you get
a complete digital packet length of 56 bytes.
I’m sure you can see the advantages of being able to
read and interpret the AX- 12+’s Control Table. It’s also
important to be able to write to an actuator’s Control
Table. So, let’s assemble a function that is capable of
modifying the write-enabled Control Table memory slots:
void write_control_table_item (char act_id, char
offset, unsigned int table_data)
{
char parm_len;
parms[0] = offset;
parm_len = 2;
switch(offset)
{
case ID:
parms[1] = make8(table_data,0);
break;
case BAUD_RATE:
parms[1] = make8(table_data,0);
break;
case RETURN_DELAY_TIME:
parms[1] = make8(table_data,0);
break;
case CW_ANGLE_LIMIT:
parms[1] = make8(table_data,0);
parms[2] = make8(table_data,1);
}
send_packet(act_id,iWRITE_DATA,parm_len);
}
There’s a case entry for every writable Control Table
entry. Thus, the write_control_table_item function is too
lengthy to print here. So, I’ve only included just enough
code to show you how it works. Note that the parms buffer
is loaded before the WRITE_DATA instruction is transmitted.
Most of the Control Table entries only require a pair of
instruction parameters. I’ve modified the parm_len value
accordingly for Control Table entries that require more than
two instruction parameters. To demonstrate how the
write_control_table_item function works, let’s modify the
RETURN DELAY TIME value. In Screenshot 3, it is currently
set to 0xFA (offset 10 in the recv_buff). This code will
modify the value to 0xF0:
SCREENSHOT 3. Note the Return Delay Time value of 0xFA at
offset 10. This value represents a time of 500 µs. We’re going to
change that in Screenshot 4. There are 52 (0x34) bytes in the
status message following the byte at offset 3. The byte immediately
following the LENGTH byte (0x34) is the ERROR byte (0x00).
SERVO 05.2009
37