22 #include "phymarxbot.h"
24 #include "phycylinder.h"
26 #include "phyballandsocket.h"
27 #include "physphere.h"
28 #include "physuspension.h"
29 #include "phycompoundobject.h"
31 #include "mathutils.h"
36 const real PhyMarXbot::basex = 0.034f;
37 const real PhyMarXbot::basey = 0.143f;
38 const real PhyMarXbot::basez = 0.048f;
39 const real PhyMarXbot::basem = 0.4f;
40 const real PhyMarXbot::bodyr = 0.085f;
41 const real PhyMarXbot::bodyh = 0.0055f;
42 const real PhyMarXbot::bodym = 0.02f;
43 const real PhyMarXbot::axledistance = 0.104f;
44 const real PhyMarXbot::trackradius = 0.022f;
45 const real PhyMarXbot::trackheight = 0.0295f;
46 const real PhyMarXbot::trackm = 0.05f;
47 const real PhyMarXbot::treaddepth = 0.004f;
48 const real PhyMarXbot::wheelr = 0.027f;
49 const real PhyMarXbot::wheelh = 0.0215f;
50 const real PhyMarXbot::wheelm = 0.02f;
51 const real PhyMarXbot::attachringh = 0.0285f;
52 const real PhyMarXbot::attachringm = 0.08f;
53 const real PhyMarXbot::ledsh = 0.010f;
54 const real PhyMarXbot::ledsradius = 0.080f;
55 const real PhyMarXbot::ledsm = 0.03f;
58 kinematicSimulation =
false;
85 QVector<PhyObject*> objs;
88 #ifdef MARXBOT_DETAILED
91 obj =
new PhyBox( basex, basey, basez, w );
92 tm.w_pos[2] = basez/2.0f + 0.015f;
98 obj->setMass( bodym );
100 tm.w_pos[2] = 0.015f + basez + bodyh/2.0f;
101 obj->setMatrix( tm );
104 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
106 tm.w_pos[0] = (basex + trackheight)/2.0f;
107 tm.w_pos[2] = trackradius + treaddepth;
108 obj->setMass( trackm );
109 obj->setMatrix( tm );
111 obj =
new PhyCylinder( trackradius, trackheight, w );
112 obj->setMass( wheelm );
113 tm.w_pos[1] = axledistance/2.0;
114 obj->setMatrix( tm );
116 obj =
new PhyCylinder( trackradius, trackheight, w );
117 obj->setMass( wheelm );
118 tm.w_pos[1] = -axledistance/2.0;
119 obj->setMatrix( tm );
122 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
124 tm.w_pos[0] = -(basex + trackheight)/2.0f;
125 tm.w_pos[2] = trackradius + treaddepth;
126 obj->setMass( trackm );
127 obj->setMatrix( tm );
129 obj =
new PhyCylinder( trackradius, trackheight, w );
130 obj->setMass( wheelm );
131 tm.w_pos[1] = axledistance/2.0;
132 obj->setMatrix( tm );
134 obj =
new PhyCylinder( trackradius, trackheight, w );
135 obj->setMass( wheelm );
136 tm.w_pos[1] = -axledistance/2.0;
137 obj->setMatrix( tm );
141 obj =
new PhyBox( basex+2.0f*trackheight, axledistance, basez+trackradius*2.0f, w );
142 obj->setMass( basem+bodym );
144 tm.w_pos[2] = (basez+trackradius*2.0f)/2.0f + treaddepth;
145 obj->setMatrix( tm );
151 base->setMaterial(
"marXbotLowerBody");
167 double xoffs[6] = { 1, -1, 1, -1, 1, -1 };
168 double yoffs[6] = { 0, 0, 1, 1, -1, -1 };
171 for(
int i=0; i<6; i++ ) {
175 xoffs[i] * (basex + trackheight)/2.0f + (yoffs[i]==0 ? xoffs[i]*(trackheight/2.0+wheelh/2.0f+0.006f) : 0.0f),
176 yoffs[i] * (axledistance/2.0f),
180 wtm.w_pos[2] = wheelr;
181 awheel =
new PhyCylinder( wheelr, wheelh, w,
"motorWheel" );
184 wtm.w_pos[2] = treaddepth-0.003f;
185 awheel =
new PhySphere( treaddepth, w,
"passiveWheel" );
187 wheelstm.append( wtm );
190 awheel->setMaterial(
"marXbotLowerBody" );
193 wheels.append( awheel );
200 wheels[i]->matrix().w_pos,
203 joint->
dofs()[0]->disableLimits();
207 wheels[i]->
matrix().w_pos,
212 wheelJoints.append( joint );
216 #ifdef MARXBOT_DETAILED
218 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
219 obj->setMass( attachringm );
221 tm.w_pos[0] = 0.005f;
222 obj->setMatrix( tm );
224 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
225 obj->setMass( attachringm );
227 tm.w_pos[0] = -0.005f;
228 obj->setMatrix( tm );
231 obj->setMass( ledsm );
232 obj->setTexture(
"marXbot_12leds" );
233 obj->setUseColorTextureOfOwner(
false );
234 tm.w_pos[0] = attachringh/2.0f + ledsh/2.0f + 0.0015f;
235 obj->setMatrix( tm );
239 obj =
new PhyCylinder( bodyr, attachringh+ledsh, w );
240 obj->setMass( attachringm );
242 tm.w_pos[0] = attachringh/2.0f-0.010f;
243 obj->setMatrix( tm );
248 attachring->setMaterial(
"marXbotUpperBody");
249 attachring->
setOwner(
this,
false );
252 attachringtm.w_pos[2] = 0.015f + basez + bodyh + attachringh/2.0f + 0.0015f;
253 attachring->
setMatrix( attachringtm * basetm );
255 forcesensor =
new PhyFixed( base, attachring, w );
256 forcesensor->
setOwner(
this,
false );
259 QVector<PhyDOF*> motors;
260 motors << wheelJoints[0]->dofs()[0] << wheelJoints[1]->dofs()[0];
262 wheelsCtrl->
setOwner(
this,
false );
264 #warning QUI DECIDERE PER LE VELOCITÀ MASSIME E MINIME DELLE RUOTE
273 QVector<SingleIR> sensors;
276 #warning QUI DECIDERE PER I RANGE/APERTURE E LE POSIZIONI (SPECIE PER I GROUND)
279 for (
unsigned int i = 0; i < 24; i++) {
280 const double curAngle = double(i) * (360.0 / 24.0) + ((360.0 / 24.0) / 2.0);
281 const double radius = bodyr;
284 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
285 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
286 mtr.w_pos.z = 0.015f + basez + bodyh/2.0f;
288 sensors.append(
SingleIR(base, mtr, 0.02, 0.1, 10.0, 5));
295 const double distFromBorder = 0.003;
298 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
299 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
300 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
301 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
302 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
303 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
304 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
305 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
312 for (
unsigned int i = 0; i < 8; i++) {
313 const double curAngle = double(i) * (360.0 / 8.0);
314 const double radius = bodyr - 0.003;
317 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
318 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
319 mtr.w_pos.z = 0.015f + basez;
321 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
328 w->pushObject(
this );
332 foreach(
PhyJoint* susp, wheelJoints ) {
343 delete groundBottomIR;
344 delete groundAroundIR;
354 if (kinematicSimulation) {
357 wheeledRobotsComputeKinematicMovement(mtr, leftWheelVelocity, rightWheelVelocity, wheelr, wheelstm[0].w_pos.x - wheelstm[1].w_pos.x,
world()->timeStep());
398 if (kinematicSimulation == k) {
402 kinematicSimulation = k;
403 if (kinematicSimulation) {
405 for (
int i = 0; i < wheelJoints.size(); i++) {
406 wheelJoints[i]->enable(
false);
408 forcesensor->
enable(
false);
412 for (
int i = 0; i < wheels.size(); i++) {
413 wheels[i]->setKinematic(
true,
true);
419 for (
int i = 0; i < wheels.size(); i++) {
420 wheels[i]->setKinematic(
false);
425 for (
int i = 0; i < wheelJoints.size(); i++) {
426 wheelJoints[i]->enable(
true);
427 wheelJoints[i]->updateJointInfo();
429 forcesensor->
enable(
true);
436 leftWheelVelocity = velocity;
441 rightWheelVelocity = velocity;
447 for(
int i=0; i<wheels.size(); i++ ) {
448 wheels[i]->setMatrix( wheelstm[i] * tm );
450 foreach(
PhyJoint* ajoint, wheelJoints ) {
453 attachring->
setMatrix( attachringtm * tm );