Remora - ethernet NVEM cnc board

More
09 Apr 2023 11:34 #268663 by meister
Hi,
my c skills are a little rusty and i can not compile your code on Linux,
but i thing something like this is a little bit faster (no funtion calls).
void makeSteps()
{
    static int8_t i;
    static int32_t stepNow;

    // loop through the step generators
    for (i = 0; i <= JOINTS; i++)
    {
        stepNow = 0;
        isEnabled[i] = ((rxData.jointEnable & (1 << i)) != 0);

        if (isEnabled[i] == true)
        {
            frequencyCommand[i] = rxData.jointFreqCmd[i];
            DDSaddValue[i] = frequencyCommand[i] * frequencyScale;
            stepNow = DDSaccumulator[i];
            DDSaccumulator[i] += DDSaddValue[i];
            stepNow ^= DDSaccumulator[i];
            stepNow &= (1L << STEPBIT);
            rawCount[i] = DDSaccumulator[i] >> STEPBIT;

            if (DDSaddValue[i] > 0)
            {
                isForward[i] = true;
            }
            else
            {
                isForward[i] = false;
            }

            if (stepNow)
            {
                // GPIO_PinWrite(STEP_PORT, dirPin[i], isForward[i]);
                if (isForward[i] == true) {
                    base->DR_SET = (1<<dirPin[i]);
                } else {
                    base->DR_CLEAR = (1<<dirPin[i]);
                }
                // GPIO_PinWrite(STEP_PORT, stepPin[i], 1);
                base->DR_SET = (1<<stepPin[i]);
                txData.jointFeedback[i] = DDSaccumulator[i];
                isStepping[i] = true;
            }
        }
    }
}


void resetSteps()
{
    static int8_t i;

    for (i = 0; i <= JOINTS; i++)
    {
        if (isStepping[i])
        {
            // GPIO_PinWrite(STEP_PORT, stepPin[i], 0);
            base->DR_CLEAR = (1<<stepPin[i]);
        }
    }
}

and i think disabling all IRQ's is not a good idea

[/code]
        __disable_irq();

        // then move the data
        for (int i = 0; i < BUFFER_SIZE; i++)
        {
            rxData.rxBuffer = rxBuffer.rxBuffer;
        }

        // re-enable thread interrupts
        __enable_irq();

[code]




 

Please Log in or Create an account to join the conversation.

More
09 Apr 2023 16:37 #268686 by cakeslob
Ohhhhh that looks sweet. The ballscrew/rail size difference was larger than I expected. Beautiful.


The disabling interrupts, Im fairly sure is to correct a bigger issue (i call it melting axis). My new thing is, when in doubt, add deadband and pgain

Please Log in or Create an account to join the conversation.

More
09 Apr 2023 16:44 #268688 by meister
i get the compilation work on my system

if i reduce the freq of this threads, the jitter is much much better !

#define PRU_BASEFREQ 20000 // PRU Base thread ISR update frequency (hz)
#define PRU_SERVOFREQ 500 // PRU Servo thread ISR update freqency (hz)

Please Log in or Create an account to join the conversation.

More
09 Apr 2023 18:30 #268700 by meister
moving code from servo thread into main loop.

that's much better for me:
--- a/remora-rt1052/source/baseThread.c
+++ b/remora-rt1052/source/baseThread.c
@@ -93,8 +93,8 @@ void updateBaseThread()
 
 void makeSteps()
 {
-    int8_t i;
-    int32_t stepNow;
+    static int8_t i;
+    static int32_t stepNow;
 
     // loop through the step generators
     for (i = 0; i <= JOINTS; i++)
@@ -123,8 +123,12 @@ void makeSteps()
 
             if (stepNow)
             {
-                GPIO_PinWrite(STEP_PORT, dirPin[i], isForward[i]);
-                GPIO_PinWrite(STEP_PORT, stepPin[i], 1);
+                if (isForward[i] == true) {
+                    STEP_PORT->DR_SET = (1<<dirPin[i]);
+                } else {
+                    STEP_PORT->DR_CLEAR = (1<<dirPin[i]);
+                }
+                STEP_PORT->DR_SET = (1<<stepPin[i]);
                 txData.jointFeedback[i] = DDSaccumulator[i];
                 isStepping[i] = true;
             }
@@ -135,13 +139,13 @@ void makeSteps()
 
 void resetSteps()
 {
-    int8_t i;
+    static int8_t i;
 
     for (i = 0; i <= JOINTS; i++)
     {
         if (isStepping[i])
         {
-            GPIO_PinWrite(STEP_PORT, stepPin[i], 0);
+            STEP_PORT->DR_CLEAR = (1<<stepPin[i]);
         }
     }
 }
diff --git a/remora-rt1052/source/configuration.h b/remora-rt1052/source/configuration.h
index 9482d64..5d7d9a2 100644
--- a/remora-rt1052/source/configuration.h
+++ b/remora-rt1052/source/configuration.h
@@ -1,8 +1,8 @@
 #ifndef CONFIGURATION_H
 #define CONFIGURATION_H
 
-#define PRU_BASEFREQ        40000            // PRU Base thread ISR update frequency (hz)
-#define PRU_SERVOFREQ       1000            // PRU Servo thread ISR update freqency (hz)
+#define PRU_BASEFREQ        60000            // PRU Base thread ISR update frequency (hz)
+#define PRU_SERVOFREQ       10            // PRU Servo thread ISR update freqency (hz)
 
 #define STEPBIT             22                // bit location in DDS accum
 #define STEP_MASK           (1L<<STEPBIT)
diff --git a/remora-rt1052/source/ethernet.c b/remora-rt1052/source/ethernet.c
index bb9d591..866b88e 100644
--- a/remora-rt1052/source/ethernet.c
+++ b/remora-rt1052/source/ethernet.c
@@ -127,13 +127,11 @@ void udp_data_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip
 
         // ensure an atomic access to the rxBuffer
         // disable thread interrupts
+
         __disable_irq();
 
         // then move the data
-        for (int i = 0; i < BUFFER_SIZE; i++)
-        {
-            rxData.rxBuffer[i] = rxBuffer.rxBuffer[i];
-        }
+        memcpy(rxData.rxBuffer, rxBuffer.rxBuffer, BUFFER_SIZE);
 
         // re-enable thread interrupts
         __enable_irq();
diff --git a/remora-rt1052/source/remora-rt1052.c b/remora-rt1052/source/remora-rt1052.c
index 549d54d..74cc253 100644
--- a/remora-rt1052/source/remora-rt1052.c
+++ b/remora-rt1052/source/remora-rt1052.c
@@ -207,6 +207,10 @@ int main(void)
         }
 
         EthernetTasks();
