just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Fri Sep 21 10:02:35 2012 +0000
Revision:
30:d8af03f01cd4
Parent:
29:2fc8c12822eb
Child:
31:5f039cbddee8
first commit. Not yet functional. Added ghost and pacman game modes, but the behaviour of these "rigid spots" is not implemented yet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 1:a4050fee11f7 1 #include "rigidLoop.h"
mbedalvaro 1:a4050fee11f7 2
mbedalvaro 1:a4050fee11f7 3 // SHOULD NOT BE HERE: (only because I am using AD_MIRRIOR... max and min in the set region function that should not be here)
mbedalvaro 1:a4050fee11f7 4 #include "hardwareIO.h"
mbedalvaro 1:a4050fee11f7 5
mbedalvaro 1:a4050fee11f7 6 rigidLoop::rigidLoop() {
mbedalvaro 1:a4050fee11f7 7 }
mbedalvaro 1:a4050fee11f7 8
mbedalvaro 1:a4050fee11f7 9 rigidLoop::~rigidLoop() {
mbedalvaro 1:a4050fee11f7 10
mbedalvaro 1:a4050fee11f7 11 }
mbedalvaro 1:a4050fee11f7 12
mbedalvaro 1:a4050fee11f7 13
mbedalvaro 1:a4050fee11f7 14 // Note: this method is hidding the abstract method in the base class... and has DIFFERENT parameters than another child would have (enum type).
mbedalvaro 12:0de9cd2bced5 15 void rigidLoop::createBlob(int _id, RigidLoopMode _elasticBlobMode, vector2Df _initPos, vector2Df _initSpeed) {
mbedalvaro 1:a4050fee11f7 16 // (1) set ID:
mbedalvaro 1:a4050fee11f7 17 identifier=_id;
mbedalvaro 1:a4050fee11f7 18
mbedalvaro 1:a4050fee11f7 19 updateMode=_elasticBlobMode;
mbedalvaro 4:f9d364f10335 20
mbedalvaro 4:f9d364f10335 21 startCenter=_initPos;
mbedalvaro 4:f9d364f10335 22 startSpeed=_initSpeed;
mbedalvaro 4:f9d364f10335 23
mbedalvaro 1:a4050fee11f7 24 // (2) Initialize common variables of all blobs (base class):
mbedalvaro 1:a4050fee11f7 25 initCommonVariables();
mbedalvaro 1:a4050fee11f7 26
mbedalvaro 1:a4050fee11f7 27 // (3) initialize common variables for the different modes of this rigid loop (even if some are not used, better not to have more subclasses...)
mbedalvaro 18:d72935b13858 28 // Sending data:
mbedalvaro 20:8e82b95180e7 29 periodSendingData=10; // in ms
mbedalvaro 18:d72935b13858 30 sendingRecenteringAngle=true;
mbedalvaro 18:d72935b13858 31 sendingAnchorPosition=true;
mbedalvaro 18:d72935b13858 32 sendingOnlyWhenTouch=true;
mbedalvaro 21:bc9b9383f4b6 33
mbedalvaro 21:bc9b9383f4b6 34 // Gravity field:
mbedalvaro 21:bc9b9383f4b6 35 gravity.set(.5,0);
mbedalvaro 3:b44ff6de81bd 36
mbedalvaro 1:a4050fee11f7 37 // (3) Initialize secondary variables depending on the behaviour mode (may be changed afterwards in real time)
mbedalvaro 1:a4050fee11f7 38
mbedalvaro 1:a4050fee11f7 39 switch (updateMode) {
mbedalvaro 4:f9d364f10335 40
mbedalvaro 4:f9d364f10335 41 case SPOT_TEST:
mbedalvaro 4:f9d364f10335 42 // Name of this kind of spot:
mbedalvaro 4:f9d364f10335 43 sprintf(spotName,"spot_test");
mbedalvaro 4:f9d364f10335 44
mbedalvaro 4:f9d364f10335 45 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 4:f9d364f10335 46 setColor(0x04);
mbedalvaro 4:f9d364f10335 47
mbedalvaro 14:0fc33a3a7b4b 48 saccadeRadius=250;
mbedalvaro 4:f9d364f10335 49
mbedalvaro 4:f9d364f10335 50 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 14:0fc33a3a7b4b 51 // NOTE: number of points in the case of need to compute recentering vector needs to be EVEN
mbedalvaro 14:0fc33a3a7b4b 52 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 16); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
mbedalvaro 4:f9d364f10335 53
mbedalvaro 4:f9d364f10335 54 massCenter=0.01;
mbedalvaro 4:f9d364f10335 55 dampMotionCenterMass=0.001;
mbedalvaro 4:f9d364f10335 56
mbedalvaro 4:f9d364f10335 57 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 4:f9d364f10335 58 createLoopFromScafold();
mbedalvaro 4:f9d364f10335 59
mbedalvaro 5:73cd58b58f95 60 // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 5:73cd58b58f95 61 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 5:73cd58b58f95 62 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
mbedalvaro 7:0df17f3078bc 63 displaySensingBuffer.setDelayMirrors(1);
mbedalvaro 7:0df17f3078bc 64 angleCorrectionForceLoop=0;//360.0/bluePrint.scafold.size()/2; // in DEGREES
mbedalvaro 4:f9d364f10335 65
mbedalvaro 4:f9d364f10335 66 break;
mbedalvaro 30:d8af03f01cd4 67
mbedalvaro 30:d8af03f01cd4 68 case SPOT_TRACK:
mbedalvaro 30:d8af03f01cd4 69 // Name of this kind of spot:
mbedalvaro 30:d8af03f01cd4 70 sprintf(spotName,"spot_track");
mbedalvaro 30:d8af03f01cd4 71
mbedalvaro 30:d8af03f01cd4 72 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 30:d8af03f01cd4 73 setColor(0x04);
mbedalvaro 30:d8af03f01cd4 74
mbedalvaro 30:d8af03f01cd4 75 gravity.set(0,0);
mbedalvaro 30:d8af03f01cd4 76
mbedalvaro 30:d8af03f01cd4 77 saccadeRadius=50;//+rand()%20;
mbedalvaro 30:d8af03f01cd4 78 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 30:d8af03f01cd4 79 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 24); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
mbedalvaro 30:d8af03f01cd4 80
mbedalvaro 30:d8af03f01cd4 81 // Numeric parameters for the simulated mechanical system:
mbedalvaro 30:d8af03f01cd4 82 massCenter=0.001;//+0.000005*(rand()%100);
mbedalvaro 30:d8af03f01cd4 83 dampMotionCenterMass=0.001;//0.00015;//00003;
mbedalvaro 30:d8af03f01cd4 84
mbedalvaro 30:d8af03f01cd4 85 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 30:d8af03f01cd4 86 createLoopFromScafold();
mbedalvaro 30:d8af03f01cd4 87
mbedalvaro 30:d8af03f01cd4 88 // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 30:d8af03f01cd4 89 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 30:d8af03f01cd4 90 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
mbedalvaro 30:d8af03f01cd4 91 displaySensingBuffer.setDelayMirrors(3);
mbedalvaro 30:d8af03f01cd4 92 angleCorrectionForceLoop=-5;// in degrees
mbedalvaro 30:d8af03f01cd4 93
mbedalvaro 30:d8af03f01cd4 94 break;
mbedalvaro 4:f9d364f10335 95
mbedalvaro 1:a4050fee11f7 96 case SPOT_FOLLOWING:
mbedalvaro 1:a4050fee11f7 97
mbedalvaro 1:a4050fee11f7 98 // Name of this kind of spot:
mbedalvaro 1:a4050fee11f7 99 sprintf(spotName,"rigid_following");
mbedalvaro 1:a4050fee11f7 100
mbedalvaro 3:b44ff6de81bd 101 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 3:b44ff6de81bd 102 setColor(0x04);
mbedalvaro 1:a4050fee11f7 103
mbedalvaro 1:a4050fee11f7 104 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 30:d8af03f01cd4 105 saccadeRadius=23;
mbedalvaro 12:0de9cd2bced5 106 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
mbedalvaro 1:a4050fee11f7 107
mbedalvaro 1:a4050fee11f7 108 // Note: We may assume NO MASS for the center of the contour following loop. Adding mass may be interesting though (smooth motion).
mbedalvaro 1:a4050fee11f7 109 massCenter=0.01;
mbedalvaro 1:a4050fee11f7 110 dampMotionCenterMass=0.001;
mbedalvaro 1:a4050fee11f7 111
mbedalvaro 4:f9d364f10335 112 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 4:f9d364f10335 113 createLoopFromScafold();
mbedalvaro 4:f9d364f10335 114
mbedalvaro 5:73cd58b58f95 115 slidingDirection=true; // For contour following (will change direction when touching wall)
mbedalvaro 22:d87317d7ca91 116 speedContourFollowing=1.1*saccadeRadius;
mbedalvaro 7:0df17f3078bc 117 justSearched=false;
mbedalvaro 5:73cd58b58f95 118
mbedalvaro 7:0df17f3078bc 119 // per-blob mirror delay: ONLY USEFUL FOR ELASTIC BLOBS, because otherwise it can be corrected by "angleCorrection"
mbedalvaro 7:0df17f3078bc 120 // (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 5:73cd58b58f95 121 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 7:0df17f3078bc 122 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop.
mbedalvaro 7:0df17f3078bc 123 // BUT because we may want to see the blue laser where there is dark zone, then we would try to adjust mirror delay as close as possible to the
mbedalvaro 7:0df17f3078bc 124 // optimal value, and finish the correction (fine tunned) with the angle correction (only possible in the case of circular rigid blob).
mbedalvaro 7:0df17f3078bc 125 displaySensingBuffer.setDelayMirrors(3); // this corresponds to an angular correction of -delayMirrors * 360/numPoints
mbedalvaro 15:56a0bf424e8d 126 angleCorrectionForceLoop= -5;// good for ONE spot: -5;// in DEGREES
mbedalvaro 4:f9d364f10335 127
mbedalvaro 1:a4050fee11f7 128 break;
mbedalvaro 1:a4050fee11f7 129
mbedalvaro 1:a4050fee11f7 130 case SPOT_BOUNCING:
mbedalvaro 1:a4050fee11f7 131 // Name of this kind of spot:
mbedalvaro 1:a4050fee11f7 132 sprintf(spotName,"rigid_bouncing");
mbedalvaro 1:a4050fee11f7 133
mbedalvaro 3:b44ff6de81bd 134 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 3:b44ff6de81bd 135 setColor(0x04);
mbedalvaro 27:1ce994629ffc 136
mbedalvaro 27:1ce994629ffc 137 gravity.set(0,0);
mbedalvaro 1:a4050fee11f7 138
mbedalvaro 28:44b7b6e35548 139 saccadeRadius=35;//+rand()%20;
mbedalvaro 1:a4050fee11f7 140 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 12:0de9cd2bced5 141 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
mbedalvaro 1:a4050fee11f7 142
mbedalvaro 1:a4050fee11f7 143 // Numeric parameters for the simulated mechanical system:
mbedalvaro 24:4e52031a495b 144 massCenter=0.0008;//+0.000005*(rand()%100);
mbedalvaro 28:44b7b6e35548 145 dampMotionCenterMass=0.0006;//0.00015;//00003;
mbedalvaro 28:44b7b6e35548 146 factorBouncingForce=0.0018; // this is because we will use a force on the central mass
mbedalvaro 28:44b7b6e35548 147
mbedalvaro 28:44b7b6e35548 148 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 28:44b7b6e35548 149 createLoopFromScafold();
mbedalvaro 30:d8af03f01cd4 150
mbedalvaro 30:d8af03f01cd4 151
mbedalvaro 30:d8af03f01cd4 152 // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 30:d8af03f01cd4 153 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 30:d8af03f01cd4 154 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
mbedalvaro 30:d8af03f01cd4 155 displaySensingBuffer.setDelayMirrors(3);
mbedalvaro 30:d8af03f01cd4 156 angleCorrectionForceLoop=-5;// in degrees
mbedalvaro 30:d8af03f01cd4 157
mbedalvaro 30:d8af03f01cd4 158 break;
mbedalvaro 30:d8af03f01cd4 159
mbedalvaro 30:d8af03f01cd4 160 case SPOT_PACMAN:
mbedalvaro 30:d8af03f01cd4 161 // this will define the behaviour of the "ghosts" in pacman. The spot just moves at a constant speed when there is no object.
mbedalvaro 30:d8af03f01cd4 162 // When it collides, we use the position of the pacman (another spot) and the tangent vector to the blocking line to define the new direction of the
mbedalvaro 30:d8af03f01cd4 163 // speed vector.
mbedalvaro 30:d8af03f01cd4 164
mbedalvaro 30:d8af03f01cd4 165 sprintf(spotName,"bounce_slide");
mbedalvaro 30:d8af03f01cd4 166
mbedalvaro 30:d8af03f01cd4 167 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 30:d8af03f01cd4 168 setColor(0x06); // make it green
mbedalvaro 30:d8af03f01cd4 169
mbedalvaro 30:d8af03f01cd4 170 gravity.set(0,0);
mbedalvaro 30:d8af03f01cd4 171
mbedalvaro 30:d8af03f01cd4 172 // make it bounce slowly:
mbedalvaro 30:d8af03f01cd4 173 dampMotionCenterMass=0.006;;
mbedalvaro 30:d8af03f01cd4 174
mbedalvaro 30:d8af03f01cd4 175 saccadeRadius=35;//+rand()%20;
mbedalvaro 30:d8af03f01cd4 176 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 30:d8af03f01cd4 177 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
mbedalvaro 30:d8af03f01cd4 178
mbedalvaro 30:d8af03f01cd4 179 // Numeric parameters for the simulated mechanical system (probably not used in this kind of spot)
mbedalvaro 30:d8af03f01cd4 180 massCenter=0.0008;//+0.000005*(rand()%100);
mbedalvaro 30:d8af03f01cd4 181 dampMotionCenterMass=0.0006;//0.00015;//00003;
mbedalvaro 30:d8af03f01cd4 182 factorBouncingForce=0.0018; // this is because we will use a force on the central mass
mbedalvaro 30:d8af03f01cd4 183
mbedalvaro 30:d8af03f01cd4 184 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 30:d8af03f01cd4 185 createLoopFromScafold();
mbedalvaro 30:d8af03f01cd4 186
mbedalvaro 30:d8af03f01cd4 187 slidingDirection=true; // For contour following (will change direction when touching wall)
mbedalvaro 30:d8af03f01cd4 188 speedContourFollowing=1.1*saccadeRadius;
mbedalvaro 30:d8af03f01cd4 189 justSearched=false;
mbedalvaro 30:d8af03f01cd4 190
mbedalvaro 30:d8af03f01cd4 191
mbedalvaro 30:d8af03f01cd4 192 // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 30:d8af03f01cd4 193 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 30:d8af03f01cd4 194 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
mbedalvaro 30:d8af03f01cd4 195 displaySensingBuffer.setDelayMirrors(3);
mbedalvaro 30:d8af03f01cd4 196 angleCorrectionForceLoop=-5;// in degrees
mbedalvaro 30:d8af03f01cd4 197
mbedalvaro 30:d8af03f01cd4 198 break;
mbedalvaro 30:d8af03f01cd4 199
mbedalvaro 30:d8af03f01cd4 200 case SPOT_GHOST:
mbedalvaro 30:d8af03f01cd4 201 // this will define the behaviour of the "ghosts" in pacman. The spot just moves at a constant speed when there is no object.
mbedalvaro 30:d8af03f01cd4 202 // When it collides, we use the position of the pacman (another spot) and the tangent vector to the blocking line to define the new direction of the
mbedalvaro 30:d8af03f01cd4 203 // speed vector.
mbedalvaro 30:d8af03f01cd4 204
mbedalvaro 30:d8af03f01cd4 205 sprintf(spotName,"bounce_slide");
mbedalvaro 30:d8af03f01cd4 206
mbedalvaro 30:d8af03f01cd4 207 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 30:d8af03f01cd4 208 setColor(0x05); // make it BLUE
mbedalvaro 30:d8af03f01cd4 209
mbedalvaro 30:d8af03f01cd4 210 gravity.set(0,0);
mbedalvaro 30:d8af03f01cd4 211
mbedalvaro 30:d8af03f01cd4 212 // make it bounce slowly:
mbedalvaro 30:d8af03f01cd4 213 dampMotionCenterMass=0.006;;
mbedalvaro 30:d8af03f01cd4 214
mbedalvaro 30:d8af03f01cd4 215 saccadeRadius=35;//+rand()%20;
mbedalvaro 30:d8af03f01cd4 216 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 30:d8af03f01cd4 217 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
mbedalvaro 30:d8af03f01cd4 218
mbedalvaro 30:d8af03f01cd4 219 // Numeric parameters for the simulated mechanical system (probably not used in this kind of spot)
mbedalvaro 30:d8af03f01cd4 220 massCenter=0.0008;//+0.000005*(rand()%100);
mbedalvaro 30:d8af03f01cd4 221 dampMotionCenterMass=0.0006;//0.00015;//00003;
mbedalvaro 30:d8af03f01cd4 222 factorBouncingForce=0.0018; // this is because we will use a force on the central mass
mbedalvaro 30:d8af03f01cd4 223
mbedalvaro 30:d8af03f01cd4 224 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 30:d8af03f01cd4 225 createLoopFromScafold();
mbedalvaro 30:d8af03f01cd4 226
mbedalvaro 30:d8af03f01cd4 227 slidingDirection=true; // For contour following (will change direction when touching wall)
mbedalvaro 30:d8af03f01cd4 228 speedContourFollowing=1.1*saccadeRadius;
mbedalvaro 30:d8af03f01cd4 229 justSearched=false;
mbedalvaro 30:d8af03f01cd4 230
mbedalvaro 28:44b7b6e35548 231
mbedalvaro 28:44b7b6e35548 232 // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 28:44b7b6e35548 233 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 28:44b7b6e35548 234 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
mbedalvaro 28:44b7b6e35548 235 displaySensingBuffer.setDelayMirrors(3);
mbedalvaro 28:44b7b6e35548 236 angleCorrectionForceLoop=-5;// in degrees
mbedalvaro 28:44b7b6e35548 237
mbedalvaro 28:44b7b6e35548 238 break;
mbedalvaro 28:44b7b6e35548 239
mbedalvaro 28:44b7b6e35548 240 case SPOT_AIR_HOCKEY:
mbedalvaro 28:44b7b6e35548 241 // Name of this kind of spot:
mbedalvaro 28:44b7b6e35548 242 sprintf(spotName,"air_hockey");
mbedalvaro 28:44b7b6e35548 243
mbedalvaro 28:44b7b6e35548 244 //startCenter.set(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
mbedalvaro 28:44b7b6e35548 245 //startSpeed.set(0,0);
mbedalvaro 28:44b7b6e35548 246
mbedalvaro 28:44b7b6e35548 247 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 28:44b7b6e35548 248 setColor(0x04);
mbedalvaro 28:44b7b6e35548 249
mbedalvaro 28:44b7b6e35548 250 gravity.set(0,0);
mbedalvaro 28:44b7b6e35548 251
mbedalvaro 28:44b7b6e35548 252 saccadeRadius=50;//+rand()%20;
mbedalvaro 28:44b7b6e35548 253 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 28:44b7b6e35548 254 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
mbedalvaro 28:44b7b6e35548 255
mbedalvaro 28:44b7b6e35548 256 // Numeric parameters for the simulated mechanical system:
mbedalvaro 28:44b7b6e35548 257 massCenter=0.0008;//+0.000005*(rand()%100);
mbedalvaro 28:44b7b6e35548 258 dampMotionCenterMass=0.00065;//0.00015;//00003;
mbedalvaro 7:0df17f3078bc 259 factorBouncingForce=0.0018; // this is because we will use a force on the central mass
mbedalvaro 1:a4050fee11f7 260
mbedalvaro 4:f9d364f10335 261 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 4:f9d364f10335 262 createLoopFromScafold();
mbedalvaro 4:f9d364f10335 263
mbedalvaro 5:73cd58b58f95 264 // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 5:73cd58b58f95 265 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 5:73cd58b58f95 266 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
mbedalvaro 7:0df17f3078bc 267 displaySensingBuffer.setDelayMirrors(3);
mbedalvaro 7:0df17f3078bc 268 angleCorrectionForceLoop=-5;// in degrees
mbedalvaro 1:a4050fee11f7 269
mbedalvaro 1:a4050fee11f7 270 break;
mbedalvaro 27:1ce994629ffc 271
mbedalvaro 30:d8af03f01cd4 272 case SPOT_LORENTZ_FORCE:
mbedalvaro 27:1ce994629ffc 273 // Name of this kind of spot:
mbedalvaro 27:1ce994629ffc 274 sprintf(spotName,"rigid_fountain");
mbedalvaro 27:1ce994629ffc 275
mbedalvaro 27:1ce994629ffc 276 //setColor(0x07);//0x04+0x02>>i);
mbedalvaro 27:1ce994629ffc 277 setColor(0x04);
mbedalvaro 27:1ce994629ffc 278
mbedalvaro 29:2fc8c12822eb 279 saccadeRadius=20;//+rand()%20;
mbedalvaro 27:1ce994629ffc 280 // default (initial) shape (the scafold belongs to the base class):
mbedalvaro 28:44b7b6e35548 281 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos, int _numScafoldPoints);
mbedalvaro 27:1ce994629ffc 282
mbedalvaro 27:1ce994629ffc 283 // Numeric parameters for the simulated mechanical system:
mbedalvaro 27:1ce994629ffc 284 massCenter=0.0005;//+0.000005*(rand()%100);
mbedalvaro 28:44b7b6e35548 285 dampMotionCenterMass=0.001;//0.00015;//00003;
mbedalvaro 28:44b7b6e35548 286 factorBouncingForce=0.0015; // this is because we will use a force on the central mass
mbedalvaro 27:1ce994629ffc 287
mbedalvaro 27:1ce994629ffc 288 // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
mbedalvaro 27:1ce994629ffc 289 createLoopFromScafold();
mbedalvaro 27:1ce994629ffc 290
mbedalvaro 27:1ce994629ffc 291 // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
mbedalvaro 27:1ce994629ffc 292 // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
mbedalvaro 27:1ce994629ffc 293 // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
mbedalvaro 27:1ce994629ffc 294 displaySensingBuffer.setDelayMirrors(3);
mbedalvaro 27:1ce994629ffc 295 angleCorrectionForceLoop=-5;// in degrees
mbedalvaro 27:1ce994629ffc 296
mbedalvaro 27:1ce994629ffc 297 break;
mbedalvaro 1:a4050fee11f7 298 }
mbedalvaro 7:0df17f3078bc 299
mbedalvaro 7:0df17f3078bc 300 saccadeRadius_initial=saccadeRadius; // this is for search mode for instance.
mbedalvaro 12:0de9cd2bced5 301
mbedalvaro 12:0de9cd2bced5 302 // Excursion limits (for all points). Tthis will set the limits of motion for the rigid loop, which is given by it's central position, so we have to correct by the radius:
mbedalvaro 12:0de9cd2bced5 303 setRegionMotion(MIN_AD_MIRRORS+saccadeRadius, MIN_AD_MIRRORS+saccadeRadius, MAX_AD_MIRRORS-saccadeRadius, MAX_AD_MIRRORS-saccadeRadius);
mbedalvaro 12:0de9cd2bced5 304
mbedalvaro 26:c9329c4fc20a 305 // draw it once on the display buffer for good initialization:
mbedalvaro 26:c9329c4fc20a 306 draw();
mbedalvaro 1:a4050fee11f7 307 }
mbedalvaro 1:a4050fee11f7 308
mbedalvaro 1:a4050fee11f7 309
mbedalvaro 1:a4050fee11f7 310 void rigidLoop::initSizeBlob(int _numPoints) {
mbedalvaro 1:a4050fee11f7 311 // Iinitialize blob size (number of points for the loop, as well as other structures such as lsdTrajectory)
mbedalvaro 1:a4050fee11f7 312 numPoints=_numPoints;
mbedalvaro 1:a4050fee11f7 313
mbedalvaro 1:a4050fee11f7 314 // Sensing and Display trajectory:
mbedalvaro 1:a4050fee11f7 315 displaySensingBuffer.lsdTrajectory.resize(numPoints); // the lsdTrajectory and the elastic loop will have the same number of points (this could be different - decimation?).
mbedalvaro 1:a4050fee11f7 316 }
mbedalvaro 1:a4050fee11f7 317
mbedalvaro 1:a4050fee11f7 318 void rigidLoop::createLoopFromScafold(void) {
mbedalvaro 1:a4050fee11f7 319
mbedalvaro 1:a4050fee11f7 320 initSizeBlob(bluePrint.scafold.size()); // very simple here (only need to set the size of the lsd buffer)
mbedalvaro 1:a4050fee11f7 321
mbedalvaro 1:a4050fee11f7 322 centerMass.mass=massCenter;
mbedalvaro 1:a4050fee11f7 323 centerMass.dampMotion = dampMotionCenterMass;
mbedalvaro 1:a4050fee11f7 324
mbedalvaro 1:a4050fee11f7 325 // note: the following may not be required in case of contour following:
mbedalvaro 2:34157ebbf56b 326 centerMass.setIntegrationStep(0.23); // VERY IMPORTANT! in the case of verlet integration, we need to set dt BEFORE setting the initial speed.
mbedalvaro 4:f9d364f10335 327 centerMass.setInitialCondition(startCenter, startSpeed);
mbedalvaro 1:a4050fee11f7 328 // centerMass.setInitialCondition(2047.0, 2047.0,0.0,0.0);
mbedalvaro 26:c9329c4fc20a 329
mbedalvaro 1:a4050fee11f7 330 }
mbedalvaro 1:a4050fee11f7 331
mbedalvaro 12:0de9cd2bced5 332 void rigidLoop::setRegionMotion(float mmix, float mmiy, float mmax, float mmay) { // wrapper for setWallLimits, because there is no more things to do than set this for a unique mass
mbedalvaro 12:0de9cd2bced5 333 // centerMass.setWallLimits(mmix+10, mmiy+10, mmax-10, mmay-10);
mbedalvaro 12:0de9cd2bced5 334 // Use the static method of the pointMass class:
mbedalvaro 30:d8af03f01cd4 335 pointMass::setWallLimits(mmix+10, mmiy+10, mmax-10, mmay-10);
mbedalvaro 1:a4050fee11f7 336 }
mbedalvaro 1:a4050fee11f7 337
mbedalvaro 24:4e52031a495b 338 void rigidLoop::speedFactor(float speedfactor) {
mbedalvaro 24:4e52031a495b 339 // in case of spot following:
mbedalvaro 24:4e52031a495b 340 speedContourFollowing*=speedfactor;
mbedalvaro 24:4e52031a495b 341
mbedalvaro 24:4e52031a495b 342 // in case of bouncing, there are many ways to change the speed (play with the mass, damping or the bouncing force).
mbedalvaro 24:4e52031a495b 343 //centerMass.mass/=speedfactor;//0.0008;//+0.000005*(rand()%100);
mbedalvaro 24:4e52031a495b 344 centerMass.dampMotion/=speedfactor;//0.00045;//0.00015;//00003;
mbedalvaro 24:4e52031a495b 345 //factorBouncingForce=0.0018; // this is because we will use a force on the central mass
mbedalvaro 24:4e52031a495b 346
mbedalvaro 24:4e52031a495b 347
mbedalvaro 24:4e52031a495b 348 }
mbedalvaro 1:a4050fee11f7 349
mbedalvaro 1:a4050fee11f7 350 void rigidLoop::update() {
mbedalvaro 1:a4050fee11f7 351
mbedalvaro 1:a4050fee11f7 352 // (I) process loop geometry: not needed (rigid)
mbedalvaro 1:a4050fee11f7 353 // Just check if the blob touched the borders (only need to do this with the central mass):
mbedalvaro 1:a4050fee11f7 354 blobWallCollision=centerMass.bWallCollision;
mbedalvaro 1:a4050fee11f7 355
mbedalvaro 1:a4050fee11f7 356 // (II) Process sensing buffer and compute light forces:
mbedalvaro 1:a4050fee11f7 357 displaySensingBuffer.processSensedData(); // note: region with light is -1, and without is 2 (TO CHANGE!!! then we don't need to do "if" in the moment computation, but just a product)
mbedalvaro 1:a4050fee11f7 358
mbedalvaro 1:a4050fee11f7 359 // (III) Compute recentering vector (the "penetration vector in fact"), using "first order moment":
mbedalvaro 3:b44ff6de81bd 360 // ATTENTION!! for this simple method (of "first order moment") to work, we have either to have numPoints very large, OR an EVEN quantity - so the
mbedalvaro 3:b44ff6de81bd 361 // sum in the circle is 0).
mbedalvaro 12:0de9cd2bced5 362 vector2Df momentVector(0,0);
mbedalvaro 7:0df17f3078bc 363 int counterDarkZone=0; // note: for a VERY strange reason, if I put this on the laserSensingtrajectory class, the program does not work anymore!!
mbedalvaro 7:0df17f3078bc 364 for (int i = 0; i < numPoints; i++) { // note: numPoints should be EVEN
mbedalvaro 1:a4050fee11f7 365 if (displaySensingBuffer.lsdTrajectory[i].lightZone>0) { // this is, we are in a dark zone (better to integrate there, because it is normally smaller)
mbedalvaro 12:0de9cd2bced5 366
mbedalvaro 12:0de9cd2bced5 367 momentVector.x+=(float)bluePrint.scafold[i].x; // note: casting is happening here automatically (unsigned short to float), but I put (float) to remember that types are different
mbedalvaro 12:0de9cd2bced5 368 momentVector.y+=(float)bluePrint.scafold[i].y;
mbedalvaro 12:0de9cd2bced5 369
mbedalvaro 12:0de9cd2bced5 370 // We can also do the following, but ATTENTION: momentVector is of type vector2Df, and scafold[i] of type vector2Dd...
mbedalvaro 12:0de9cd2bced5 371 // momentVector+=bluePrint.scafold[i];// note: no need to do -centerMass.pos, because the scafold is "centered" around 0
mbedalvaro 12:0de9cd2bced5 372
mbedalvaro 7:0df17f3078bc 373 counterDarkZone++;
mbedalvaro 1:a4050fee11f7 374 }
mbedalvaro 1:a4050fee11f7 375 }
mbedalvaro 7:0df17f3078bc 376 momentVector=momentVector*(2*PI/numPoints);
mbedalvaro 7:0df17f3078bc 377 float momentNorm=momentVector.length(); // = 2.R.sin(half_angle) in the direction of the dark zone
mbedalvaro 5:73cd58b58f95 378
mbedalvaro 12:0de9cd2bced5 379 vector2Df unitTowardsLight; // this is the normed vector, pointing towards the light zone
mbedalvaro 2:34157ebbf56b 380 if (momentNorm==0) {
mbedalvaro 7:0df17f3078bc 381 unitTowardsLight.set(0,0);
mbedalvaro 3:b44ff6de81bd 382 recenteringVectorLoop.set(0,0);
mbedalvaro 3:b44ff6de81bd 383 normRecenteringVector=0;
mbedalvaro 3:b44ff6de81bd 384 angleRecenteringVector=0;
mbedalvaro 3:b44ff6de81bd 385 } else {
mbedalvaro 7:0df17f3078bc 386 unitTowardsLight=momentVector/(-1.0*momentNorm);
mbedalvaro 7:0df17f3078bc 387 // Apply correction angle (delay mirrors):
mbedalvaro 7:0df17f3078bc 388 unitTowardsLight.rotateDeg(angleCorrectionForceLoop);
mbedalvaro 7:0df17f3078bc 389
mbedalvaro 30:d8af03f01cd4 390 // Compute "recenteringVectorLoop": the vector making the spot goes completely AWAY form the dark zone
mbedalvaro 7:0df17f3078bc 391 float aux=0.5*momentNorm/saccadeRadius; // note: in principle, we ALWAYS have momentNorm < 2.R, so aux < 1
mbedalvaro 7:0df17f3078bc 392 if (aux>1) aux=1.0; // can happen because of the discrete integration!
mbedalvaro 7:0df17f3078bc 393 if (counterDarkZone<=numPoints/2) { // note: numPoints HAS to be EVEN
mbedalvaro 7:0df17f3078bc 394 recenteringVectorLoop=unitTowardsLight*saccadeRadius*(1.0-sqrt(1.0-aux*aux));
mbedalvaro 7:0df17f3078bc 395 } else {
mbedalvaro 7:0df17f3078bc 396 recenteringVectorLoop=unitTowardsLight*saccadeRadius*(1.0+sqrt(1.0-aux*aux));
mbedalvaro 7:0df17f3078bc 397 }
mbedalvaro 7:0df17f3078bc 398
mbedalvaro 7:0df17f3078bc 399
mbedalvaro 3:b44ff6de81bd 400 // Compute redundant quantities (if necessary, for sending through OSC, etc):
mbedalvaro 3:b44ff6de81bd 401 normRecenteringVector=recenteringVectorLoop.length();
mbedalvaro 3:b44ff6de81bd 402 angleRecenteringVector=recenteringVectorLoop.angleDegHoriz();
mbedalvaro 3:b44ff6de81bd 403 }
mbedalvaro 3:b44ff6de81bd 404
mbedalvaro 30:d8af03f01cd4 405 // ======================== Now, depending on the mode of operation, we have different types of behaviour ========================================
mbedalvaro 30:d8af03f01cd4 406
mbedalvaro 12:0de9cd2bced5 407 vector2Df slidingVector; //( need to declare it here because a switch "jump" cannot bypass an initialization)
mbedalvaro 1:a4050fee11f7 408 switch (updateMode) {
mbedalvaro 30:d8af03f01cd4 409 // ================================================================
mbedalvaro 4:f9d364f10335 410 case SPOT_TEST: // this is just for adjusting mirror delays, checking recentering vector, etc:
mbedalvaro 4:f9d364f10335 411 // do nothing for the time being
mbedalvaro 4:f9d364f10335 412 // NOTE: it is not so easy to show the recentering vector without affecting the mirror delay BECAUSE I AM USING THE INTERRUPT METHOD for display.
mbedalvaro 4:f9d364f10335 413 // A possible solution is to instantiate ANOTHER blob with a shape just equal to a line, and rotate it using data from the this blob. Make a new class? Seems a good idea.
mbedalvaro 4:f9d364f10335 414
mbedalvaro 27:1ce994629ffc 415 // (1) current color: change with touch? NO
mbedalvaro 27:1ce994629ffc 416 transientBlobColor=blobColor; // just the original blob color
mbedalvaro 27:1ce994629ffc 417
mbedalvaro 4:f9d364f10335 418 break;
mbedalvaro 30:d8af03f01cd4 419 // ================================================================
mbedalvaro 30:d8af03f01cd4 420 case SPOT_TRACK:
mbedalvaro 30:d8af03f01cd4 421 centerMass.pos +=recenteringVectorLoop;
mbedalvaro 30:d8af03f01cd4 422 centerMass.posOld=centerMass.pos; // this is necessary to compute bouceOffWalls using Verlet method... (MAKE A new variable INTEGRATION METHOD?)
mbedalvaro 30:d8af03f01cd4 423 centerMass.bounceOffWalls(); // constrain position (and compute wall "hit")
mbedalvaro 30:d8af03f01cd4 424
mbedalvaro 30:d8af03f01cd4 425 // Change color with touch? YES
mbedalvaro 30:d8af03f01cd4 426 if (displaySensingBuffer.lightTouched)
mbedalvaro 30:d8af03f01cd4 427 transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
mbedalvaro 30:d8af03f01cd4 428 else
mbedalvaro 30:d8af03f01cd4 429 transientBlobColor=blobColor; // just the original blob color
mbedalvaro 30:d8af03f01cd4 430
mbedalvaro 30:d8af03f01cd4 431 break;
mbedalvaro 30:d8af03f01cd4 432 // ================================================================
mbedalvaro 1:a4050fee11f7 433 case SPOT_FOLLOWING:
mbedalvaro 1:a4050fee11f7 434 // we need to compute the tangencial "speed":
mbedalvaro 1:a4050fee11f7 435 // vector2D slidingVector;
mbedalvaro 2:34157ebbf56b 436 if (momentNorm>0) {
mbedalvaro 5:73cd58b58f95 437 //momentVector/=momentNorm;
mbedalvaro 3:b44ff6de81bd 438 // We can now compute the sliding vector as:
mbedalvaro 7:0df17f3078bc 439 slidingVector=unitTowardsLight.getRotatedDeg(slidingDirection? 90 : -90) * speedContourFollowing;
mbedalvaro 7:0df17f3078bc 440
mbedalvaro 7:0df17f3078bc 441 // Then the final correcting vector is the sum of sliding plus a recentering vector (with a factor if one want some smothing)
mbedalvaro 3:b44ff6de81bd 442 // This is used to update the position of the central mass - WITHOUT INTEGRATION (or with it, but for the time being, we don't do that):
mbedalvaro 7:0df17f3078bc 443 centerMass.pos +=slidingVector+ ( unitTowardsLight*(-1.0*saccadeRadius) + recenteringVectorLoop )* 0.6;
mbedalvaro 7:0df17f3078bc 444 // ATTENTION!!! the REAL radius may be smaller if the mirrors are running fast!!! (hence the last factor, that is not only for "smoothing" the
mbedalvaro 7:0df17f3078bc 445 // re-entry and avoid oscillations).
mbedalvaro 3:b44ff6de81bd 446
mbedalvaro 3:b44ff6de81bd 447 // The following function can help constraining the position "pos", but it also does too much. Do something simpler perhaps?
mbedalvaro 7:0df17f3078bc 448 centerMass.posOld=centerMass.pos; // this is necessary to compute bouceOffWalls using Verlet method... (MAKE A new variable INTEGRATION METHOD?)
mbedalvaro 7:0df17f3078bc 449
mbedalvaro 3:b44ff6de81bd 450 centerMass.bounceOffWalls(); // constrain position (and compute wall "hit")
mbedalvaro 7:0df17f3078bc 451
mbedalvaro 7:0df17f3078bc 452 if (justSearched) {
mbedalvaro 7:0df17f3078bc 453 saccadeRadius=saccadeRadius_initial;
mbedalvaro 12:0de9cd2bced5 454 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
mbedalvaro 7:0df17f3078bc 455 justSearched=false;
mbedalvaro 7:0df17f3078bc 456 }
mbedalvaro 30:d8af03f01cd4 457
mbedalvaro 2:34157ebbf56b 458 } else {
mbedalvaro 7:0df17f3078bc 459 // not on something. SEARCH MODE (or go to spot_bouncing mode?)
mbedalvaro 15:56a0bf424e8d 460 saccadeRadius+=30; if (saccadeRadius>800) saccadeRadius=saccadeRadius_initial;
mbedalvaro 12:0de9cd2bced5 461 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
mbedalvaro 7:0df17f3078bc 462 justSearched=true;
mbedalvaro 2:34157ebbf56b 463 }
mbedalvaro 1:a4050fee11f7 464
mbedalvaro 27:1ce994629ffc 465 // Change color with touch? NO
mbedalvaro 27:1ce994629ffc 466 // if (displaySensingBuffer.lightTouched)
mbedalvaro 27:1ce994629ffc 467 // transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
mbedalvaro 27:1ce994629ffc 468 // else
mbedalvaro 27:1ce994629ffc 469 transientBlobColor=blobColor; // just the original blob color
mbedalvaro 28:44b7b6e35548 470
mbedalvaro 28:44b7b6e35548 471 // change sliding direction (for countour following):
mbedalvaro 28:44b7b6e35548 472 if (blobWallCollision) {
mbedalvaro 28:44b7b6e35548 473 if (wallCounter>5) {
mbedalvaro 28:44b7b6e35548 474 slidingDirection=!slidingDirection;
mbedalvaro 28:44b7b6e35548 475 wallCounter=0;
mbedalvaro 28:44b7b6e35548 476 }
mbedalvaro 28:44b7b6e35548 477 }
mbedalvaro 28:44b7b6e35548 478 wallCounter++;
mbedalvaro 27:1ce994629ffc 479
mbedalvaro 1:a4050fee11f7 480 break;
mbedalvaro 30:d8af03f01cd4 481
mbedalvaro 30:d8af03f01cd4 482 // ================================================================
mbedalvaro 1:a4050fee11f7 483 case SPOT_BOUNCING:
mbedalvaro 1:a4050fee11f7 484 // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
mbedalvaro 1:a4050fee11f7 485 centerMass.resetForce();
mbedalvaro 5:73cd58b58f95 486
mbedalvaro 21:bc9b9383f4b6 487 if (displaySensingBuffer.lightTouched) {
mbedalvaro 7:0df17f3078bc 488 // add force; MANY POSSIBILITIES:
mbedalvaro 7:0df17f3078bc 489 // (1) Constant in norm:
mbedalvaro 7:0df17f3078bc 490 //centerMass.addForce(unitTowardsLight*saccadeRadius*factorBouncingForce);
mbedalvaro 7:0df17f3078bc 491 // Exactly what is needed to have an elastic bouncing:
mbedalvaro 7:0df17f3078bc 492
mbedalvaro 7:0df17f3078bc 493 // Proportional to the penetration depth in the dark zone (spring):
mbedalvaro 5:73cd58b58f95 494 centerMass.addForce(recenteringVectorLoop*factorBouncingForce);
mbedalvaro 7:0df17f3078bc 495 // Or proportional to the square (or something else) of the penetration:
mbedalvaro 7:0df17f3078bc 496 //centerMass.addForce(recenteringVectorLoop*normRecenteringVector*factorBouncingForce);
mbedalvaro 7:0df17f3078bc 497
mbedalvaro 5:73cd58b58f95 498 }
mbedalvaro 21:bc9b9383f4b6 499
mbedalvaro 22:d87317d7ca91 500 // Gravity? - side or central attraction?
mbedalvaro 27:1ce994629ffc 501 centerMass.addForce(gravity*centerMass.mass);
mbedalvaro 24:4e52031a495b 502
mbedalvaro 22:d87317d7ca91 503 // or central spring attraction;
mbedalvaro 24:4e52031a495b 504 //vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X);
mbedalvaro 24:4e52031a495b 505 //vector2Df dist=centerMass.pos-centerAttraction;
mbedalvaro 24:4e52031a495b 506 //centerMass.addForce(-dist*centerMass.mass*0.0007);
mbedalvaro 24:4e52031a495b 507
mbedalvaro 24:4e52031a495b 508 // or "radial gravity":
mbedalvaro 27:1ce994629ffc 509 //vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X);
mbedalvaro 27:1ce994629ffc 510 //vector2Df dist=centerMass.pos-centerAttraction;
mbedalvaro 27:1ce994629ffc 511 //centerMass.addForce(dist.normalize()*centerMass.mass*0.5);
mbedalvaro 27:1ce994629ffc 512
mbedalvaro 27:1ce994629ffc 513
mbedalvaro 27:1ce994629ffc 514 // update dynamics for the central mass:
mbedalvaro 27:1ce994629ffc 515 #ifndef VERLET_METHOD
mbedalvaro 27:1ce994629ffc 516 centerMass.addDampingForce(); // // only in case of EULER method (damping in VERLET mode is done automatically when updating)
mbedalvaro 27:1ce994629ffc 517 #endif
mbedalvaro 27:1ce994629ffc 518
mbedalvaro 27:1ce994629ffc 519 centerMass.update(); // unconstrained
mbedalvaro 27:1ce994629ffc 520 centerMass.bounceOffWalls(); // constrain position (and compute wall "hit")
mbedalvaro 27:1ce994629ffc 521
mbedalvaro 27:1ce994629ffc 522 if (displaySensingBuffer.lightTouched) {
mbedalvaro 27:1ce994629ffc 523 // do collision damping:
mbedalvaro 27:1ce994629ffc 524 centerMass.setSpeed(centerMass.getSpeed()*0.99);
mbedalvaro 27:1ce994629ffc 525 }
mbedalvaro 27:1ce994629ffc 526
mbedalvaro 27:1ce994629ffc 527 // Change color with touch? YES
mbedalvaro 27:1ce994629ffc 528 if (displaySensingBuffer.lightTouched)
mbedalvaro 27:1ce994629ffc 529 transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
mbedalvaro 27:1ce994629ffc 530 else
mbedalvaro 27:1ce994629ffc 531 transientBlobColor=blobColor; // just the original blob color
mbedalvaro 27:1ce994629ffc 532 break;
mbedalvaro 27:1ce994629ffc 533
mbedalvaro 30:d8af03f01cd4 534 // ================================================================
mbedalvaro 28:44b7b6e35548 535 case SPOT_AIR_HOCKEY:
mbedalvaro 27:1ce994629ffc 536 // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
mbedalvaro 27:1ce994629ffc 537 centerMass.resetForce();
mbedalvaro 27:1ce994629ffc 538
mbedalvaro 27:1ce994629ffc 539 if (displaySensingBuffer.lightTouched) {
mbedalvaro 27:1ce994629ffc 540 // add force; MANY POSSIBILITIES:
mbedalvaro 27:1ce994629ffc 541 // (1) Constant in norm:
mbedalvaro 27:1ce994629ffc 542 //centerMass.addForce(unitTowardsLight*saccadeRadius*factorBouncingForce);
mbedalvaro 27:1ce994629ffc 543 // Exactly what is needed to have an elastic bouncing:
mbedalvaro 27:1ce994629ffc 544
mbedalvaro 27:1ce994629ffc 545 // Proportional to the penetration depth in the dark zone (spring):
mbedalvaro 27:1ce994629ffc 546 centerMass.addForce(recenteringVectorLoop*factorBouncingForce);
mbedalvaro 27:1ce994629ffc 547 // Or proportional to the square (or something else) of the penetration:
mbedalvaro 27:1ce994629ffc 548 //centerMass.addForce(recenteringVectorLoop*normRecenteringVector*factorBouncingForce);
mbedalvaro 27:1ce994629ffc 549
mbedalvaro 27:1ce994629ffc 550 }
mbedalvaro 27:1ce994629ffc 551
mbedalvaro 28:44b7b6e35548 552 // Gravity? - side or central attraction?
mbedalvaro 28:44b7b6e35548 553 //centerMass.addForce(gravity*centerMass.mass);
mbedalvaro 28:44b7b6e35548 554
mbedalvaro 28:44b7b6e35548 555 // or central spring attraction;
mbedalvaro 28:44b7b6e35548 556 //vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X);
mbedalvaro 28:44b7b6e35548 557 //vector2Df dist=centerMass.pos-centerAttraction;
mbedalvaro 28:44b7b6e35548 558 //centerMass.addForce(-dist*centerMass.mass*0.0007);
mbedalvaro 28:44b7b6e35548 559
mbedalvaro 28:44b7b6e35548 560 // or "radial gravity":
mbedalvaro 28:44b7b6e35548 561 //vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X);
mbedalvaro 28:44b7b6e35548 562 //vector2Df dist=centerMass.pos-centerAttraction;
mbedalvaro 28:44b7b6e35548 563 //centerMass.addForce(dist.normalize()*centerMass.mass*0.5);
mbedalvaro 22:d87317d7ca91 564
mbedalvaro 1:a4050fee11f7 565
mbedalvaro 25:74cb85b85fd2 566 // update dynamics for the central mass:
mbedalvaro 1:a4050fee11f7 567 #ifndef VERLET_METHOD
mbedalvaro 1:a4050fee11f7 568 centerMass.addDampingForce(); // // only in case of EULER method (damping in VERLET mode is done automatically when updating)
mbedalvaro 1:a4050fee11f7 569 #endif
mbedalvaro 1:a4050fee11f7 570
mbedalvaro 1:a4050fee11f7 571 centerMass.update(); // unconstrained
mbedalvaro 1:a4050fee11f7 572 centerMass.bounceOffWalls(); // constrain position (and compute wall "hit")
mbedalvaro 5:73cd58b58f95 573
mbedalvaro 5:73cd58b58f95 574 if (displaySensingBuffer.lightTouched) {
mbedalvaro 5:73cd58b58f95 575 // do collision damping:
mbedalvaro 7:0df17f3078bc 576 centerMass.setSpeed(centerMass.getSpeed()*0.99);
mbedalvaro 5:73cd58b58f95 577 }
mbedalvaro 22:d87317d7ca91 578
mbedalvaro 27:1ce994629ffc 579 // Change color with touch? YES
mbedalvaro 27:1ce994629ffc 580 if (displaySensingBuffer.lightTouched)
mbedalvaro 27:1ce994629ffc 581 transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
mbedalvaro 27:1ce994629ffc 582 else
mbedalvaro 27:1ce994629ffc 583 transientBlobColor=blobColor; // just the original blob color
mbedalvaro 28:44b7b6e35548 584
mbedalvaro 30:d8af03f01cd4 585 // In case of "air hockey mode", reset position to initial positions and speeds when the spot touches any two opposites sides:
mbedalvaro 30:d8af03f01cd4 586 if ((centerMass.innerCollitionDirection.x==1)||( centerMass.innerCollitionDirection.x==-1)) {
mbedalvaro 30:d8af03f01cd4 587 transientBlobColor=blobColor|0x02;
mbedalvaro 30:d8af03f01cd4 588 for (saccadeRadius=30; saccadeRadius<900 ; saccadeRadius+=10) {
mbedalvaro 30:d8af03f01cd4 589 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
mbedalvaro 30:d8af03f01cd4 590 draw();
mbedalvaro 30:d8af03f01cd4 591 }
mbedalvaro 30:d8af03f01cd4 592 saccadeRadius=saccadeRadius_initial;
mbedalvaro 30:d8af03f01cd4 593 bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), numPoints);
mbedalvaro 30:d8af03f01cd4 594 // reset to central position:
mbedalvaro 28:44b7b6e35548 595 centerMass.setInitialCondition(startCenter, startSpeed);
mbedalvaro 30:d8af03f01cd4 596 transientBlobColor=blobColor;
mbedalvaro 30:d8af03f01cd4 597 }
mbedalvaro 28:44b7b6e35548 598 break;
mbedalvaro 27:1ce994629ffc 599
mbedalvaro 30:d8af03f01cd4 600
mbedalvaro 30:d8af03f01cd4 601 // ================================================================
mbedalvaro 30:d8af03f01cd4 602 case SPOT_LORENTZ_FORCE:
mbedalvaro 28:44b7b6e35548 603 // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
mbedalvaro 28:44b7b6e35548 604 centerMass.resetForce();
mbedalvaro 28:44b7b6e35548 605
mbedalvaro 28:44b7b6e35548 606 if (displaySensingBuffer.lightTouched) {
mbedalvaro 28:44b7b6e35548 607 // add force; MANY POSSIBILITIES:
mbedalvaro 28:44b7b6e35548 608 // (1) Constant in norm:
mbedalvaro 28:44b7b6e35548 609 //centerMass.addForce(unitTowardsLight*saccadeRadius*factorBouncingForce);
mbedalvaro 28:44b7b6e35548 610 // Exactly what is needed to have an elastic bouncing:
mbedalvaro 28:44b7b6e35548 611
mbedalvaro 28:44b7b6e35548 612 // Proportional to the penetration depth in the dark zone (spring):
mbedalvaro 28:44b7b6e35548 613 centerMass.addForce(recenteringVectorLoop*factorBouncingForce);
mbedalvaro 28:44b7b6e35548 614 // Or proportional to the square (or something else) of the penetration:
mbedalvaro 28:44b7b6e35548 615 //centerMass.addForce(recenteringVectorLoop*normRecenteringVector*factorBouncingForce);
mbedalvaro 27:1ce994629ffc 616
mbedalvaro 28:44b7b6e35548 617 }
mbedalvaro 28:44b7b6e35548 618
mbedalvaro 28:44b7b6e35548 619 // RADIAL GRAVITY for the "fountain mode":
mbedalvaro 28:44b7b6e35548 620 // vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X);
mbedalvaro 28:44b7b6e35548 621 // vector2Df radialVector=centerMass.pos-centerAttraction;
mbedalvaro 28:44b7b6e35548 622 // radialVector.rotateDeg(slidingDirection? 80 : 260);
mbedalvaro 28:44b7b6e35548 623 // centerMass.addForce(radialVector.normalize()*centerMass.mass*0.5);
mbedalvaro 28:44b7b6e35548 624
mbedalvaro 28:44b7b6e35548 625 // bubble chamber? LORENTZ FORCE:
mbedalvaro 28:44b7b6e35548 626 vector2Df speedmass=centerMass.getSpeed();
mbedalvaro 28:44b7b6e35548 627 centerMass.addForce( speedmass.getRotatedDeg(90)*0.000002*speedContourFollowing);
mbedalvaro 28:44b7b6e35548 628
mbedalvaro 28:44b7b6e35548 629 // update dynamics for the central mass:
mbedalvaro 28:44b7b6e35548 630 #ifndef VERLET_METHOD
mbedalvaro 28:44b7b6e35548 631 centerMass.addDampingForce(); // // only in case of EULER method (damping in VERLET mode is done automatically when updating)
mbedalvaro 28:44b7b6e35548 632 #endif
mbedalvaro 28:44b7b6e35548 633
mbedalvaro 28:44b7b6e35548 634 centerMass.update(); // unconstrained
mbedalvaro 28:44b7b6e35548 635 centerMass.bounceOffWalls(); // constrain position (and compute wall "hit")
mbedalvaro 28:44b7b6e35548 636
mbedalvaro 28:44b7b6e35548 637 if (displaySensingBuffer.lightTouched) {
mbedalvaro 28:44b7b6e35548 638 // do collision damping:
mbedalvaro 28:44b7b6e35548 639 centerMass.setSpeed(centerMass.getSpeed()*0.99);
mbedalvaro 28:44b7b6e35548 640 }
mbedalvaro 28:44b7b6e35548 641
mbedalvaro 28:44b7b6e35548 642 // Change color with touch? YES
mbedalvaro 28:44b7b6e35548 643 if (displaySensingBuffer.lightTouched)
mbedalvaro 28:44b7b6e35548 644 transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
mbedalvaro 28:44b7b6e35548 645 else
mbedalvaro 28:44b7b6e35548 646 transientBlobColor=blobColor; // just the original blob color
mbedalvaro 28:44b7b6e35548 647
mbedalvaro 28:44b7b6e35548 648 // In case of "fountain mode", reset position to initial positions and speeds, or change gravity sign:
mbedalvaro 28:44b7b6e35548 649 // if (blobWallCollision) centerMass.setInitialCondition(startCenter, startSpeed);
mbedalvaro 28:44b7b6e35548 650 if (blobWallCollision) slidingDirection=!slidingDirection;
mbedalvaro 1:a4050fee11f7 651 break;
mbedalvaro 30:d8af03f01cd4 652 // ================================================================
mbedalvaro 1:a4050fee11f7 653 }
mbedalvaro 17:356ca5690a59 654
mbedalvaro 1:a4050fee11f7 655 }
mbedalvaro 1:a4050fee11f7 656
mbedalvaro 1:a4050fee11f7 657
mbedalvaro 1:a4050fee11f7 658 // Drawing the graphics - this will in fact use the graphic renderer - if any - and produce the trajectory to be displayed by the laser
mbedalvaro 1:a4050fee11f7 659 void rigidLoop::draw() {
mbedalvaro 1:a4050fee11f7 660 // for the time being, there is no "opengl" like renderer, so we just copy into the lsdTrajectory:
mbedalvaro 1:a4050fee11f7 661 float cx= centerMass.pos.x;
mbedalvaro 1:a4050fee11f7 662 float cy= centerMass.pos.y;
mbedalvaro 1:a4050fee11f7 663 for (int i = 0; i < numPoints; i++) {
mbedalvaro 1:a4050fee11f7 664 // The shape is drawn by translating the scafold shape (centered on centerMass):
mbedalvaro 12:0de9cd2bced5 665 displaySensingBuffer.lsdTrajectory[i].x= (unsigned short)(bluePrint.scafold[i].x + cx ); // note: it should be an unsigned short!!
mbedalvaro 12:0de9cd2bced5 666 displaySensingBuffer.lsdTrajectory[i].y= (unsigned short)(bluePrint.scafold[i].y + cy );
mbedalvaro 12:0de9cd2bced5 667
mbedalvaro 12:0de9cd2bced5 668 // We can also do this, but ATTENTION: centerMass.pos is a vector2Df, and scafold[i] is a vector2Dd (typecasting?)
mbedalvaro 12:0de9cd2bced5 669 // displaySensingBuffer.lsdTrajectory[i]= bluePrint.scafold[i] + centerMass.pos;
mbedalvaro 12:0de9cd2bced5 670
mbedalvaro 25:74cb85b85fd2 671 //displaySensingBuffer.displayColor=blobColor; // perhaps per point color is not a good idea for the time being...
mbedalvaro 1:a4050fee11f7 672 }
mbedalvaro 25:74cb85b85fd2 673
mbedalvaro 25:74cb85b85fd2 674 // Global color for the whole loop:
mbedalvaro 27:1ce994629ffc 675 displaySensingBuffer.displayColor=transientBlobColor;
mbedalvaro 27:1ce994629ffc 676
mbedalvaro 1:a4050fee11f7 677 }
mbedalvaro 1:a4050fee11f7 678
mbedalvaro 1:a4050fee11f7 679 void rigidLoop::computeBoundingBox() {
mbedalvaro 1:a4050fee11f7 680 }
mbedalvaro 1:a4050fee11f7 681
mbedalvaro 1:a4050fee11f7 682
mbedalvaro 1:a4050fee11f7 683
mbedalvaro 1:a4050fee11f7 684 void rigidLoop::sendDataSpecific() {
mbedalvaro 1:a4050fee11f7 685 char auxstring[10];
mbedalvaro 1:a4050fee11f7 686 myled2=1; // for tests...
mbedalvaro 1:a4050fee11f7 687
mbedalvaro 1:a4050fee11f7 688 // First, set the top address of the message to the ID of the blob (not the name):
mbedalvaro 18:d72935b13858 689 // sprintf(auxstring, "%d", identifier);
mbedalvaro 18:d72935b13858 690 // sendMes.setTopAddress("0");//auxstring);
mbedalvaro 1:a4050fee11f7 691
mbedalvaro 1:a4050fee11f7 692 // ===================== OSC ======================
mbedalvaro 1:a4050fee11f7 693 if (sendOSC) {
mbedalvaro 1:a4050fee11f7 694
mbedalvaro 1:a4050fee11f7 695 // (a) Anchor mass:
mbedalvaro 1:a4050fee11f7 696 if (sendingAnchorPosition) {
mbedalvaro 18:d72935b13858 697 sprintf(auxstring, "/p %d",identifier);
mbedalvaro 18:d72935b13858 698 sendMes.setSubAddress(auxstring);
mbedalvaro 1:a4050fee11f7 699 long x, y; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 700 x=(long)(centerMass.pos.x);
mbedalvaro 1:a4050fee11f7 701 y=(long)(centerMass.pos.y);
mbedalvaro 1:a4050fee11f7 702 sendMes.setArgs( "ii", &x, &y);
mbedalvaro 1:a4050fee11f7 703 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 704 }
mbedalvaro 1:a4050fee11f7 705
mbedalvaro 1:a4050fee11f7 706 // (b) data from blob points (this is ONLY FOR TESTS, because the loop is rigid - sending the center is enough)
mbedalvaro 1:a4050fee11f7 707 if (sendingLoopPositions) {
mbedalvaro 1:a4050fee11f7 708 #ifdef SEND_AS_POINTS
mbedalvaro 1:a4050fee11f7 709 long x, y; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 710 float cx= centerMass.pos.x;
mbedalvaro 1:a4050fee11f7 711 float cy= centerMass.pos.y;
mbedalvaro 1:a4050fee11f7 712 for (int i = 0; i < numPoints; i++) {
mbedalvaro 2:34157ebbf56b 713 sprintf(auxstring, "/p%d",identifier*10+ i);//20+ i+(identifier-1)*10); // auxstring read as "/p1", "/p2", ...
mbedalvaro 1:a4050fee11f7 714 sendMes.setSubAddress(auxstring); // ATTENTION: the host computer needs to know in advance how many points are in the loop (I did not implement "bundle" messages yet...)
mbedalvaro 1:a4050fee11f7 715 x=(long)(bluePrint.scafold[i].x + cx);
mbedalvaro 1:a4050fee11f7 716 y=(long)(bluePrint.scafold[i].y + cy);
mbedalvaro 1:a4050fee11f7 717 sendMes.setArgs( "ii", &x, &y);
mbedalvaro 1:a4050fee11f7 718 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 719 }
mbedalvaro 1:a4050fee11f7 720
mbedalvaro 1:a4050fee11f7 721 #endif
mbedalvaro 1:a4050fee11f7 722 #ifdef SEND_AS_BLOB
mbedalvaro 1:a4050fee11f7 723 sendMes.clearArgs(); // no need, we won't use osc.sendOsc()...
mbedalvaro 1:a4050fee11f7 724 uint8_t blobdata[4*numPoints]; // 2 bytes per coordinate, and 2 coordinates
mbedalvaro 1:a4050fee11f7 725 float cx= centerMass.pos.x;
mbedalvaro 1:a4050fee11f7 726 float cy= centerMass.pos.y;
mbedalvaro 1:a4050fee11f7 727 for (int i = 0; i < numPoints; i++ ) {
mbedalvaro 1:a4050fee11f7 728 // note: massesLoop[i].pos.x is a "float"
mbedalvaro 1:a4050fee11f7 729 uint16_t x=(uint16_t)(bluePrint.scafold[i].x + cx);
mbedalvaro 1:a4050fee11f7 730 blobdata[4*i]=(uint8_t)x>>8; // BIG ENDIAN (send FIRST the MOST SIGNIFICANT BYTE)
mbedalvaro 1:a4050fee11f7 731 blobdata[4*i+1]=(uint8_t)x;
mbedalvaro 1:a4050fee11f7 732
mbedalvaro 1:a4050fee11f7 733 uint16_t y=(uint16_t)(bluePrint.scafold[i].y + cy);
mbedalvaro 1:a4050fee11f7 734 blobdata[4*i+2]=(uint8_t)y>>8; // BIG ENDIAN (send FIRST the MOST SIGNIFICANT BYTE)
mbedalvaro 1:a4050fee11f7 735 blobdata[4*i+3]=(uint8_t)y;
mbedalvaro 1:a4050fee11f7 736 }
mbedalvaro 1:a4050fee11f7 737 osc.sendOscBlob(&(blobdata[0]), 4*numPoints, &sendMes ); // second parameter is osc blob size in bytes
mbedalvaro 1:a4050fee11f7 738 #endif
mbedalvaro 1:a4050fee11f7 739 #ifdef SEND_AS_STRING
mbedalvaro 1:a4050fee11f7 740 sendMes.clearArgs(); // no need, we won't use osc.sendOsc()...
mbedalvaro 1:a4050fee11f7 741 uint8_t blobdata[4*numPoints]; // 2 bytes per coordinate, and 2 coordinates
mbedalvaro 1:a4050fee11f7 742 float cx= centerMass.pos.x;
mbedalvaro 1:a4050fee11f7 743 float cy= centerMass.pos.y;
mbedalvaro 1:a4050fee11f7 744 for (int i = 0; i < numPoints; i++ ) {
mbedalvaro 1:a4050fee11f7 745 // note: massesLoop[i].pos.x is a "float"
mbedalvaro 1:a4050fee11f7 746 uint16_t x=(uint16_t)(bluePrint.scafold[i].x + cx );
mbedalvaro 1:a4050fee11f7 747 blobdata[4*i]=(uint8_t)x>>8; // BIG ENDIAN (send FIRST the MOST SIGNIFICANT BYTE)
mbedalvaro 1:a4050fee11f7 748 blobdata[4*i+1]=(uint8_t)x;
mbedalvaro 1:a4050fee11f7 749
mbedalvaro 1:a4050fee11f7 750 uint16_t y=(uint16_t)(bluePrint.scafold[i].y + cy);
mbedalvaro 1:a4050fee11f7 751 blobdata[4*i+2]=(uint8_t)y>>8; // BIG ENDIAN (send FIRST the MOST SIGNIFICANT BYTE)
mbedalvaro 1:a4050fee11f7 752 blobdata[4*i+3]=(uint8_t)y;
mbedalvaro 1:a4050fee11f7 753 }
mbedalvaro 1:a4050fee11f7 754 osc.sendOscString(blobdata, 4*numPoints, &sendMes ); // second parameter is osc blob size in bytes
mbedalvaro 1:a4050fee11f7 755 #endif
mbedalvaro 1:a4050fee11f7 756 }
mbedalvaro 1:a4050fee11f7 757 if (sendingLoopRegions) {
mbedalvaro 1:a4050fee11f7 758 long x; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 759 for (int i = 0; i < numPoints; i++) {
mbedalvaro 1:a4050fee11f7 760 sprintf(auxstring, "/r%d", i); // auxstring read as "/f1", "/f2", ...
mbedalvaro 1:a4050fee11f7 761 sendMes.setSubAddress(auxstring); // ATTENTION: the host computer needs to know in advance how many points are in the loop (I did not implement "bundle" messages yet...)
mbedalvaro 1:a4050fee11f7 762 x=(long)(displaySensingBuffer.lsdTrajectory[i].lightZone>0? 1 : 0);
mbedalvaro 1:a4050fee11f7 763 sendMes.setArgs( "i", &x);
mbedalvaro 1:a4050fee11f7 764 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 765 }
mbedalvaro 1:a4050fee11f7 766 }
mbedalvaro 1:a4050fee11f7 767 if (sendingLoopTouchWall) { // global touch wall for the loop (not per point)
mbedalvaro 1:a4050fee11f7 768 long wall; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 769 sprintf(auxstring, "/bWall");
mbedalvaro 1:a4050fee11f7 770 sendMes.setSubAddress(auxstring);
mbedalvaro 1:a4050fee11f7 771 wall=(long)(blobWallCollision? 1 : 0);
mbedalvaro 1:a4050fee11f7 772 sendMes.setArgs( "i", &wall);
mbedalvaro 1:a4050fee11f7 773 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 774 }
mbedalvaro 1:a4050fee11f7 775
mbedalvaro 1:a4050fee11f7 776 // (d) Light sensing statistics:
mbedalvaro 1:a4050fee11f7 777 if (sendingBlobMaxMin) {
mbedalvaro 1:a4050fee11f7 778 sendMes.setSubAddress("/maxmin");
mbedalvaro 1:a4050fee11f7 779 long x, y; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 780 x=(long)(displaySensingBuffer.maxI);
mbedalvaro 1:a4050fee11f7 781 y=(long)(displaySensingBuffer.minI);
mbedalvaro 1:a4050fee11f7 782 sendMes.setArgs( "ii", &x, &y);
mbedalvaro 1:a4050fee11f7 783 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 784 }
mbedalvaro 1:a4050fee11f7 785
mbedalvaro 1:a4050fee11f7 786 // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known).
mbedalvaro 1:a4050fee11f7 787 if (sendingRecenteringVector) {
mbedalvaro 1:a4050fee11f7 788 sendMes.setSubAddress("/rvector");
mbedalvaro 1:a4050fee11f7 789 long x, y; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 790 x=(long)(recenteringVectorLoop.x);
mbedalvaro 1:a4050fee11f7 791 y=(long)(recenteringVectorLoop.y);
mbedalvaro 1:a4050fee11f7 792 sendMes.setArgs( "ii", &x, &y);
mbedalvaro 1:a4050fee11f7 793 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 794 }
mbedalvaro 1:a4050fee11f7 795 if (sendingRecenteringAngle) {
mbedalvaro 18:d72935b13858 796 sprintf(auxstring, "/v %d",identifier);
mbedalvaro 18:d72935b13858 797 sendMes.setSubAddress(auxstring);
mbedalvaro 1:a4050fee11f7 798 long x; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 799 x=(long)(angleRecenteringVector);
mbedalvaro 1:a4050fee11f7 800 sendMes.setArgs( "i", &x);
mbedalvaro 1:a4050fee11f7 801 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 802 }
mbedalvaro 1:a4050fee11f7 803 if (sendingRecenteringNorm) {
mbedalvaro 1:a4050fee11f7 804 sendMes.setSubAddress("/rnorm");
mbedalvaro 1:a4050fee11f7 805 long x; //ATTENTION: parameters to setArgs should be long or unsigned long only (not int!!)
mbedalvaro 1:a4050fee11f7 806 x=(long)(normRecenteringVector);
mbedalvaro 1:a4050fee11f7 807 sendMes.setArgs( "i", &x);
mbedalvaro 1:a4050fee11f7 808 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 809 }
mbedalvaro 1:a4050fee11f7 810
mbedalvaro 1:a4050fee11f7 811 if (sendingTouched) {
mbedalvaro 1:a4050fee11f7 812 if (displaySensingBuffer.lightTouched) {
mbedalvaro 1:a4050fee11f7 813 sendMes.clearArgs(); // there are no arguments to send
mbedalvaro 1:a4050fee11f7 814 sendMes.setSubAddress("/touched");
mbedalvaro 1:a4050fee11f7 815 osc.sendOsc( &sendMes );
mbedalvaro 1:a4050fee11f7 816 }
mbedalvaro 1:a4050fee11f7 817 }
mbedalvaro 1:a4050fee11f7 818
mbedalvaro 1:a4050fee11f7 819 } // end of OSC sending per-spot
mbedalvaro 1:a4050fee11f7 820
mbedalvaro 1:a4050fee11f7 821 // ===================== SERIAL ======================
mbedalvaro 1:a4050fee11f7 822 if (sendSerial) {
mbedalvaro 1:a4050fee11f7 823 //.. to do
mbedalvaro 1:a4050fee11f7 824 }
mbedalvaro 1:a4050fee11f7 825
mbedalvaro 1:a4050fee11f7 826 myled2=0; // for tests...
mbedalvaro 1:a4050fee11f7 827 }