iCub-main
Triangle.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2009 RobotCub Consortium
5  * Author: Alessandro Scalzo alessandro.scalzo@iit.it
6  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
7  *
8  */
9 
10 #include "include/TouchSensor.h"
11 
12 #ifndef __ALE_TRIANGLE_H__
13 #define __ALE_TRIANGLE_H__
14 
15 class Triangle : public TouchSensor
16 {
17 public:
18  Triangle(double cx,double cy,double th,double gain=1.0,int layoutNum=0,int lrMirror=0)
19  {
20  const double DEG2RAD=M_PI/180.0;
21 
22  const double CST=cos(DEG2RAD*th);
23  const double SNT=sin(DEG2RAD*th);
24 
25  const double H=sin(DEG2RAD*60.0);
26  const double L=2.0*H/9.0;
27 
28  dGain=gain;
29  ilrMirror=lrMirror;
30  ilayoutNum=layoutNum;
31  nVerts=3;
32  nTaxels=12;
33  m_RadiusOrig=2.0;
34 
35  dX[5]=L*cos(DEG2RAD*30.0); dX[4]=0.5-dX[5]; dX[2]=0.5+dX[5]; dX[1]=1.0-dX[5];
36  dX[6]=0.25; dX[3]=0.5; dX[0]=0.75;
37  dX[7]=0.25+dX[5]; dX[11]=0.75-dX[5];
38  dX[8]=dX[7]; dX[10]=dX[11];
39  dX[9]=0.5;
40 
41  dY[5]=L*sin(DEG2RAD*30.0); dY[4]=dY[5]; dY[2]=dY[5]; dY[1]=dY[5];
42  dY[6]=0.5*H-L; dY[3]=L; dY[0]=dY[6];
43  dY[7]=0.5*H-L*sin(DEG2RAD*30.0); dY[11]=dY[7];
44  dY[8]=0.5*H+L*sin(DEG2RAD*30.0); dY[10]=dY[8];
45  dY[9]=H-L;
46 
47  for (int i=0; i<nTaxels; ++i)
48  {
49  double x=30.0*dX[i]-15.0;
50  double y=30.0*dY[i]-10.0*H;
51 
52  if (lrMirror==1) x=-x;
53  dX[i]=cx+CST*x-SNT*y;
54  dY[i]=cy+SNT*x+CST*y;
55  }
56 
57  dXv[0]=-15.0;
58  dYv[0]=-8.66;
59 
60  dXv[1]=+15.0;
61  dYv[1]=-8.66;
62 
63  dXv[2]=0;
64  dYv[2]=+17.32;
65 
66  for (int i=0; i<nVerts; ++i)
67  {
68  double x=dXv[i];
69  double y=dYv[i];
70  if (lrMirror==1) x=-x;
71 
72  dXv[i]=cx+CST*x-SNT*y;
73  dYv[i]=cy+SNT*x+CST*y;
74  }
75 
76  // in static definition
77  //dXmin=dYmin= HUGE;
78  //dXmax=dYmax=-HUGE;
79 
80  for (int i=0; i<nVerts; ++i)
81  {
82  if (dXv[i]<dXmin) dXmin=dXv[i];
83  if (dXv[i]>dXmax) dXmax=dXv[i];
84  if (dYv[i]<dYmin) dYmin=dYv[i];
85  if (dYv[i]>dYmax) dYmax=dYv[i];
86  }
87 
88  dXc=cx;
89  dYc=cy;
90  }
91 };
92 
93 #endif
#define M_PI
Definition: XSensMTx.cpp:24
constexpr double DEG2RAD
double dX[MAX_TAXELS]
Definition: TouchSensor.h:382
double dYc
Definition: TouchSensor.h:385
int x[MAX_TAXELS]
Definition: TouchSensor.h:402
double m_RadiusOrig
Definition: TouchSensor.h:390
static double dXmin
Definition: TouchSensor.h:383
double dXc
Definition: TouchSensor.h:385
static double dYmax
Definition: TouchSensor.h:383
double dXv[8]
Definition: TouchSensor.h:384
double dY[MAX_TAXELS]
Definition: TouchSensor.h:382
static double dXmax
Definition: TouchSensor.h:383
double dYv[8]
Definition: TouchSensor.h:384
double dGain
Definition: TouchSensor.h:386
int y[MAX_TAXELS]
Definition: TouchSensor.h:402
static double dYmin
Definition: TouchSensor.h:383
Triangle(double cx, double cy, double th, double gain=1.0, int layoutNum=0, int lrMirror=0)
Definition: Triangle.h:18