Transmitting Control Torques
Control inputs for the four joints in each finger should be packed in a single CAN frame. The sample
code below demonstrates how to encode four PWM inputs into an 8 byte data buffer and how to set
the CAN frame ID properly.
Code 6: Transmitting Control Torques
long
Txid;
unsigned char
data[8];
float
torque2pwm = 800.0f
short
pwm[4] = {
0.1*torque2pwm,
0.1*torque2pwm,
0.1*torque2pwm,
0.1*torque2pwm
};
if
(findex >= 0 && findex < 4)
{
data[0] =
(unsigned
data[1] =
(unsigned
data[2] =
(unsigned
data[3] =
(unsigned
data[4] =
(unsigned
data[5] =
(unsigned
data[6] =
(unsigned
data[7] =
(unsigned
Txid =
((unsigned
long)(ID_CMD_SET_TORQUE_1 + findex)<<6) |
canWrite(hCAN, Txid, data, 8, STD);
}
Copyright 2008-2012 SimLab Co., Ltd. All rights reserved.
A L L E G R O H A N D U S E R S M A N U A L
char)( (pwm[0] >> 8) & 0x00ff);
char)(pwm[0] & 0x00ff);
char)( (pwm[1] >> 8) & 0x00ff);
char)(pwm[1] & 0x00ff);
char)( (pwm[2] >> 8) & 0x00ff);
char)(pwm[2] & 0x00ff);
char)( (pwm[3] >> 8) & 0x00ff);
char)(pwm[3] & 0x00ff);
((unsigned
long)ID_COMMON <<3) |
((unsigned
long)ID_DEVICE_MAIN);
29
Need help?
Do you have a question about the Allegro Hand and is the answer not in the manual?
Questions and answers