sotsuron

Fork of linearMirrorMotion1017 by Hiromasa Oku

Committer:
takapiasano
Date:
Wed Jul 24 08:31:32 2013 +0000
Revision:
28:d86c629b6fd3
Parent:
27:38bc8dc67dab
demo draw on tracks

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hiromasaoku 16:6dd2e60bc5bc 1 #include "renderclass.h"
hiromasaoku 16:6dd2e60bc5bc 2 #include "mbed.h"
hiromasaoku 16:6dd2e60bc5bc 3 #include "laserProjectorHardware.h"
hiromasaoku 16:6dd2e60bc5bc 4 #include <vector>
hiromasaoku 16:6dd2e60bc5bc 5
hiromasaoku 16:6dd2e60bc5bc 6 Ticker translationTimer;
hiromasaoku 16:6dd2e60bc5bc 7
hiromasaoku 16:6dd2e60bc5bc 8 //for translating -----------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 9
hiromasaoku 18:6f86abfae754 10 inline void render::shearing(point2dl& dataBefore)
hiromasaoku 18:6f86abfae754 11 {
takapiasano 27:38bc8dc67dab 12 dataBefore.x = -dataBefore.x/2.0 - 10.0*intvx; //vx * speedTimer.read_us()*10; //2000000;//dataBefore.x - speed *speedTimer.read_us()/1000000 ;//- speed * cos(angle+PI/2)*speedTimer.read_us()/800;
takapiasano 27:38bc8dc67dab 13 dataBefore.y = dataBefore.y/2.0 - 10.0*intvy; //vy * speedTimer.read_us()*10;//dataBefore.y ;//- speed * sin(angle+PI/2)*speedTimer.read_us()/800;
hiromasaoku 16:6dd2e60bc5bc 14 }
hiromasaoku 16:6dd2e60bc5bc 15
hiromasaoku 18:6f86abfae754 16 inline void render::rotation(point2dl& dataBefore)
hiromasaoku 18:6f86abfae754 17 {
hiromasaoku 18:6f86abfae754 18 int x=dataBefore.x;
takapiasano 26:74ecbf9985e1 19 dataBefore.x = cos(angle)*x - sin(angle)*dataBefore.y;//
takapiasano 26:74ecbf9985e1 20 dataBefore.y = sin(angle)*x + cos(angle)*dataBefore.y;
takapiasano 24:ab74d2018e6c 21
hiromasaoku 16:6dd2e60bc5bc 22 }
hiromasaoku 16:6dd2e60bc5bc 23 //----------------------------------------------------------------------------------
hiromasaoku 16:6dd2e60bc5bc 24
hiromasaoku 18:6f86abfae754 25 void render::startRender()
hiromasaoku 18:6f86abfae754 26 {
hiromasaoku 20:8475768fc2f7 27 speedTimer.start();
hiromasaoku 19:8e9fe7d25b9c 28 renderTimer.attach_us(this, &render::draw,RENDER_INTERVAL);
hiromasaoku 19:8e9fe7d25b9c 29 pc.printf("render started!\n");
takapiasano 26:74ecbf9985e1 30 pc.printf("int : %f, %f, v :, %f,%f, " , intvx , intvy , vx , vy);
takapiasano 26:74ecbf9985e1 31
hiromasaoku 16:6dd2e60bc5bc 32 }
hiromasaoku 16:6dd2e60bc5bc 33
hiromasaoku 18:6f86abfae754 34 void render::stopRender()
hiromasaoku 18:6f86abfae754 35 {
hiromasaoku 16:6dd2e60bc5bc 36 renderTimer.detach();
takapiasano 24:ab74d2018e6c 37 speedTimer.stop();
hiromasaoku 16:6dd2e60bc5bc 38 }
hiromasaoku 16:6dd2e60bc5bc 39
hiromasaoku 18:6f86abfae754 40 void render::setRender(vector<letter> *p)
hiromasaoku 18:6f86abfae754 41 {
takapiasano 24:ab74d2018e6c 42 translated.clear();
takapiasano 26:74ecbf9985e1 43 radious = 200;
takapiasano 28:d86c629b6fd3 44 angle = 0;
takapiasano 26:74ecbf9985e1 45
hiromasaoku 16:6dd2e60bc5bc 46 ptext = p;
hiromasaoku 19:8e9fe7d25b9c 47 pc.printf("Size of text to render: %d/n", (*ptext).size() );
hiromasaoku 16:6dd2e60bc5bc 48 //for(int i=0; i!=(*ptext).size(); i++){
takapiasano 24:ab74d2018e6c 49 int count=0;
hiromasaoku 18:6f86abfae754 50 for(std::vector<letter>::iterator itr = (*ptext).begin(); itr != (*ptext).end(); ++itr) {
takapiasano 24:ab74d2018e6c 51 letter translatedLetter;
takapiasano 24:ab74d2018e6c 52 for(int i=0; i<(*itr).letpoints.size(); i++) {
takapiasano 24:ab74d2018e6c 53 point2dl tranPoint;
takapiasano 28:d86c629b6fd3 54 tranPoint.x=itr->letpoints[i].x;//+560*count;
takapiasano 26:74ecbf9985e1 55 tranPoint.y=-itr->letpoints[i].y;
takapiasano 24:ab74d2018e6c 56 tranPoint.laserSwitch=itr->letpoints[i].laserSwitch;
takapiasano 24:ab74d2018e6c 57 translatedLetter.letpoints.push_back(tranPoint);
takapiasano 24:ab74d2018e6c 58
hiromasaoku 16:6dd2e60bc5bc 59 } //copy the liblary to the buffer.
takapiasano 24:ab74d2018e6c 60 translated.push_back(translatedLetter);
takapiasano 24:ab74d2018e6c 61 count++;
takapiasano 24:ab74d2018e6c 62 }
takapiasano 21:4095a071724d 63
takapiasano 24:ab74d2018e6c 64 shearingSwitch = 1;
takapiasano 24:ab74d2018e6c 65 radious = 1800;
takapiasano 21:4095a071724d 66
hiromasaoku 18:6f86abfae754 67 currentLetters=0;
takapiasano 24:ab74d2018e6c 68
takapiasano 24:ab74d2018e6c 69 firstPointCounter=0;
takapiasano 24:ab74d2018e6c 70 lastPointCounter=0;
takapiasano 24:ab74d2018e6c 71
takapiasano 24:ab74d2018e6c 72 rendererState=FIRST_POINT;
hiromasaoku 16:6dd2e60bc5bc 73 }
hiromasaoku 16:6dd2e60bc5bc 74
hiromasaoku 18:6f86abfae754 75
takapiasano 26:74ecbf9985e1 76 void render::updateSpeed(float vvx, float vvy)
takapiasano 21:4095a071724d 77 {
takapiasano 26:74ecbf9985e1 78 vx = vvx;
takapiasano 26:74ecbf9985e1 79 vy = vvy;
takapiasano 26:74ecbf9985e1 80
takapiasano 26:74ecbf9985e1 81 //intvx += RENDER_INTERVAL*vx;
takapiasano 26:74ecbf9985e1 82 //intvy += RENDER_INTERVAL*vy;
takapiasano 26:74ecbf9985e1 83
takapiasano 28:d86c629b6fd3 84 angle= 0;//atan2(vx,vy) + PI/2;
takapiasano 26:74ecbf9985e1 85 }
takapiasano 21:4095a071724d 86
hiromasaoku 20:8475768fc2f7 87
hiromasaoku 18:6f86abfae754 88 void render::draw()
hiromasaoku 18:6f86abfae754 89 {
takapiasano 26:74ecbf9985e1 90 /*
takapiasano 26:74ecbf9985e1 91 if(firstPointCounter < 3){
takapiasano 26:74ecbf9985e1 92
takapiasano 26:74ecbf9985e1 93 IO.writeOutXY(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
takapiasano 25:423050363215 94 if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 25:423050363215 95 if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 26:74ecbf9985e1 96
takapiasano 26:74ecbf9985e1 97 firstPointCounter+=1;
takapiasano 25:423050363215 98 }
takapiasano 25:423050363215 99 else{
takapiasano 25:423050363215 100
takapiasano 25:423050363215 101 IO.setRedPower(0);
takapiasano 25:423050363215 102 IO.setGreenPower(0);
takapiasano 26:74ecbf9985e1 103 firstPointCounter = 0;
takapiasano 25:423050363215 104 }
takapiasano 25:423050363215 105
takapiasano 25:423050363215 106
takapiasano 26:74ecbf9985e1 107 */
takapiasano 26:74ecbf9985e1 108
takapiasano 26:74ecbf9985e1 109
takapiasano 26:74ecbf9985e1 110 //if(abs(vx)<0.001 || abs(vy) < 0.001)startSwitch = 1;
takapiasano 26:74ecbf9985e1 111
takapiasano 26:74ecbf9985e1 112 if(translated.size()>0 && startSwitch == 1) {
takapiasano 24:ab74d2018e6c 113
takapiasano 24:ab74d2018e6c 114 switch(rendererState) {
takapiasano 24:ab74d2018e6c 115
takapiasano 24:ab74d2018e6c 116 case NORMAL_POINT:
takapiasano 26:74ecbf9985e1 117 intvx += speedTimer.read_us()*vx;
takapiasano 26:74ecbf9985e1 118 intvy += speedTimer.read_us()*vy;
takapiasano 28:d86c629b6fd3 119
takapiasano 26:74ecbf9985e1 120
takapiasano 24:ab74d2018e6c 121 point2dl drawPoint=translated[currentLetters].letpoints[currentPoints];
takapiasano 24:ab74d2018e6c 122 transform(drawPoint); // transform it with the current speed and angle
takapiasano 24:ab74d2018e6c 123 IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
takapiasano 25:423050363215 124 if(laserColor % 2 == 0) IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 25:423050363215 125 if(laserColor % 3 == 0) IO.setGreenPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 21:4095a071724d 126
takapiasano 24:ab74d2018e6c 127 // move to the next point
takapiasano 24:ab74d2018e6c 128 currentPoints++;
takapiasano 24:ab74d2018e6c 129
takapiasano 24:ab74d2018e6c 130 //Should we change the state?
takapiasano 24:ab74d2018e6c 131 if(currentPoints >= translated[currentLetters].letpoints.size() ) {
takapiasano 24:ab74d2018e6c 132 rendererState=AFTER_LAST_POINT;
takapiasano 24:ab74d2018e6c 133 }
takapiasano 24:ab74d2018e6c 134 break;
hiromasaoku 18:6f86abfae754 135
takapiasano 24:ab74d2018e6c 136 case AFTER_LAST_POINT:
takapiasano 24:ab74d2018e6c 137 // just wait!
takapiasano 24:ab74d2018e6c 138 if (lastPointCounter<WAITING_LAST) {
takapiasano 24:ab74d2018e6c 139 IO.setRedPower(0);
takapiasano 25:423050363215 140 IO.setGreenPower(0);
takapiasano 24:ab74d2018e6c 141 lastPointCounter++;
takapiasano 24:ab74d2018e6c 142 }
takapiasano 24:ab74d2018e6c 143 else {
takapiasano 24:ab74d2018e6c 144 lastPointCounter=0;
takapiasano 24:ab74d2018e6c 145 currentPoints = 0;
takapiasano 24:ab74d2018e6c 146 // switch the laser off and move to the first point of the next letter:
takapiasano 24:ab74d2018e6c 147
takapiasano 24:ab74d2018e6c 148 currentLetters++;
takapiasano 28:d86c629b6fd3 149 speedTimer.reset();
takapiasano 28:d86c629b6fd3 150 intvx = intvy =0;
takapiasano 28:d86c629b6fd3 151
takapiasano 28:d86c629b6fd3 152
takapiasano 24:ab74d2018e6c 153 if(currentLetters >= translated.size()) {
takapiasano 24:ab74d2018e6c 154 currentLetters = 0;
takapiasano 28:d86c629b6fd3 155 startSwitch=1;
takapiasano 28:d86c629b6fd3 156
takapiasano 26:74ecbf9985e1 157
takapiasano 26:74ecbf9985e1 158
takapiasano 24:ab74d2018e6c 159 }
takapiasano 24:ab74d2018e6c 160 rendererState=FIRST_POINT;
takapiasano 26:74ecbf9985e1 161
takapiasano 24:ab74d2018e6c 162 }
takapiasano 24:ab74d2018e6c 163 break;
takapiasano 24:ab74d2018e6c 164
takapiasano 24:ab74d2018e6c 165 case FIRST_POINT:
takapiasano 26:74ecbf9985e1 166
takapiasano 24:ab74d2018e6c 167 if (firstPointCounter<WAITING_FIRST) {
takapiasano 24:ab74d2018e6c 168 firstPointCounter++;
takapiasano 24:ab74d2018e6c 169
takapiasano 24:ab74d2018e6c 170 // show first point!
takapiasano 28:d86c629b6fd3 171 intvx = intvy =0;
takapiasano 28:d86c629b6fd3 172 speedTimer.reset();
takapiasano 28:d86c629b6fd3 173
takapiasano 24:ab74d2018e6c 174 point2dl drawPoint=translated[currentLetters].letpoints[0];
takapiasano 24:ab74d2018e6c 175 transform(drawPoint); // transform it with the current speed and angle
takapiasano 24:ab74d2018e6c 176 IO.writeOutXY(CENTER_AD_MIRROR_X + (int)drawPoint.x , CENTER_AD_MIRROR_Y + (int)drawPoint.y);
takapiasano 28:d86c629b6fd3 177
takapiasano 26:74ecbf9985e1 178
takapiasano 26:74ecbf9985e1 179
takapiasano 24:ab74d2018e6c 180 //IO.setRedPower(translated[currentLetters].letpoints[currentPoints].laserSwitch);
takapiasano 24:ab74d2018e6c 181
takapiasano 24:ab74d2018e6c 182 } else {
takapiasano 24:ab74d2018e6c 183 firstPointCounter=0;
takapiasano 24:ab74d2018e6c 184 currentPoints=1;
takapiasano 24:ab74d2018e6c 185 rendererState=NORMAL_POINT;
takapiasano 24:ab74d2018e6c 186 }
takapiasano 24:ab74d2018e6c 187 break;
takapiasano 24:ab74d2018e6c 188 }
hiromasaoku 20:8475768fc2f7 189 }
takapiasano 26:74ecbf9985e1 190
takapiasano 25:423050363215 191 }
hiromasaoku 18:6f86abfae754 192
takapiasano 24:ab74d2018e6c 193 void render::transform(point2dl& mypoint) {
takapiasano 24:ab74d2018e6c 194 rotation(mypoint);
takapiasano 24:ab74d2018e6c 195 if(shearingSwitch == 1) shearing(mypoint);
takapiasano 25:423050363215 196 }
hiromasaoku 16:6dd2e60bc5bc 197