]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
Merge branch 'master' of vokacmic@rtime.felk.cvut.cz:/var/git/eurobot
authorMichal Vokac <vokac.m@gmail.com>
Wed, 28 Apr 2010 17:49:38 +0000 (19:49 +0200)
committerMichal Vokac <vokac.m@gmail.com>
Wed, 28 Apr 2010 17:49:38 +0000 (19:49 +0200)
src/common/can_ids.h
src/disp-4dgl/Display2010.4XE [new file with mode: 0644]
src/disp-4dgl/Display2010.4dg [new file with mode: 0644]
src/eb_vidle/fsm.h
src/eb_vidle/fsm_vidle.c
src/eb_vidle/main.c
src/eb_vidle/vhn.c [deleted file]
src/eb_vidle/vhn.h [deleted file]
src/robofsm/homologation.cc

index ca9b039c3a18bae589d4d30a867c8a78bcd85439..73d2631d24914c14890191ee575ab5d814536755 100644 (file)
@@ -35,6 +35,9 @@
 #define CAN_MOTION_ODOMETRY_SIMPLE to_boa(0x22) /* MOT->BOA */
 #define CAN_MOTION_STATUS          to_boa(0x23) /* MOT->BOA */
 
+
+
+#define CAN_BUMPER             to_boa(0x30)
 // ids of can-peripherials
 #define CAN_CHELAE to_per(0x32)          /**< BOA->PER @copydetails set_chelae() front view  1st B  left,  2nd B right */ 
 #define CAN_ADC_1 to_boa(0x33)          /* PER->BOA */
