Commit of version on DVD.
authorMartin Prudek <prudemar@fel.cvut.cz>
Thu, 21 May 2015 20:42:50 +0000 (22:42 +0200)
committerMartin Prudek <prudemar@fel.cvut.cz>
Thu, 21 May 2015 20:42:50 +0000 (22:42 +0200)
pmsm-control/test_sw/Makefile
pmsm-control/test_sw/cmd_proc.c

index 8684cd7..73aeb4a 100644 (file)
@@ -23,8 +23,8 @@ build:
 
 #spoustime na desktopu
 #sestavi udp server
-server: main_ref_srv.o udp_srv.o
-       gcc -o server main_ref_srv.o udp_srv.o -lpthread
+pc_udp_server: main_ref_srv.o udp_srv.o
+       gcc -o pc_udp_server main_ref_srv.o udp_srv.o -lpthread
 
 #pro rpi
 #sestavi klienta s pouzitim wiringPi pro non-rt
@@ -33,14 +33,18 @@ client_wirpi: main_ctrl.o  udp_cli.o wir_Pi_api.o pid.o misc.o
 
 #pro rpi
 #sestavi klienta pro PREEMPT_RT
-client_rt: main_ctrl.o loc_pos_file.o udp_cli.o pid.o rpi_hw.o web_srv.o web_dat.o misc.o
-       gcc -o client main_ctrl.o udp_cli.o pid.o web_srv.o web_dat.o misc.o loc_pos_file.o rpi_hw.o  -lpthread -lrt
+rpi_udp_client_rt: main_ctrl.o loc_pos_file.o  misc.o udp_cli.o
+       gcc -o rpi_udp_client_dc_rt main_ctrl.o  misc.o loc_pos_file.o udp_cli.o  -lpthread -lrt
 
 #poustim z desktopu
 #prenese zdrojove kody klienta na raspberry
 scp:
        scp -rp ./ pi@10.0.0.22:/home/pi/motor
 
+#poustim z desktopu
+#prenese zdrojove kody klienta na raspberry B plus
+scpp:
+       scp -rp ./ pi@10.0.0.28:/home/pi/motor
 #poustime z RPi
 #sestavi "blikej" - jednoduchy testovaci nastroj
 blikej: howto_gpio.o rpi_hw.o 
@@ -51,3 +55,11 @@ spi: rp_spi.o
 #pro rpi
 pmsm: main_pmsm.o rp_spi.o rpi_hw.o misc.o pxmc_sin_fixtab.o cmd_proc.o controllers.o commutators.o comp.o logs.o pmsm_state.o
        gcc -o pmsm_controll main_pmsm.o rp_spi.o rpi_hw.o  misc.o pxmc_sin_fixtab.o cmd_proc.o controllers.o commutators.o comp.o logs.o pmsm_state.o -lpthread -lrt
+
+#udp capable pmsm control
+pmsm_udp: main_pmsm.o rp_spi.o rpi_hw.o misc.o pxmc_sin_fixtab.o cmd_proc.o controllers.o commutators.o comp.o logs.o pmsm_state.o udp_cli.o
+       gcc -o pmsm_controll main_pmsm.o rp_spi.o rpi_hw.o  misc.o pxmc_sin_fixtab.o cmd_proc.o controllers.o commutators.o comp.o logs.o pmsm_state.o udp_cli.o -lpthread -lrt
+
+#pro rpi
+rpi_udp_server_dc_rt: main_rpi_udp_server_dc_rt.o loc_pos_file.o  misc.o udp_srv.o
+       gcc -o rpi_udp_server_dc_rt main_rpi_udp_server_dc_rt.o  misc.o loc_pos_file.o udp_srv.o  -lpthread -lrt
index 66e9be8..f163602 100644 (file)
@@ -5,11 +5,41 @@
 #include "cmd_proc.h"
 #include "logs.h"
 
+/*
+ * UDP_CAPABLE definuje, zda je pouzeitelna moznost cteni
+ * referencnich informaci z jineho zarizeni po protokolu
+ * UDP. Jde zatim jen o testovaci rezim
+ */
+#define UDP_CAPABLE_X
+
+#ifdef UDP_CAPABLE
+#include "udp_cli.h"
+#include "misc.h"
+#include <pthread.h>
+#endif
+
+
 #define PRUM_PROUD     2061
 #define PRUM_SOUC      6183
 
 static char doPrint = 1;
 
