Go to Post Life isn't a set track: you have to go out and make your own path. - Greg Marra [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rating: Thread Rating: 6 votes, 5.00 average. Display Modes
  #1   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
  #2   Spotlight this post!  
Unread 01-21-2010, 04:51 PM
mattbutts mattbutts is offline
Registered User
FRC #1741 (Red Alert)
Team Role: Mentor
 
Join Date: Oct 2009
Rookie Year: 2009
Location: Greenwood, IN
Posts: 4
mattbutts is an unknown quantity at this point
Re: Black Jaguar RS232->CAN - anyone?

Quote:
Originally Posted by woodk View Post
...
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);

}
...
This is what I needed! Thanks!

I am assuming this will show up in the source code soon, but we are starting to test it now so I wanted to get something going.

Thanks again,
Matt
Reply With Quote
  #3   Spotlight this post!  
Unread 01-22-2010, 11:32 AM
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: Black Jaguar RS232->CAN - anyone?

Guys,

I'm attempting to add all the commands for speed and position using woodk's code below and ran into something interesting. If you look at Get() in CANJaguar.cpp:

float CANJaguar::Get()
{
UINT32 messageID;
UINT8 dataBuffer[8];
UINT8 dataSize;
INT32 replyValue32;

switch(m_controlMode)
{
case kPercentVoltage:
messageID = LM_API_VOLT_SET | m_deviceNumber;
// Sending set with no data is a request for the last set
...

The Get() method uses the LM_API_VOLT_SET API definition, but the Set() method uses the LM_API_VOLT_T_SET which is the FIRST trusted message version (I think). Does anyone know why this might be? Or does anyone know if this returns a correct value? I only just set up the CAN stuff yesterday and haven't gotten knee deep into debugging yet...

In can_proto.h:

//************************************************** ***************************
//
// The Luminary Micro Motor Class Control Voltage API definitions.
//
//************************************************** ***************************
#define LM_API_VOLT (CAN_MSGID_MFR_LM | CAN_MSGID_DTYPE_MOTOR | \
CAN_API_MC_VOLTAGE)
#define LM_API_VOLT_EN (LM_API_VOLT | (0 << CAN_MSGID_API_S))
#define LM_API_VOLT_DIS (LM_API_VOLT | (1 << CAN_MSGID_API_S))
#define LM_API_VOLT_SET (LM_API_VOLT | (2 << CAN_MSGID_API_S))
#define LM_API_VOLT_SET_RAMP (LM_API_VOLT | (3 << CAN_MSGID_API_S))

//##### FIRST BEGIN #####
#ifdef FIRST_FIRMWARE_VERSION
#define LM_API_VOLT_T_EN (LM_API_VOLT | (4 << CAN_MSGID_API_S))
#define LM_API_VOLT_T_SET (LM_API_VOLT | (5 << CAN_MSGID_API_S))
#endif // FIRST_FIRMWARE_VERSION
//##### FIRST END #####

- Bryce

P.S. Any thoughts on value used in the Position mode for Set() / Get()? In the GetPosition() declaration it states the return value as a float. Does this suggest that position is limited to only one revolution? Also, what data type would one pass to set the encoders?
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.

Last edited by Bryscus : 01-22-2010 at 11:40 AM.
Reply With Quote
  #4   Spotlight this post!  
Unread 01-22-2010, 01:56 PM
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: Black Jaguar RS232->CAN - anyone?

Ok, I sort of answered my own question. If there's anyone working on the methods of the API design, check out document SW-RDK-BDC-UG-5570.pdf which is located in the docs folder after installing the "RDK-BDC Firmware Development Package" located here: http://www.luminarymicro.com/products/mdl_bdc.html. You need to register to download the file. I'm not sure if I'm allowed to post it. It explains the command structure and also the data format that the Jags are expecting.

- Bryce
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.
Reply With Quote
  #5   Spotlight this post!  
Unread 01-22-2010, 03:01 PM
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
Exclamation Bug in Luminary Micro's Code

EDIT!!!!: OK, I talked with Joe Hershberger about this issue. Apparently they decided to stick with the code and change the Documentation. I guess the document has not been updated yet. I will keep this posted just in case anyone finds this error as well. So to repeat, the can_proto.h code is correct and should match the FIRST version of the Jag firmware.

woodk,

I might know why your current control is not working... At the section starting at line 119 in can_proto.h there appears to be a bug. If you refer to pages 21 and 22 of the "RDK-BDC Firmware Development Package User's Guide" they have a table of which bits to use for the API Classes. There are six bits that are assigned for telling the Jag which mode to operate in. The voltage and speed mode bit masks are correct, but the rest are off by one bit. Anyway, this is the code starting at line 119.

#define CAN_API_MC_VOLTAGE 0x00000000
#define CAN_API_MC_SPD 0x00000400
#define CAN_API_MC_POS 0x00000c00
#define CAN_API_MC_ICTRL 0x00001000
#define CAN_API_MC_STATUS 0x00001400
#define CAN_API_MC_CFG 0x00001c00
#define CAN_API_MC_ACK 0x00002000

What I believe to be the correct code is below:

#define CAN_API_MC_VOLTAGE 0x00000000
#define CAN_API_MC_SPD 0x00000400
#define CAN_API_MC_POS 0x00000800
#define CAN_API_MC_ICTRL 0x00000C00
#define CAN_API_MC_STATUS 0x00001000
#define CAN_API_MC_CFG 0x00001400
#define CAN_API_MC_ACK 0x00001800

Try this and see if your current control works. Bits, bits everywhere...

- Bryce

P.S. THANKS JOE!
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.

Last edited by Bryscus : 01-22-2010 at 03:35 PM.
Reply With Quote
  #6   Spotlight this post!  
Unread 01-22-2010, 04:25 PM
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: Black Jaguar RS232->CAN - anyone?

Hi Guys,

I think this is the last remaining method to implement speed control (with an encoder). I will test all of this tomorrow to see if it all works (along with woodk's code). Sorry about all the posts, I've been working on this a bit today. The following code is the method to tell the Jag the number of lines of the encoder (per revolution) attached to it. If you want you can just remove the kPosition. I've written the functions for that as well by using woodk's code as a blueprint (and the manual). If one needs to set the number of turns on a potentiometer attached to a motor (position mode only), just replace LM_API_CFG_ENC_LINES with LM_API_CFG_POT_TURNS (that should work).

void SetEncoder(UINT16 encoderLines);

void CANJaguar::SetEncoder(UINT16 encoderLines)
{
UINT32 messageID;
UINT8 dataBuffer[8];
UINT8 dataSize;

switch(m_controlMode)
{
case kPercentVoltage:
//Do nothing. An encoder is not used during Voltage mode
return;
case kSpeed:
case kPosition:
messageID = LM_API_CFG_ENC_LINES | m_deviceNumber;
*((UINT16*)dataBuffer) = swap16(encoderLines);
dataSize = sizeof(UINT16);
break;
default:
return;
}

sendMessage(messageID, dataBuffer, dataSize);
}

- Bryce
__________________
The opulence of the front office decor varies inversely with the fundamental solvency of the firm.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Serial to CAN Gateway in new Black Jaguars? dmcguire3006 Electrical 54 01-26-2010 07:32 AM
Release Announcement for the MDL-BDC24 (Black Jaguar) JDNovak FRC Control System 2 12-16-2009 06:13 PM
The Black Jaguar David Doerr FRC Control System 5 11-25-2009 03:43 PM
Can I control a victor/jaguar with an RC receiver Bruceb Electrical 3 12-30-2008 10:50 AM
Will ANYONE mess with the black balls? archiver 2001 0 06-23-2002 10:35 PM


All times are GMT -5. The time now is 10:55 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi