Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
authorlaurent
Thu, 23 Feb 2012 23:34:40 +0100
changeset 2036 7c31fab22c74
parent 2035 1d113faf4433
child 2037 d54036f70390
Adding support for setting TargetPosition only if PositionSetPoint value from MCL is valid
etherlab/plc_ds402node.c
etherlab/plc_etherlab.c
--- a/etherlab/plc_ds402node.c	Thu Feb 23 15:48:19 2012 +0100
+++ b/etherlab/plc_ds402node.c	Thu Feb 23 23:34:40 2012 +0100
@@ -131,5 +131,10 @@
 	    	break;
 	}
 
-	*(__DS402Node_%(location)s.TargetPosition) = (IEC_DINT)(__DS402Node_%(location)s.axis->PositionSetPoint * __DS402Node_%(location)s.axis->RatioNumerator / __DS402Node_%(location)s.axis->RatioDenominator);
+	if (__DS402Node_%(location)s.axis->CSP && *(__DS402Node_%(location)s.ModesOfOperationDisplay) == 0x08) {
+		*(__DS402Node_%(location)s.TargetPosition) = (IEC_DINT)(__DS402Node_%(location)s.axis->PositionSetPoint * __DS402Node_%(location)s.axis->RatioNumerator / __DS402Node_%(location)s.axis->RatioDenominator);
+	}
+	else {
+		*(__DS402Node_%(location)s.TargetPosition) = *(__DS402Node_%(location)s.ActualPosition);
+	}
 }
--- a/etherlab/plc_etherlab.c	Thu Feb 23 15:48:19 2012 +0100
+++ b/etherlab/plc_etherlab.c	Thu Feb 23 23:34:40 2012 +0100
@@ -16,6 +16,8 @@
   #include "iec_std_lib.h"
 #endif
 
+extern unsigned long long common_ticktime__;
+
 // declaration of interface variables
 %(located_variables_declaration)s
 
@@ -70,6 +72,8 @@
         return -1;
     }
 
+	ecrt_master_set_send_interval(master, common_ticktime__);
+
 %(slaves_initialization)s
 
     sprintf(&rt_dev_file[0],"%%s%%u",EC_RTDM_DEV_FILE_NAME,0);
@@ -111,16 +115,16 @@
 
 void __retrieve_%(location)s(void)
 {
+    // send process data
+    ecrt_rtdm_domain_queque(rt_fd);
+    ecrt_rtdm_master_send(rt_fd);
+
+    rt_task_sleep(rt_timer_ns2tsc(wait_period_ns));
+
     // receive ethercat
     ecrt_rtdm_master_recieve(rt_fd);
     ecrt_rtdm_domain_process(rt_fd);
 
-    rt_task_sleep(rt_timer_ns2tsc(wait_period_ns));
-
-    // send process data
-    ecrt_rtdm_domain_queque(rt_fd);
-    ecrt_rtdm_master_send(rt_fd);
-
 %(retrieve_variables)s
 }