+#ifdef UDP_CAPABLE
+static struct remote_pos_st remote_pos={
+               .stop=1
+};
+#endif
+
+/*
+ * zastavi cteni po UDP
+ */
+static inline void stop_udp_SEM(){
+       #ifdef UDP_CAPABLE
+       remote_pos.stop=1;
+       #endif
+}
+
+
 
 /*
  * \brief
@@ -26,6 +56,11 @@ static void printHelp(){
        puts("log - Spusti nebo ulozi logovani.");
        puts("ao:[hodnota] - Prenastavi alpha offset.");
 
+       #ifdef UDP_CAPABLE
+       puts("udp_pos:[ip] - Bude ridit pozici na hodnotu vzdaleneho zarizeni");
+       puts("udp_spd:[ip] - Bude ridit rychlost na hodnotu vzdaleneho zarizeni");
+       #endif
+
        puts("print - Zapne nebo vypne pravidelne vypisovani hodnot.");
        puts("help - Vypne vypisovani hodnot a zobrazi tuto napovedu.");
        puts("exit - Bezpecne ukonci program.");
@@ -60,6 +95,7 @@ static void start(struct rpi_state* state){
  * Zastavi komutaci, vypne pwm
  */
 static void stop(struct rpi_state* state){
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        setCommutationOff(state);
        setRegulationOff(state);
@@ -75,6 +111,7 @@ static void stop(struct rpi_state* state){
  * Nastavi pevnou sirku plneni
  */
 static void dutySet(struct rpi_state* state, int duty){
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        if (duty>MAX_DUTY) duty=MAX_DUTY;
        if (duty<-MAX_DUTY) duty=-MAX_DUTY;/*paranoia*/
@@ -89,6 +126,7 @@ static void dutySet(struct rpi_state* state, int duty){
  * Zapne rizeni na zvolenou polohu vztazenou k pozici pri startu
  */
 static void goAbsolute(struct rpi_state* state, int pos){
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        setRegulationPos(state);
        setCommutationOn(state);
@@ -120,6 +158,7 @@ static void exitApp(struct rpi_state* state){
 static void setSpeed(struct rpi_state* state, int speed){
        if (speed>MAX_SPEED) speed=MAX_SPEED;
        if (speed<-MAX_SPEED) speed=-MAX_SPEED;/*paranoia*/
+       stop_udp_SEM();
        sem_wait(&state->thd_par_sem);
        setRegulationSpeed(state);
        setCommutationOn(state);
@@ -159,6 +198,34 @@ static void setLogSEM(struct rpi_state* state){
        }
 }
 
+#ifdef UDP_CAPABLE
+static void  startUdpPos(struct rpi_state* state, char *ip){
+       pthread_t thread_id=pthread_self();
+       if (!remote_pos.stop) return; /*dont be reentrant*/
+       setCommutationOn(state);
+       setRegulationPos(state);
+       remote_pos.stop=0;
+       remote_pos.ip=ip;
+       remote_pos.factor=-5;
+       remote_pos.semaphore=&state->thd_par_sem;
+       remote_pos.rem_pos=&state->desired_pos;
+       create_rt_task(&thread_id,48,start_reading_remote_position,&remote_pos);
+}
+
+/*FIXME thers no max speed limit check!!! hard debug mode!! be careful*/
+static void  startUdpSpd(struct rpi_state* state, char *ip){
+       pthread_t thread_id=pthread_self();
+       if (!remote_pos.stop) return; /*dont be reentrant*/
+       setCommutationOn(state);
+       setRegulationSpeed(state);
+       remote_pos.stop=0;
+       remote_pos.ip=ip;
+       remote_pos.factor=-1;
+       remote_pos.semaphore=&state->thd_par_sem;
+       remote_pos.rem_pos=&state->desired_spd;
+       create_rt_task(&thread_id,48,start_reading_remote_position,&remote_pos);
+}
+#endif
 /**
  * \brief
  * Commands detection.
@@ -167,12 +234,14 @@ void poll_cmd(struct rpi_state* state){
        unsigned int tmp;
         char buff[50];
         char cmd[30];
+        char cmd2[30];
         int val;
 
         while(1){
                 scanf("%49s",buff);
                 delCol(buff);
                 sscanf(buff,"%s %d",cmd,&val);
+                sscanf(buff,"%s %s",cmd,cmd2);
 
 
                 if (!strcmp(cmd,"start")){
@@ -198,6 +267,15 @@ void poll_cmd(struct rpi_state* state){
                 }else if (!strcmp(cmd,"ao")){
                        setAlphaOff(state,val);
                 }
+               #ifdef UDP_CAPABLE
+                else if (!strcmp(cmd,"udp_pos")){
+                       startUdpPos(state,cmd2);
+                }else if (!strcmp(cmd,"udp_spd")){
+                       startUdpSpd(state,cmd2);
+
+                }
+               #endif
+
         }
 
 }