View Single Post
  #6   Spotlight this post!  
Unread 26-02-2010, 17:35
Bryscus's Avatar
Bryscus Bryscus is offline
EE, CpE
AKA: Bryce B.
FRC #0180 (SPAM)
Team Role: Engineer
 
Join Date: Jan 2009
Rookie Year: 1999
Location: Jupiter, FL
Posts: 173
Bryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud ofBryscus has much to be proud of
Re: CAN Jaguar enhancements

Jason,

Let me apologize first. I was apparently having a long day and misspoke a number of times. I see what you are trying to do now and also must say that the mode is also set at initialization for C++ as well - I remembered incorrectly. I must warn you that I do not have any Java experience, so if there are any weird errors that are logical because of syntax I probably won't be able to spot them.

To preface my post, I am referencing Rev. 50 and 29 of the CANJaguar.java and JaguarCANDriver.java files, respectively located on the firstforge page.

Well, then. Let me begin:

1.) I'm not quite sure why you chose to make your LM_API_SYNC_GROUP_...(s) of type short and not byte. I do see that you cast them to a byte, but why not just keep them as bytes to begin with. Either way, unless there's some weird casting issue in Java, the group ID portion should still work just fine.

2.) In public void setControlMode(), you disableControl as you should. Do you make sure you re-enable control? You should also set up your encoder references again just to be safe and probably the number of lines too (couldn't hurt).

At this point, your code seems to look pretty good to me at least for switching modes. Next is my 2 bits for why your synchronous updates don't work.

1.) Your code looks good to me. I've delved into the bit masks and everything seems fine. Here's where it gets interesting. I'm willing to bet that the problem lies within the JaguarCANDriver.sendMessage() method that we can't see. Here is "protected void sendMessage(int messageID, byte[] data, int dataSize)":

Code:
 protected void sendMessage(int messageID, byte[] data, int dataSize) {
        final int[] kTrustedMessages = {
            LM_API_VOLT_T_EN, LM_API_VOLT_T_SET, LM_API_SPD_T_EN, LM_API_SPD_T_SET,
            LM_API_POS_T_EN, LM_API_POS_T_SET, LM_API_ICTRL_T_EN, LM_API_ICTRL_T_SET};

        byte i;
        for (i = 0; i < kTrustedMessages.length; i++) {
            if ((kFullMessageIDMask & messageID) == kTrustedMessages[i]) {
                sendTrustedDataBuffer[0] = 0;
                sendTrustedDataBuffer[1] = 0;
                // Make sure the data will still fit after adjusting for the token.
                if (dataSize > JaguarCANDriver.kMaxMessageDataSize - 2) {
                    // TODO: Error
                    return;
                }

                byte j;
                for (j = 0; j <
                        dataSize; j++) {
                    sendTrustedDataBuffer[j + 2] = data[j];
                }

                JaguarCANDriver.sendMessage(messageID, sendTrustedDataBuffer, dataSize + 2);
                return;
            }
        }
        JaguarCANDriver.sendMessage(messageID, data, dataSize);
    }
If you notice, the trusted messages are matched with constant values. This means that for trusted messages, the messageID does not contain the Device ID, otherwise the if statement with kTrustedMessages[i] would never be true. This means that JaguarCANDriver.sendMessage() must add the Device ID to the message that it sends (from m_deviceNumber). Normally this is fine, but this is BAD when you want to send a SYNC message that probably requires a Device ID value of 0. You might want to try setting m_deviceNumber to 0 before you send the sync command. So try:

Code:
    public void syncUpdate(short syncGroup){
        byte[] dataBuffer = new byte[8];
        dataBuffer[0] = (byte) syncGroup;
        //temporarily store m_deviceNumber;
        //set m_deviceNumber = 0;
        sendMessage(CAN_MSGID_API_SYNC, dataBuffer, (byte) 1);
        //restore m_deviceNumber to previous value;
    }
Again, I don't know the Java syntax so there's the pseudo-code.

Anyway, I think these are your problems. I have not implemented these changes in C++ yet, but I do have the plan to do so. I'll email Joe Hershberger about these potential issues. I've been looking at this code for 2-3 hours now so I think I'll just give it a rest for now.

I'm sorry if some of this doesn't make sense, but I'll try to answer any other questions that I can.

- Bryce

P.S. What is the status of the LEDs when your system stops working?
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.

Last edited by Bryscus : 26-02-2010 at 18:24.
Reply With Quote