diff --git a/src/disp-4dgl/Display2010.4XE b/src/disp-4dgl/Display2010.4XE
new file mode 100644 (file)
index 0000000..c097a37
Binary files /dev/null and b/src/disp-4dgl/Display2010.4XE differ
diff --git a/src/disp-4dgl/Display2010.4dg b/src/disp-4dgl/Display2010.4dg
new file mode 100644 (file)
index 0000000..dfb463f
--- /dev/null
@@ -0,0 +1,805 @@
+#platform "uOLED-32028-PMD3T"
+
+// Note that 4DGL has built in sine table, this is just for #DATA access example.
+
+#inherit "4DGL_16bitColours.fnc"
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+#CONST                                          
+    LEFT 15
+    TOP  15
+    // tables
+    V_TAB   4   //number of rectangles
+    MAX_WIDTH   239
+    MAX_HEIGHT  319
+    LAST_ROW    19
+    VOLT_HEIGHT 30
+    VOLT_WIDTH  59// width for voltage color field
+    BUTTONWIDTH 60 
+    BUTTONHEIGHT 30
+
+    // positions
+    VOLT    0
+    VOLT1   1
+    STATE   2
+    NMB_BT  8
+#END
+
+
+#CONST
+    NO               0
+    YES              1
+    Y                2
+    X                1   
+#END
+
+
+#DATA
+    // button Y positions for control page
+    word dY 3,33,63,93,123,153,183,213,293
+    word colors RED,GREEN,ORANGE
+    word collor BLUE,BLUE,CRIMSON,CRIMSON,YELLOW,YELLOW,GREEN,INDIGO,GRAY
+    byte commands 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88
+    byte Text_row 0,2,3
+    byte Text_col 1,0
+    byte Text_pos 1,6,11,16,1,6,11,16
+    byte rec_pos_X 0,60,120,180 
+    byte rec_pos_Y 18,48,66,96
+    byte rec_X 1,61,121,181,1,61,121,181 
+    byte rec_Y 67,67,67,67,97,97,97,97
+    byte comm_chars '-', '|', '/', '-', '\\', '|'
+#END
+
+#CONST
+   COMPS       0x81
+   VOLTAGES    0x82
+   MAIN_FSM    0x83
+   MOVE_FSM    0x84
+   ACT_FSM     0x85
+   LOCATION    0x86
+   KEEPALIVE   0x87
+   CORNS       0x88 
+   DRESS       0x89
+#END
+
+
+#CONST
+    MOT     0
+    ODO     1
+    CAM     2
+    PWR     3
+    HOK     4
+    APP     5
+    VID     6
+    STA     7
+#END
+
+
+#CONST
+    VOLT33      0
+    VOLT50      1
+    VOLT80      2
+    VOLT_BAT    3
+#END
+
+
+var RX_buffer[200];//var work_buffer[200];
+// voltage strings 
+var voltage_3V3[4];
+var voltage_5V0[4];
+var voltage_8V0[4];
+var voltage_BAT[5];
+// states strings
+var act_fsm_state[20];
+var move_fsm_state[20];
+var main_fsm_state[20];
+// pozition
+var position[9];
+var voltages[17];
+var comp_state[10];
+
+
+
+var firstState, firstCtrl;
+var keyval, page;        // - 1 if no key pressed else 0-15
+var BT_text[10];
+var BT_state[10];
+var BT_OLDstate[10];
+var names[8];
+var buffer[100];//[30];
+var comp_collor;
+var volt_state;
+var corns;
+var states;
+var rx_ch,index,id;
+var comm_idx;
+var dress_color;
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func data_init()
+   var idx;
+   idx := 0;
+   repeat 
+      voltages[idx] := 'x';
+      idx++;
+   until(idx == 17);
+  
+   position[0] := 'x';
+   position[1] := 'x';
+   position[2] := 'x';
+   position[3] := 'y';
+   position[4] := 'y';
+   position[5] := 'y';
+   position[6] := 'a';
+   position[7] := 'a';
+   position[8] := 'a';
+   
+    
+// component names array
+      act_fsm_state[0] := 'I';
+      act_fsm_state[1] := 'n';
+      act_fsm_state[2] := 'i';
+      act_fsm_state[3] := 't';
+      act_fsm_state[4] := '\0';
+
+      move_fsm_state[0] := 'I';
+      move_fsm_state[1] := 'n';
+      move_fsm_state[2] := 'i';
+      move_fsm_state[3] := 't';
+      move_fsm_state[4] := '\0';
+
+      main_fsm_state[0] := 'I';
+      main_fsm_state[1] := 'n';
+      main_fsm_state[2] := 'i';
+      main_fsm_state[3] := 't';
+      main_fsm_state[4] := '\0';
+      
+      names[0] := "MOT";
+      names[1] := "ODO";
+      names[2] := "CAM";
+      names[3] := "PWR";
+      names[4] := "HOK";
+      names[5] := "APP";
+      names[6] := "VID";
+      names[7] := "STA";
+
+    idx := 0;
+    repeat
+        comp_state[idx] := (idx+1) & 0x0f;
+        idx++;    
+    until(idx==8);
+    corns := 0;
+  
+    dress_color := BLUE;
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_voltage()//select variable is chooseing which voltage will be rewrite. CAN BE VALUE 0, to 5. 5 is ALL
+    var cntX, cntY, x, y, v_tab, idx;
+    cntX:=0;
+    cntY:=0;    
+    v_tab:=4;
+    gfx_Set(PEN_SIZE, 1);     
+    //draw table
+    gfx_Rectangle(0, 0, MAX_WIDTH, 18, WHITE);//table
+    while(cntX < v_tab)
+        x := rec_pos_X[cntX];
+        y := rec_pos_Y[cntY];  
+        gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
+        cntX++;
+    wend
+    //write legend
+    gfx_Set(PEN_SIZE, 0);     
+    txt_Set(FONT_SIZE, 3);
+    txt_Set(TEXT_COLOUR, GRAY);
+    txt_Set(TEXT_OPACITY, 0); 
+    txt_MoveCursor(Text_row[VOLT],0);
+    print ("Voltage indicator:");
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+func redraw_voltage()//(var voltage)
+    var idx, color; 
+    gfx_Set(PEN_SIZE, 0);   
+    txt_Set(TEXT_COLOUR, BLACK);
+    color := RED;
+    if((voltages[0] & 0x08) != 0x08)
+        color := GREEN;
+    endif    
+    gfx_Rectangle(1, 19, 58, 47, color);//table
+    txt_MoveCursor(2,0);
+    print([CHR]voltages[1], [CHR]voltages[2],".", [CHR]voltages[3],[CHR]voltages[4], "\n");
+    color := RED;    
+    if((voltages[0] & 0x04) != 0x04)
+        color := GREEN;
+    endif
+    gfx_Rectangle(61,19,118,47, color);//table
+    txt_MoveCursor(2,5);
+    print([CHR]voltages[5], [CHR]voltages[6],".", [CHR]voltages[7],[CHR]voltages[8], "\n");
+    color := RED;    
+    if((voltages[0] & 0x02) != 0x02)
+        color := GREEN; 
+    endif
+    gfx_Rectangle(121, 19, 178,47, color);//table
+    txt_MoveCursor(2,10);
+    print([CHR]voltages[9], [CHR]voltages[10], ".",[CHR]voltages[11],[CHR]voltages[12], "\n");
+    color := RED;    
+    if((voltages[0] & 0x01) != 0x01)
+        color := GREEN;
+    endif
+    gfx_Rectangle(181,19,238, 47, color);//table
+    txt_MoveCursor(2,15);
+    print([CHR]voltages[13],[CHR]voltages[14], ".",[CHR]voltages[15],[CHR]voltages[16], "\n");
+    paint_voltage();
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_comm()
+   gfx_Set(PEN_SIZE, 1);//table     
+   gfx_Rectangle(180, 174, 239, 192, WHITE);//table
+   txt_MoveCursor(11,15);
+   txt_Set(TEXT_COLOUR, GRAY);
+   print("Comm:");
+endfunc
+
+
+
+func redraw_comm()
+   if(comm_idx >= 6)
+        comm_idx := 0;
+   endif      
+   gfx_Set(PEN_SIZE, 0);//solid rec     
+   gfx_Rectangle(181, 191, 238, 221, GREEN);//table
+   txt_MoveCursor(13,17);
+   txt_Set(TEXT_COLOUR, BLACK);
+   print([CHR]comm_chars[comm_idx]);
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+   
+func draw_error()
+   sys_SetTimer(0,3000);
+   gfx_Set(PEN_SIZE, 0);//solid rec     
+   gfx_Rectangle(181, 191, 238, 221, BLACK);//table
+   txt_MoveCursor(13,16);
+   txt_Set(TEXT_COLOUR, RED);
+   print("ERR");
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_comp_state(var data)
+    var Y_axes, X_axes,X_end, Y_end, comp_nmb, col_idx, text_Y;
+    comp_nmb := ((data & 0x1f)-1);   
+    col_idx := (data & 0x60) >> 5;
+    if((comp_nmb >7)||(col_idx > 2) ||comp_nmb<0)
+        return;
+    endif
+    Y_axes := rec_Y[comp_nmb];
+    X_axes := rec_X[comp_nmb];
+    X_end := X_axes + 57;
+    Y_end := Y_axes + 28;
+    text_Y := 5;
+    if(comp_nmb >3)
+        text_Y := 7;
+    endif    
+    gfx_Set(PEN_SIZE, 0);//solid rectangle     
+    gfx_Rectangle(X_axes, Y_axes, X_end, Y_end, colors[col_idx]);//table
+    txt_MoveCursor(text_Y,Text_pos[comp_nmb]); 
+    txt_Set(TEXT_COLOUR, BLACK);   
+    print([STR]names[comp_nmb]);
+    comp_state[comp_nmb] := data;
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_comp_states(var select)
+    var cntX,cntY,x,y, v_tab, row;
+    cntX := 0;
+    cntY := 1;
+    row := 0;
+    v_tab:=4;
+    gfx_Set(PEN_SIZE, 1);     
+    //draw table for components
+    gfx_Rectangle(0, rec_pos_Y[cntY], MAX_WIDTH, 66, WHITE);//table
+    cntY++;    
+      while(cntX < v_tab)
+         x := rec_pos_X[cntX];
+         y := rec_pos_Y[cntY];  
+         gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
+         cntX++;
+      wend
+      cntY := 3;
+      cntX := 0;
+      while(cntX < v_tab)
+         x := rec_pos_X[cntX];
+         y := rec_pos_Y[cntY];  
+         gfx_Rectangle(x, y, x+VOLT_WIDTH, y+VOLT_HEIGHT, WHITE);//table
+         cntX++;
+      wend
+    txt_MoveCursor(Text_row[STATE],0);
+    txt_Set(TEXT_COLOUR, GRAY);
+    print("Component indicator:")
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_corn()
+    gfx_Set(PEN_SIZE, 1);//table     
+    gfx_Rectangle(180, 126, 239, 222, WHITE);//table
+    gfx_Rectangle(180, 126, 239, 144, WHITE);//table
+    gfx_Rectangle(179, 126, 239, 222, WHITE);//table
+    txt_MoveCursor(8,15);
+    txt_Set(TEXT_COLOUR, GRAY);
+    print("Corn:")
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_corns()    
+    txt_MoveCursor(10,17);
+    txt_Set(TEXT_COLOUR, BLACK);
+    gfx_Set(PEN_SIZE, 0);//solid rectangle     
+    gfx_Rectangle(181, 145, 237, 173, dress_color);//table
+    print(corns&0x0f);
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_move_state()    
+    var idx;    
+    gfx_Set(PEN_SIZE, 0);//table     
+    gfx_Rectangle(0, 159, 178, 190, BLACK);//table
+    txt_MoveCursor(10,0);
+    txt_Set(TEXT_COLOUR, OLIVE);
+    idx :=0;
+    print("MO:");    
+    repeat
+       if(idx == 11)
+            print("-\n   ");
+       endif
+       putch(move_fsm_state[idx]);
+       idx++;
+    until(move_fsm_state[idx] == '\0');    
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_act_state()
+    var idx;
+    gfx_Set(PEN_SIZE, 0);//table     
+    gfx_Rectangle(0, 191, 178, 221, BLACK);//table
+    txt_MoveCursor(12,0);
+    txt_Set(TEXT_COLOUR, BROWN);
+    idx :=0;
+    print("AC:");    
+    repeat
+       if(idx == 11)
+            print("-\n   ");
+       endif
+       putch(act_fsm_state[idx]);
+       idx++;
+    until(act_fsm_state[idx] == '\0');    
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_main_state()
+    var idx;
+    idx :=0;
+    gfx_Rectangle(0, 127, 178, 158, BLACK);//table
+    txt_MoveCursor(8,0);
+    txt_Set(TEXT_COLOUR, TEAL);
+    gfx_Set(PEN_SIZE, 0);//table     
+    print("MA:");    
+    repeat
+       if(idx == 11)
+            print("-\n   ");
+       endif
+       putch(main_fsm_state[idx]);
+       idx++;
+    until(main_fsm_state[idx] == '\0');    
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func paint_position()
+    gfx_Set(PEN_SIZE, 0);//solid rectangle     
+    gfx_Rectangle(0, 223, 239, 255, MAGENTA);//table
+    gfx_Rectangle(0, 256, 239, 291, MAGENTA);//table
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw_position()
+    gfx_Set(PEN_SIZE, 0);//solid rectangle     
+    gfx_Rectangle(60, 239, 110, 255, MAGENTA);//table
+    gfx_Rectangle(160, 239, 220, 255,MAGENTA);//table
+    gfx_Rectangle(0, 272, 47, 286, MAGENTA);//table
+    txt_MoveCursor(14,0); 
+    txt_Set(TEXT_COLOUR, BLACK);   
+    print("Position:\n X = ", [CHR]position[0],".",[CHR]position[1],[CHR]position[2]);
+    print(" Y = ", [CHR]position[3],".",[CHR]position[4], [CHR]position[5], "\n");
+    print("Angle: ","\n"," ", [CHR]position[6],[CHR]position[7],[CHR]position[8]," Deg \n");
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func draw_keys()
+    var i;
+    i:=0;
+    repeat
+      gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT2, 2, 2, BT_text[i]);
+    until(++i == NMB_BT);
+    gfx_Button(BT_state[i], 3, dY[i], collor[i], BLACK, FONT1, 2, 2, BT_text[i]);
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func redraw()
+   if(keyval == 8)//||(keyval == 8))//do nothing
+      return; 
+   endif
+   if(keyval < 10)
+      gfx_Button(BT_state[keyval], 3, dY[keyval], collor[keyval], BLACK, FONT2, 2, 2, BT_text[keyval]);
+   endif
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+func send_cmd()
+   if(keyval == 8)//do nothing
+      return; 
+   endif
+   if(keyval < 9)
+      to(COM0);
+      putch(commands[keyval]);
+      to(TEXT);
+   endif
+endfunc
+//*********************************************************************************************
+//*********************************************************************************************
+
+func read_key()
+    var x, y;
+    y := touch_Get(Y);
+    y := y / (BUTTONHEIGHT+1);
+    keyval := y;
+    if(keyval == 8)
+        keyval := -1;
+    endif
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func clear_page()
+    gfx_Set(0,0);
+    gfx_Rectangle(0,0,MAX_WIDTH,MAX_HEIGHT,BLACK);
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+// function for debugging only
+func send_axis()
+    var y;
+    y := touch_Get(Y);
+    txt_MoveCursor(16,1);
+    to(COM0),print(y);
+    to(COM0),print("\n"); 
+    to(COM0),print(keyval);
+    to(COM0),print("\n"); 
+endfunc
+
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func read_serial()
+      var cnt_idx;  
+      rx_ch := serin();
+      if(rx_ch < 0)
+          goto out;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if((rx_ch & 0x80) == 0x80)
+          id := rx_ch;
+          index:=0;
+      if (id == KEEPALIVE)
+          sys_SetTimer(0,3000);// 3 seconds  
+          comm_idx++;  
+          redraw_comm();
+          id:=0;
+      endif;
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if (index < 100)    // 100 is buffer capacity
+          RX_buffer[index] := rx_ch;
+          index++;
+      else
+          index := 0;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if(id == COMPS && index == 1)
+          redraw_comp_state(RX_buffer[0]);//draw_status();
+          id:=0;
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if(id == CORNS)// && index == 1)
+          corns := RX_buffer[0];  
+          redraw_corns();//draw_status();
+          id:=0;
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if(id == ACT_FSM && rx_ch == '\0')
+          cnt_idx := 0;
+          repeat    
+             act_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
+             cnt_idx++;
+          until(RX_buffer[cnt_idx] == '\0')
+          act_fsm_state[cnt_idx] := '\0';
+          redraw_act_state();
+          id:=0;
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if(id == MOVE_FSM && rx_ch == '\0')
+          cnt_idx := 0;
+          repeat    
+             move_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
+             cnt_idx++;
+          until(RX_buffer[cnt_idx] == '\0')
+          move_fsm_state[cnt_idx] := '\0';
+          redraw_move_state();
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if(id == MAIN_FSM && rx_ch == '\0')
+          cnt_idx := 0;
+          repeat    
+             main_fsm_state[cnt_idx] := RX_buffer[cnt_idx];
+             cnt_idx++;
+          until(RX_buffer[cnt_idx] == '\0')
+          main_fsm_state[cnt_idx] := '\0';
+          redraw_main_state();
+          id:=0;
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if (id == VOLTAGES && index == 17)
+         cnt_idx :=0;   
+         repeat    
+            voltages[cnt_idx] := RX_buffer[cnt_idx];
+            cnt_idx++;
+         until(cnt_idx == 17)
+         redraw_voltage();
+         id:=0;
+         goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if(id == LOCATION && index == 9)
+          cnt_idx := 0;
+          repeat
+              position[cnt_idx] := RX_buffer[cnt_idx];
+              cnt_idx++;
+          until(cnt_idx == 9)          
+          redraw_position();
+          id:=0;
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+      if(id == DRESS && index == 1)
+          if(RX_buffer[0] == 1)  
+              dress_color := YELLOW;
+          endif
+          if(RX_buffer[0] == 0)  
+              dress_color := BLUE;
+          endif
+              redraw_corns();
+              id:=0;
+          goto out;//return;
+      endif
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
+out:
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func STATE_page()
+    var state, cnt,idx1,tmr;
+    sys_SetTimer(0,3000);
+    paint_voltage();
+    cnt:=0;
+    redraw_voltage();
+    paint_comp_states(0);
+    paint_corn();
+    com_Init(buffer,100,0);
+    cnt := 0;                   //draw states for all components
+    repeat
+        redraw_comp_state(comp_state[cnt]);
+    until(cnt++ == 8)
+    paint_position();
+    redraw_position();
+    redraw_corns();
+    redraw_main_state();
+    redraw_move_state();
+    redraw_act_state();
+    paint_comm();
+    redraw_comm();
+
+    gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLACK,FONT1,2,2, " To control screen ");
+    touch_DetectRegion(0, MAX_HEIGHT-30, MAX_WIDTH, MAX_HEIGHT);
+    touch_Set(TOUCH_ENABLE);
+    repeat
+        state := touch_Get(TOUCH_STATUS);
+        if(state == TOUCH_PRESS)
+            gfx_Button(DOWN,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");
+        endif
+        if(state == TOUCH_RELEASE)
+            gfx_Button(UP,0, MAX_HEIGHT-27, GRAY, BLUE,FONT1, 2, 2, " To control screen ");
+            page := 1;
+            break;
+        endif
+        read_serial(); 
+        if(sys_GetTimer(0) == 0)
+            idx1 := 0;
+            repeat
+                idx1++;  
+                comp_state[idx1] := idx1;  
+            until(idx1==8);
+            cnt := 0;                   //draw states for all components
+            repeat
+                redraw_comp_state(comp_state[cnt]);
+            until(cnt++ == 8)
+            draw_error();
+        endif
+    forever
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+
+func CTRL_page()
+    var n, state, x;
+    n :=0;
+    keyval := -1;  // initate key value
+    BT_text[0] := "  FORK DOWN   ";    //set texts for all buttons
+    BT_text[1] := "  FORK UP     ";
+    BT_text[2] := "  DOOR OPEN   ";
+    BT_text[3] := "  DOOR CLOSE  ";
+    BT_text[4] := "  START ROLL  ";
+    BT_text[5] := "  STOP ROLL   ";
+    BT_text[6] := "SEND ALL STATE";
+    BT_text[7] := " SWITCH COLOR ";
+    BT_text[8] := "  To state screen  ";
+    touch_Set(TOUCH_ENABLE);          // enable the touch screen                
+    touch_DetectRegion(0, 0, MAX_WIDTH, MAX_HEIGHT);
+//*********************************************************************************************
+    repeat  
+       BT_state[n] := UP;           //set state for all buttons
+       BT_OLDstate[n] := DOWN;
+    until(++n == 9);   
+//*********************************************************************************************
+    draw_keys();
+    repeat 
+    sys_SetTimer(0,3000);
+        state := touch_Get(TOUCH_STATUS);
+        if(state == TOUCH_PRESS)
+           read_key();
+        //   send_axis();     //debugging only   
+           if(keyval != -1)
+              if(keyval == 10 || keyval == 9)
+                  BT_state[8] := DOWN;
+                  gfx_Button(BT_state[8], 3, dY[8], collor[8], BLUE, FONT1, 2, 2, BT_text[8]);// misto redraw();
+              else    
+                 BT_state[keyval] := DOWN; // set that button is pushed
+                 redraw();
+              endif;    
+           endif
+        endif
+        if(state == TOUCH_RELEASE)
+            if(keyval != -1)
+                BT_state[keyval] := UP; //button was released
+                page := 0;
+                redraw();
+                if(keyval == 10 || keyval == 9)
+                    gfx_Button(BT_state[8], 3, dY[8], collor[8], BLACK, FONT1, 2, 2, BT_text[8]);// misto redraw();
+                    keyval := -1;
+                    break;
+                endif;    
+                send_cmd();
+            endif
+        endif
+    forever
+endfunc
+
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+//*********************************************************************************************
+
+func main()
+    page := 0;
+    firstState := 0;
+    firstCtrl := 0;
+    comp_collor := RED;
+    data_init();
+    voltages[0]:=0xff;// voltage color initate
+    comm_idx := 3;
+
+    repeat
+        if(!page)// view state page
+            clear_page();    
+            STATE_page();
+        else// view ctrl page
+            clear_page();            
+            CTRL_page();
+        endif    
+    forever        
+endfunc
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
index d3a74320c040f9f5fea0cd69b28d39327f901631..8e5cbdf1b46664c98b43ca01bcde045b285354fc 100644 (file)
@@ -21,6 +21,7 @@ struct fsm {
        int32_t act_pos;                        // actual position
        int32_t req_pos;                        // requested position
        volatile uint32_t can_req_position;     // next requested position
+       int32_t start_pos;
        uint32_t can_response;                  // when the move is done, the value here equals to the req_pos
        uint8_t flags;   //< CAN flags bits (defined in can_msg_def.h)
        uint32_t time_start;    /* For timeout detection */
index 634de205b81c89b3ef993a68db49c591739e69c3..7529e5c0c9a35b9eaca52bd40697a755304a3cb2 100644 (file)
@@ -8,6 +8,7 @@
 #include <engine.h>
 #include <stdbool.h>
 #include "def.h"
+#include <adc.h>
 
 #define DBG_ENTRY() do {                       \
                send_rs_str(__func__);          \
@@ -29,6 +30,7 @@ void fsm_vidle_init(struct fsm *fsm, enum event event)
                /* TODO: Homing */
                fsm->flags &= ~CAN_VIDLE_INITIALIZING;
                fsm->current_state = wait_for_cmd;
+               fsm->act_pos = adc_val[0];
                break;
        case EVENT_EXIT:
                break;
@@ -41,18 +43,27 @@ static void stop()
        engine_A_en(ENGINE_EN_OFF);
 }
 
+
+#define DEAD_ZONE      10
 static bool do_control(struct fsm *fsm)
 {
+       bool finished;
        int e = fsm->req_pos - fsm->act_pos;
-       int P = 1;
-       int action = P*e;
+       int P = 2;
+       int action = (P*e) / 10;                // ORIGINAL: int action = P*e;
 
 
        engine_A_dir(action < 0);
        engine_A_pwm(action > 0 ? action : -action);
        engine_A_en(ENGINE_EN_ON);
 
-       return false;           /* TODO: Determine end of move */
+
+       if (fsm->req_pos > fsm->start_pos)
+               finished = fsm->act_pos > fsm->req_pos - DEAD_ZONE;
+       else
+               finished = fsm->act_pos < fsm->req_pos + DEAD_ZONE;
+
+       return finished;
 }
 
 static void wait_for_cmd(struct fsm *fsm, enum event event)
@@ -63,6 +74,7 @@ static void wait_for_cmd(struct fsm *fsm, enum event event)
                stop();
                break;
        case EVENT_DO:
+               do_control(fsm);
                if (fsm->can_req_position != fsm->req_pos) {
                        fsm->req_pos = fsm->can_req_position;
                        fsm->current_state = move;
@@ -80,7 +92,7 @@ static void move(struct fsm *fsm, enum event event)
        case EVENT_ENTRY:
                DBG_ENTRY();
                fsm->time_start = timer_msec;
-               fsm->flags = CAN_VIDLE_TIMEOUT;
+               fsm->start_pos = fsm->act_pos;
                break;
        case EVENT_DO:
                if (timer_msec - fsm->time_start > 1000) {
index 398a70e7ff6d33129b34c8fd09e25dd438ec1d1a..9b87f9e8f4ba6bb3c8e7d7763f8c5f0242fe2118 100644 (file)
 #include <deb_led.h>
 #include "engine.h"    
 #include "uar.h"
-#include "vhn.h"
 #include <can_msg_def.h>
 #include "fsm.h"
 #include "def.h"
+#include <adc.h>
 
 #define        CAN_SPEED       1000000         //< CAN bus speed
 #define CAN_ISR                0
 
+#define ADC_ISR                1
+
 #define TIMER_IRQ_PRIORITY     5
 
 
@@ -47,6 +49,8 @@ struct fsm fsm_vidle;
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 
+
+
 void init_motors(void){
   
        init_engine_A();                        // initialization of PWM unit
@@ -99,6 +103,63 @@ void timer0_irq() {
        VICVectAddr = 0;
 }
 
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+uint8_t start_bt = 0;
+uint32_t time_start = 0;
+uint8_t start_cnt = 0;
+#define START_PIN      15              // start pin
+#define START_TIME     16
+
+
+void start_button(void)
+{
+       can_msg_t msg; 
+       if (start_bt > 10) 
+       {
+               if ((IO0PIN & (1<<START_PIN))==0) 
+               {       
+                 start_bt = 0;
+                 start_cnt = 0;
+               }
+               return;
+       }
+       
+       if (time_start == 0) time_start = timer_msec + START_TIME;      
+       
+       
+
+       if (timer_msec > time_start)
+       {
+               time_start = timer_msec + START_TIME;
+               
+               if (IO0PIN & (1<<START_PIN)) 
+               {
+                       ++start_cnt;
+                       if(start_cnt > 3)
+                       {
+                         ++start_bt;
+                         msg.data[0] = 1;
+                         deb_led_off(LEDY);
+                       }
+               }
+               else 
+               {
+                       deb_led_on(LEDY);
+                       msg.data[0] = 0;
+                       start_cnt = 0;
+               }
+
+               msg.id = CAN_ROBOT_CMD;
+               msg.flags = 0;
+               msg.dlc = 1;
+               while (can_tx_msg(&msg));
+       }
+}
+
+
+//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 void CAN_rx(can_msg_t *msg) {
        can_msg_t rx_msg;
        uint32_t req =0;
@@ -133,7 +194,9 @@ void init_periphery(void){
        set_irq_handler(4 /*timer0*/, TIMER_IRQ_PRIORITY, timer0_irq);
 
        init_uart();
-/*     vhn_init(); */  // What is VHN? -MS
+       init_adc(ADC_ISR);
+       
+       
 } 
 /*********************************************************/
 void can_send_status(void)
@@ -147,7 +210,7 @@ void can_send_status(void)
     tx_msg.data[2] = (fsm_vidle.can_response  >> 8) & 0xFF;
     tx_msg.data[3] = fsm_vidle.can_response & 0xFF;
     tx_msg.data[4] = fsm_vidle.flags; 
-    while(can_tx_msg(&tx_msg)); /* CAN erratum workaround */
+    /*while*/(can_tx_msg(&tx_msg)); /* CAN erratum workaround */
 }
 
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -169,6 +232,11 @@ void dbg_print_time()
 
 void fsm_vidle_init(struct fsm *fsm, enum event event);
 
+
+
+
+#define BUMPER_PIN     17              // bumper pin  (SCK1)
+
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -176,6 +244,7 @@ int main(void)
 {
        uint32_t main_time = timer_usec;
        uint32_t led_time = timer_msec;
+       uint32_t bumper_time = timer_msec;
        uint32_t CAN_time = timer_msec;
        
 
@@ -183,27 +252,42 @@ int main(void)
        
        init_fsm(&fsm_vidle, &fsm_vidle_init);
 
-       /* TODO: Add comment */
-       SET_PIN(PINSEL1, 1, PINSEL_0);
-       SET_PIN(PINSEL1, 3, PINSEL_0);
+       /* TODO: Add comment FIXME: zkusit smazat, mam moct ze to melo neco spojeneho s chelae z eb09  */
+       //SET_PIN(PINSEL1, 1, PINSEL_0);
+       //SET_PIN(PINSEL1, 3, PINSEL_0);
+       
+       
+       
+       
+       SET_PIN(PINSEL0, START_PIN, PINSEL_0);          // inicializace start pinu
+       SET_PIN(PINSEL0, 0, PINSEL_0);          // inicializace bumper pinu (FIXME SET_PIN je BLBA implemetace, musim ji nekdy opravit)
+       
+       
+       IO0DIR &= ~((1<<START_PIN) | (1<<BUMPER_PIN));
        
        IO1DIR &= ~(3<<20);
        
        send_rs_str("Vidle started\n");
+       // The above send_rs_str is importat - we wait for the first AD conversion to be finished
+       fsm_vidle.can_req_position = adc_val[0];
        
        while(1){
+         
+               start_button();
                if(timer_usec >= main_time + 1000)
                {
                        main_time = timer_usec;
 
-                       dbg_print_time();
+                       //dbg_print_time();
 
                        /* TODO: Precti potak a uloz ho do fsm_vidle.act_pos */
+                       fsm_vidle.act_pos = adc_val[0];
+                       
                    
                        run_fsm(&fsm_vidle);
                }
 
-#if 0
+#if 1
                if (timer_msec >= CAN_time + 100 || //repeat sending message every 100 ms
                    fsm_vidle.trigger_can_send) {   //or when something important happen
                        fsm_vidle.trigger_can_send = false;
@@ -214,9 +298,34 @@ int main(void)
 #endif 
                if(timer_msec >= led_time + 500)        
                {
-                       led_time = timer_msec;
+               /*  static int up;
+                 if (up == 0)
+                       fsm_vidle.can_req_position = 0x380;
+                 if (up == 6)
+                       fsm_vidle.can_req_position = 0x1e0;
+                 up = (up+1)%12;
+               */      led_time = timer_msec;
                        deb_led_change(LEDG);
+               send_rs_int(fsm_vidle.act_pos);
+               send_rs_str("\n");
+               }
+               
+               if(timer_msec >= bumper_time + 100)     
+               {
+                       can_msg_t tx_msg;
+                       tx_msg.id = CAN_BUMPER;
+                       tx_msg.dlc = 1;
+                       tx_msg.flags = 0;
+                       
+                       if (IO0PIN & (1<<START_PIN))
+                           tx_msg.data[0] = 1;
+                       else
+                           tx_msg.data[0] = 0;
+                       
+                       can_tx_msg(&tx_msg); /* CAN erratum workaround */
                }
+               
+               
        }
 }
 
diff --git a/src/eb_vidle/vhn.c b/src/eb_vidle/vhn.c
deleted file mode 100644 (file)
index 0a82d76..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#include <lpc21xx.h>                            /* LPC21xx definitions */
-#include <deb_led.h>
-#include <system_def.h>        
-#include <can_ids.h>
-#include <periph/can.h>
-#include <string.h>
-#include <deb_led.h>
-#include "serv.h"
-#include "engine.h"    
-#include "lift.h"
-#include "uar.h"
-#include "def.h"
-#include "vhn.h"
-
-
-void vhn_init(void)
-{
-       PINSEL2 &= ~(3<<2);
-       IO1DIR |= (VHN_EN_A | VHN_EN_B | VHN_IN_A | VHN_IN_B);
-       IO1SET = (VHN_EN_A | VHN_EN_B | VHN_IN_A | VHN_IN_B);
-}
-
-void vhn_speed(uint8_t speed, uint8_t dir) {
-  
-    if(speed == 0)
-    {
-      IO1CLR = (VHN_IN_A | VHN_IN_B);
-      return;
-    }
-  
-    if(dir == ENGINE_DIR_FW)
-    {
-       IO1SET = VHN_IN_A;
-       IO1CLR = VHN_IN_B;
-    }
-    else
-    {
-       IO1CLR = VHN_IN_A;
-       IO1SET = VHN_IN_B;
-    }
-    
-    IO1SET = (VHN_EN_A | VHN_EN_A);
-    engine_B_pwm(speed);
-      
-}
diff --git a/src/eb_vidle/vhn.h b/src/eb_vidle/vhn.h
deleted file mode 100644 (file)
index 6b41625..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef  __VHN_H
-#define  __VHN_H
-
-  #define VHN_EN_A             (1<<16)
-  #define VHN_EN_B             (1<<17)
-  #define VHN_IN_A             (1<<18)
-  #define VHN_IN_B             (1<<19)
-
-
-    void vhn_init(void);
-    void vhn_speed(uint8_t speed, uint8_t dir);
-
-       
-       
-
-
-#endif /*__VHN_H*/
index f1e7d0f77f421a0dcb1a3932f7a1aed49b55340a..26e1d38d46e3f2741cbe42ec190c9dc1dad31bb2 100644 (file)
@@ -107,6 +107,7 @@ FSM_STATE_DECL(climb_the_slope);
 FSM_STATE_DECL(sledge_down);
 FSM_STATE_DECL(to_container_diag);
 FSM_STATE_DECL(to_container_ortho);
+FSM_STATE_DECL(experiment);
 
 /************************************************************************
  * INITIAL AND STARTING STATES
@@ -306,6 +307,41 @@ FSM_STATE(to_container_ortho)
        }
 }
 
+static int cnt = 0;
+FSM_STATE(experiment)
+{
+       switch(FSM_EVENT) {
+               case EV_ENTRY: {
+                               double x, y, phi;
+                               robot_get_est_pos(&x, &y, &phi);
+                               printf("experiment: puck cnt: %d, est pos %.3f, %.3f, %.3f\n",
+                                       cnt, x, y, phi);
+                               struct corn * corn = choose_next_corn();
+                               Pos *p = get_corn_approach_position(corn /*&robot.corns->corns[cnt++]*/);
+                               corn->was_collected = true;
+                               //robot_trajectory_new(&tcFast);
+                               //robot_trajectory_add_final_point_trans(robot_trajectory_add_final_point_trans(p->x, p->y, TURN(p->phi));
+                               robot_goto_trans(p->x, p->y, TURN(p->phi), &tcFast);
+                               delete(p);
+                               break;
+                       }
+               case EV_MOTION_DONE:
+                       FSM_TRANSITION(experiment);
+                       break;
+               case EV_START:
+               case EV_TIMER:
+               case EV_RETURN:
+               case EV_ACTION_DONE:
+               case EV_ACTION_ERROR:
+               case EV_GOAL_NOT_REACHABLE:
+                       DBG_PRINT_EVENT("unhandled event");
+               case EV_EXIT:
+                       break;
+       }
+}
+
+
+
 /************************************************************************
  * MAIN FUNCTION
  ************************************************************************/