+        readInputs();
+        setOutputs();
+
+
     }
 }
 
diff --git a/remora-rt1052/source/remora.h b/remora-rt1052/source/remora.h
index 7f9e1b5..00af8b9 100644
--- a/remora-rt1052/source/remora.h
+++ b/remora-rt1052/source/remora.h
@@ -5,6 +5,8 @@
 
 #pragma pack(push, 1)
 
+
+
 typedef union
 {
   // this allow structured access to the incoming SPI data without having to move it
diff --git a/remora-rt1052/source/servoThread.c b/remora-rt1052/source/servoThread.c
index 49648f2..f923e4a 100644
--- a/remora-rt1052/source/servoThread.c
+++ b/remora-rt1052/source/servoThread.c
@@ -136,10 +136,10 @@ void configServoThread()
 void updateServoThread()
 {
     monitorEthernet();
-    readInputs();
-    setOutputs();
+    //readInputs();
+    //setOutputs();
     updatePWM();
-    updateNVMPG();
+    //updateNVMPG();
 }

Please Log in or Create an account to join the conversation.

More
09 Apr 2023 21:40 - 09 Apr 2023 21:41 #268716 by zmrdko
Is anybody else experiencing slow approach to exact position as well on ec500? (rt1052)

Last edit: 09 Apr 2023 21:41 by zmrdko.

Please Log in or Create an account to join the conversation.

More
09 Apr 2023 22:24 #268720 by scotta

moving code from servo thread into main loop.

that's much better for me:

--- a/remora-rt1052/source/baseThread.c
+++ b/remora-rt1052/source/baseThread.c
@@ -93,8 +93,8 @@ void updateBaseThread()
 
 void makeSteps()
 {
-    int8_t i;
-    int32_t stepNow;
+    static int8_t i;
+    static int32_t stepNow;
 
     // loop through the step generators
     for (i = 0; i <= JOINTS; i++)
@@ -123,8 +123,12 @@ void makeSteps()
 
             if (stepNow)
             {
-                GPIO_PinWrite(STEP_PORT, dirPin[i], isForward[i]);
-                GPIO_PinWrite(STEP_PORT, stepPin[i], 1);
+                if (isForward[i] == true) {
+                    STEP_PORT->DR_SET = (1<<dirPin[i]);
+                } else {
+                    STEP_PORT->DR_CLEAR = (1<<dirPin[i]);
+                }
+                STEP_PORT->DR_SET = (1<<stepPin[i]);
                 txData.jointFeedback[i] = DDSaccumulator[i];
                 isStepping[i] = true;
             }
@@ -135,13 +139,13 @@ void makeSteps()
 
 void resetSteps()
 {
-    int8_t i;
+    static int8_t i;
 
     for (i = 0; i <= JOINTS; i++)
     {
         if (isStepping[i])
         {
-            GPIO_PinWrite(STEP_PORT, stepPin[i], 0);
+            STEP_PORT->DR_CLEAR = (1<<stepPin[i]);
         }
     }
 }
diff --git a/remora-rt1052/source/configuration.h b/remora-rt1052/source/configuration.h
index 9482d64..5d7d9a2 100644
--- a/remora-rt1052/source/configuration.h
+++ b/remora-rt1052/source/configuration.h
@@ -1,8 +1,8 @@
 #ifndef CONFIGURATION_H
 #define CONFIGURATION_H
 
-#define PRU_BASEFREQ        40000            // PRU Base thread ISR update frequency (hz)
-#define PRU_SERVOFREQ       1000            // PRU Servo thread ISR update freqency (hz)
+#define PRU_BASEFREQ        60000            // PRU Base thread ISR update frequency (hz)
+#define PRU_SERVOFREQ       10            // PRU Servo thread ISR update freqency (hz)
 
 #define STEPBIT             22                // bit location in DDS accum
 #define STEP_MASK           (1L<<STEPBIT)
diff --git a/remora-rt1052/source/ethernet.c b/remora-rt1052/source/ethernet.c
index bb9d591..866b88e 100644
--- a/remora-rt1052/source/ethernet.c
+++ b/remora-rt1052/source/ethernet.c
@@ -127,13 +127,11 @@ void udp_data_callback(void *arg, struct udp_pcb *upcb, struct pbuf *p, const ip
 
         // ensure an atomic access to the rxBuffer
         // disable thread interrupts
+
         __disable_irq();
 
         // then move the data
-        for (int i = 0; i < BUFFER_SIZE; i++)
-        {
-            rxData.rxBuffer[i] = rxBuffer.rxBuffer[i];
-        }
+        memcpy(rxData.rxBuffer, rxBuffer.rxBuffer, BUFFER_SIZE);
 
         // re-enable thread interrupts
         __enable_irq();
diff --git a/remora-rt1052/source/remora-rt1052.c b/remora-rt1052/source/remora-rt1052.c
index 549d54d..74cc253 100644
--- a/remora-rt1052/source/remora-rt1052.c
+++ b/remora-rt1052/source/remora-rt1052.c
@@ -207,6 +207,10 @@ int main(void)
         }
 
         EthernetTasks();
+        readInputs();
+        setOutputs();
+
+
     }
 }
 
