View Single Post
  #7   Spotlight this post!  
Unread 01-21-2010, 09:45 AM
woodk woodk is offline
Registered User
FRC #2809
 
Join Date: Jan 2009
Location: Kingston, Ontario, Canada
Posts: 31
woodk has a spectacular aura aboutwoodk has a spectacular aura aboutwoodk has a spectacular aura about
Re: Black Jaguar RS232->CAN - anyone?

Quote:
Originally Posted by mattbutts View Post
We are also looking at this. I was planning to have one of the students on our team write the functionality for the speed control mode, but I am having a hard time finding the structure for the different CAN messages.

Specifically, looking through the code, it looks like the only trusted messages listed are for enabling different modes and setting their target. In speed control, we would need to know what the messages look like for defining the P and I gains as well as the encoder information.

Unless these can be set in the Jaguar using the BDCOM utility and will stick through power cycles.

Anyone know where I can find this information?
I couldn't find this information anywhere, so I used a program to monitor the serial port while BDCOM is running. From this, I modified CANJaguar.cpp and was able to get speed control working (I think). I haven't added the method to set the number of encoder lines yet, so I don't know what "units" the speed is in. I haven't got current mode working. The values sent by DBComm seem to be somewhat random, and the "control" does not seem to work anyway. Current control on the Jaguars with the original firmware (not updated with FRC firmware) seems to work (form bdc-comm-cli.exe) , but the updated ones do not ... I don't know if there is a new command or way of sending the current setpoints ... I guess we'll have to see if they release updated code samples.

You need to add new "case"s for kSpeed to InitJaguar, Set (and Get if you want). In Set, the case I added is: (set speed uses a 16.16 signed fixed point number)
case kSpeed:
messageID = LM_API_SPD_T_SET | m_deviceNumber;
INT32 value32 = (INT32)(outputValue*65536.0 );
*((INT32*)dataBuffer) = swap32(value32);
dataSize = sizeof(INT32);
break;

I also added a method to set the PID constants:

/**
* Set the Jaguar PID constants.
*
* The inputs are any floating point values
*
* @param outputValue The P I and D constants for the motor control.
*/
void CANJaguar::SetPIDConstants(float kp, float ki, float kd)
{
UINT32 messageID;
UINT8 dataBuffer[8];
UINT8 dataSize;

// Send Kp:
switch(m_controlMode)
{
case kCurrent:
messageID = LM_API_ICTRL_PC | m_deviceNumber;
break;
case kSpeed:
messageID = LM_API_SPD_PC | m_deviceNumber;
break;
default:
;
}
INT32 value = (INT32)(kp*65536.0);
*((INT32*)dataBuffer) = swap32(value);
dataSize = sizeof(INT32);
sendMessage(messageID, dataBuffer, dataSize);

// Send Ki:
switch(m_controlMode)
{
case kCurrent:
messageID = LM_API_ICTRL_IC | m_deviceNumber;
break;
case kSpeed:
messageID = LM_API_SPD_IC | m_deviceNumber;
break;
default:
;
}
value = (INT32)(ki*65536.0);
*((INT32*)dataBuffer) = swap32(value);
dataSize = sizeof(INT32);
sendMessage(messageID, dataBuffer, dataSize);

// Send Kd:
switch(m_controlMode)
{
case kCurrent:
messageID = LM_API_ICTRL_DC | m_deviceNumber;
break;
case kSpeed:
messageID = LM_API_SPD_DC | m_deviceNumber;
break;
default:
;
}
value = (INT32)(kd*65536.0);
*((INT32*)dataBuffer) = swap32(value);
dataSize = sizeof(INT32);
sendMessage(messageID, dataBuffer, dataSize);

}


Hope this helps. Have fun!

- Kevin
Reply With Quote