View Single Post
  #5   Spotlight this post!  
Unread 25-02-2010, 14:14
JasonStern JasonStern is offline
Mentor
FRC #1123 (AIM Robotics)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Arlington, VA
Posts: 65
JasonStern is on a distinguished road
Re: CAN Jaguar enhancements

Quote:
Originally Posted by Bryscus View Post
First of all, I don't see what would keep you from switching control types on the fly. The control method of the Jag is set AFTER initialization.
In the Java code, there is no method to set the control type.

Quote:
Originally Posted by Bryscus View Post
Secondly, why do you need feedback if you're in open loop mode? This is a contradiction. If you receive feedback your are by definition in a closed loop mode.
Receiving feedback in and of itself does not place you in closed loop; you have to be using the feedback to change the input value before you have closed the loop. For example, if you write your current speed to a spreadsheet but don't use the value anywhere else (like we are doing for the motor calibration code), you are still in an open loop.

Wiring the feedback values into the Jags as opposed to the crio provides more versatility in that you can change control modes without having to rewire. You might also be in a position where you want the Jag itself to run in an open loop and want to implement the controller on the crio instead.

Quote:
Originally Posted by Bryscus View Post
I wonder to what modification are you referring?
I made three main changes:
1. Removed the checks for which control type you are in when setting the references
2. Add a method to change the control type
3. Added code to add sync functionality

Note: this worked a few times and then stopped working, so I would not recommend using this code without testing!!! The diff is based off of rev 50.

CANJaguar.java:
Code:
--- C:/temp/CANJaguarOld.java	Thu Feb 25 13:28:27 2010
+++ C:/temp/CANJaguar.java	Thu Feb 25 13:38:01 2010
@@ -268,6 +268,10 @@
      * @param outputValue The set-point to sent to the motor controller.
      */
     public void set(double outputValue) {
+        this.set(outputValue, LM_API_SYNC_GROUP_NONE);
+    }
+
+    public void set(double outputValue, short syncGroup) {
         int messageID = 0;
         byte[] dataBuffer = new byte[8];
         byte dataSize = 0;
@@ -296,6 +300,12 @@
             default:
                 return;
         }
+
+        if(syncGroup != LM_API_SYNC_GROUP_NONE){
+            dataBuffer[dataSize] = (byte) syncGroup;
+            dataSize += 1;
+        }
+
         setTransaction(messageID, dataBuffer, dataSize);
     }
 
@@ -510,6 +520,19 @@
     }
 
     /**
+     * Sets the controller mode. Control will be automatically disabled when this method is called.
+     * 
+     * @param controlMode
+     */
+    public void setControlMode(CANJaguar.ControlMode controlMode ){
+        if(!m_controlMode.equals(controlMode)){
+            disableControl();
+            m_controlMode = controlMode;
+            initJaguar();
+        }
+    }
+
+    /**
      * Set the reference source device for speed controller mode.
      *
      * Choose encoder as the source of speed feedback when in speed control mode.
@@ -517,18 +540,10 @@
      *
      * @param reference Specify a SpeedReference.
      */
-    private void setSpeedReference(SpeedReference reference) {
+    public void setSpeedReference(SpeedReference reference) {
         byte[] dataBuffer = new byte[8];
-
-        switch (m_controlMode.value) {
-            case ControlMode.kSpeed_val:
                 dataBuffer[0] = reference.value;
                 setTransaction(LM_API_SPD_REF, dataBuffer, (byte) 1);
-                break;
-            default:
-                // TODO: Error, Invalid
-                return;
-        }
     }
 
     /**
@@ -541,16 +556,14 @@
      */
     public void setPositionReference(PositionReference reference) {
         byte[] dataBuffer = new byte[8];
-
-        switch (m_controlMode.value) {
-            case ControlMode.kPosition_val:
                 dataBuffer[0] = reference.value;
                 setTransaction(LM_API_POS_REF, dataBuffer, (byte) 1);
-                break;
-            default:
-                // TODO: Error, Invalid
-                return;
         }
+
+    public void syncUpdate(short syncGroup){
+        byte[] dataBuffer = new byte[8];
+        dataBuffer[0] = (byte) syncGroup;
+        sendMessage(CAN_MSGID_API_SYNC, dataBuffer, (byte) 1);
     }
 
     /**
JaguarCANProtocol.java:
Code:
--- C:/temp/JaguarCANProtocolOld.java	Thu Feb 25 13:29:27 2010
+++ C:/temp/JaguarCANProtocol.java	Mon Feb 22 15:09:27 2010
@@ -131,6 +131,16 @@
     //
     //*****************************************************************************
     public static final int LM_API_SYNC_PEND_NOW   = 0;
+    public static final short LM_API_SYNC_GROUP_NONE   = 0x00;
+    public static final short LM_API_SYNC_GROUP_1   = 0x01;
+    public static final short LM_API_SYNC_GROUP_2   = 0x02;
+    public static final short LM_API_SYNC_GROUP_3   = 0x04;
+    public static final short LM_API_SYNC_GROUP_4   = 0x08;
+    public static final short LM_API_SYNC_GROUP_5   = 0x10;
+    public static final short LM_API_SYNC_GROUP_6   = 0x20;
+    public static final short LM_API_SYNC_GROUP_7   = 0x40;
+    public static final short LM_API_SYNC_GROUP_8   = 0x80;
+    public static final short LM_API_SYNC_GROUP_ALL   = 0xFF;
 
     //*****************************************************************************
     //
__________________
Que será será
Reply With Quote