diff --git a/remora-rt1052/source/remora.h b/remora-rt1052/source/remora.h
index 7f9e1b5..00af8b9 100644
--- a/remora-rt1052/source/remora.h
+++ b/remora-rt1052/source/remora.h
@@ -5,6 +5,8 @@
 
 #pragma pack(push, 1)
 
+
+
 typedef union
 {
   // this allow structured access to the incoming SPI data without having to move it
diff --git a/remora-rt1052/source/servoThread.c b/remora-rt1052/source/servoThread.c
index 49648f2..f923e4a 100644
--- a/remora-rt1052/source/servoThread.c
+++ b/remora-rt1052/source/servoThread.c
@@ -136,10 +136,10 @@ void configServoThread()
 void updateServoThread()
 {
     monitorEthernet();
-    readInputs();
-    setOutputs();
+    //readInputs();
+    //setOutputs();
     updatePWM();
-    updateNVMPG();
+    //updateNVMPG();
 }[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]

 

This breaks the intent of Remora which runs two threads, one which is in sync with LinuxCNC. The servo thread. No need to read inputs / set output and process Ethernet (which won't be present) faster than needed to match the 1000ms LinuxCNC thread.

Have you tried increasing the P gain to see if that removes the "jitter". 

Please Log in or Create an account to join the conversation.

More
09 Apr 2023 22:26 #268721 by scotta

Is anybody else experiencing slow approach to exact position as well on ec500? (rt1052)

Yes, this is solved by adding a Pgain setting. The default gain is 1, increasing it to 10 or more will improve the response of the control loop.

Please Log in or Create an account to join the conversation.

More
09 Apr 2023 22:31 #268723 by scotta

i get the compilation work on my system

if i reduce the freq of this threads, the jitter is much much better !

#define PRU_BASEFREQ 20000 // PRU Base thread ISR update frequency (hz)
#define PRU_SERVOFREQ 500 // PRU Servo thread ISR update freqency (hz)

Did you also change the servo frequency in LinuxCNC and inform the Remora component about the different base thread frequency? If not the frequency command calculations are all out and the control loop will be working harder to compensate for the wacky following error. Changing these settings in the firmware must be mirrored on the LinuxCNC side.

Please Log in or Create an account to join the conversation.

More
10 Apr 2023 02:46 - 10 Apr 2023 02:54 #268738 by frayja2002
Just a quick update.

Here is the list of pins i have checked on an RT-1053 based NVEM box.

Scott, could you tell me where (if anywhere) to other output pins go to.

Thanks
Alex
Attachments:
Last edit: 10 Apr 2023 02:54 by frayja2002.
The following user(s) said Thank You: cnc-phil

Please Log in or Create an account to join the conversation.

More
10 Apr 2023 06:11 #268743 by scotta

Just a quick update.

Here is the list of pins i have checked on an RT-1053 based NVEM box.

Scott, could you tell me where (if anywhere) to other output pins go to.

Thanks
Alex

Hi Alex, that's it for the NVEM / EC300. The extra outputs are available on the EC500.

Please Log in or Create an account to join the conversation.

Time to create page: 0.365 seconds
Powered by Kunena Forum