22 #include "phymarxbot.h"
24 #include "phycylinder.h"
26 #include "phyballandsocket.h"
27 #include "physphere.h"
28 #include "physuspension.h"
29 #include "phycompoundobject.h"
32 #include "mathutils.h"
38 const real PhyMarXbot::basex = 0.034f;
39 const real PhyMarXbot::basey = 0.143f;
40 const real PhyMarXbot::basez = 0.048f;
41 const real PhyMarXbot::basem = 0.4f;
42 const real PhyMarXbot::bodyr = 0.085f;
43 const real PhyMarXbot::bodyh = 0.0055f;
44 const real PhyMarXbot::bodym = 0.02f;
45 const real PhyMarXbot::axledistance = 0.104f;
46 const real PhyMarXbot::trackradius = 0.022f;
47 const real PhyMarXbot::trackheight = 0.0295f;
48 const real PhyMarXbot::trackm = 0.05f;
49 const real PhyMarXbot::treaddepth = 0.004f;
50 const real PhyMarXbot::wheelr = 0.027f;
51 const real PhyMarXbot::wheelh = 0.0215f;
52 const real PhyMarXbot::wheelm = 0.02f;
53 const real PhyMarXbot::turreth = 0.0385f;
54 const real PhyMarXbot::turretm = 0.08f;
55 const real PhyMarXbot::attachdevr = bodyr;
56 const real PhyMarXbot::attachdevx = turreth * 0.8;
57 const real PhyMarXbot::attachdevy = turreth * 0.4;
58 const real PhyMarXbot::attachdevz = turreth * 0.2;
59 const real PhyMarXbot::attachdevm = 0.03;
62 kinematicSimulation =
false;
90 QVector<PhyObject*> objs;
94 obj =
new PhyBox( basex+2.0f*trackheight, axledistance, basez+trackradius*2.0f, w );
97 tm.w_pos[2] = (basez+trackradius*2.0f)/2.0f + treaddepth;
104 basev->setMaterial(
"marXbotLowerBody");
121 double xoffs[6] = { 1, -1, 1, -1, 1, -1 };
122 double yoffs[6] = { 0, 0, 1, 1, -1, -1 };
125 for(
int i=0; i<6; i++ ) {
129 xoffs[i] * (basex + trackheight)/2.0f + (yoffs[i]==0 ? xoffs[i]*(trackheight/2.0+wheelh/2.0f+0.006f) : 0.0f),
130 yoffs[i] * (axledistance/2.0f),
134 wtm.w_pos[2] = wheelr;
135 awheel =
new PhyCylinder( wheelr, wheelh, w,
"motorWheel" );
138 wtm.w_pos[2] = treaddepth-0.003f;
139 awheel =
new PhySphere( treaddepth, w,
"passiveWheel" );
141 wheelstm.append( wtm );
143 awheel->setMaterial(
"marXbotLowerBody" );
147 wheels.append( awheel );
154 wheels[i]->matrix().w_pos,
157 joint->
dofs()[0]->disableLimits();
161 wheels[i]->
matrix().w_pos,
166 wheelJoints.append( joint );
173 turrettm.w_pos.z = 0.005f + basez + bodyh + turreth + 0.0015f;
175 turretv->setMaterial(
"marXbotUpperBody");
179 forcesensor =
new PhyFixed( basev, turretv, w );
180 forcesensor->
setOwner(
this,
false );
184 attachdevjoint = NULL;
188 attachdevCtrl->
setOwner(
this,
false );
191 QVector<PhyDOF*> motors;
192 motors << wheelJoints[0]->dofs()[0] << wheelJoints[1]->dofs()[0];
194 wheelsCtrl->
setOwner(
this,
false );
196 #warning QUI DECIDERE PER LE VELOCITÀ MASSIME E MINIME DELLE RUOTE
205 QVector<SingleIR> sensors;
208 #warning QUI DECIDERE PER I RANGE/APERTURE E LE POSIZIONI (SPECIE PER I GROUND)
211 for (
unsigned int i = 0; i < 24; i++) {
212 const double curAngle = double(i) * (360.0 / 24.0) + ((360.0 / 24.0) / 2.0);
213 const double radius = bodyr;
216 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
217 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
218 mtr.w_pos.z = 0.005f + basez + bodyh + turreth / 2.0f + 0.0015f;
220 sensors.append(
SingleIR(basev, mtr, 0.02, 0.1, 10.0, 5));
227 const double distFromBorder = 0.003;
230 mtr.w_pos =
wVector(basex / 2.0f + trackheight - distFromBorder, axledistance / 2.0f - distFromBorder, treaddepth);
231 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
232 mtr.w_pos =
wVector(basex / 2.0f + trackheight - distFromBorder, -axledistance / 2.0f + distFromBorder, treaddepth);
233 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
234 mtr.w_pos =
wVector(-basex / 2.0f - trackheight + distFromBorder, axledistance / 2.0f - distFromBorder, treaddepth);
235 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
236 mtr.w_pos =
wVector(-basex / 2.0f - trackheight + distFromBorder, -axledistance / 2.0f + distFromBorder, treaddepth);
237 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
244 for (
unsigned int i = 0; i < 8; i++) {
245 const double curAngle = double(i) * (360.0 / 8.0);
246 const double radius = bodyr - 0.003;
249 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
250 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
251 mtr.w_pos.z = 0.005f + basez + bodyh + turreth / 2.0f + 0.0015f;
253 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
260 w->pushObject(
this );
265 attachdevCtrl->attachmentDeviceAboutToBeDestroyed();
268 delete attachdevCtrl;
270 delete groundBottomIR;
271 delete groundAroundIR;
272 foreach(
PhyJoint* susp, wheelJoints ) {
279 delete attachdevjoint;
295 if (kinematicSimulation) {
298 wheeledRobotsComputeKinematicMovement(mtr, leftWheelVelocity, rightWheelVelocity, wheelr, wheelstm[0].w_pos.x - wheelstm[1].w_pos.x,
world()->timeStep());
350 displacement.w_pos =
wVector(0.0, 0.0, basez + trackradius * 2.0f + treaddepth + turreth - 0.010f + 0.0001f);
360 return (frontMarker != NULL);
371 attachdev =
new PhyBox(attachdevx, attachdevy, attachdevz,
world());
372 attachdev->
setMass(attachdevm);
373 attachdevtm = turretv->
matrix();
374 attachdevtm.w_pos.y -= attachdevr;
380 attachdevjoint->
dofs()[0]->disableLimits();
381 attachdevjoint->
dofs()[0]->setDesiredPosition(0.0);
382 attachdevjoint->
dofs()[0]->setStiffness(0.1);
383 attachdevjoint->
setOwner(
this,
false);
386 attachdevCtrl->attachmentDeviceAboutToBeDestroyed();
388 delete attachdevjoint;
389 attachdevjoint = NULL;
397 if (kinematicSimulation == k) {
401 kinematicSimulation = k;
402 if (kinematicSimulation) {
404 for (
int i = 0; i < wheelJoints.size(); i++) {
405 wheelJoints[i]->enable(
false);
407 forcesensor->
enable(
false);
408 if (attachdevjoint != NULL) {
409 attachdevjoint->
enable(
false);
414 for (
int i = 0; i < wheels.size(); i++) {
415 wheels[i]->setKinematic(
true,
true);
418 if (attachdev != NULL) {
424 for (
int i = 0; i < wheels.size(); i++) {
425 wheels[i]->setKinematic(
false);
428 if (attachdev != NULL) {
433 for (
int i = 0; i < wheelJoints.size(); i++) {
434 wheelJoints[i]->enable(
true);
435 wheelJoints[i]->updateJointInfo();
437 forcesensor->
enable(
true);
439 if (attachdevjoint != NULL) {
440 attachdevjoint->
enable(
true);
448 leftWheelVelocity = velocity;
453 rightWheelVelocity = velocity;
459 for(
int i=0; i<wheels.size(); i++ ) {
460 wheels[i]->setMatrix( wheelstm[i] * tm );
462 foreach(
PhyJoint* ajoint, wheelJoints ) {
467 if ((attachdev != NULL) && (attachdevjoint != NULL)) {
468 attachdev->
setMatrix( attachdevtm * tm );
474 const real PhyMarXbot::basex = 0.034f;
475 const real PhyMarXbot::basey = 0.143f;
476 const real PhyMarXbot::basez = 0.048f;
477 const real PhyMarXbot::basem = 0.4f;
478 const real PhyMarXbot::bodyr = 0.085f;
479 const real PhyMarXbot::bodyh = 0.0055f;
480 const real PhyMarXbot::bodym = 0.02f;
481 const real PhyMarXbot::axledistance = 0.104f;
482 const real PhyMarXbot::trackradius = 0.022f;
483 const real PhyMarXbot::trackheight = 0.0295f;
484 const real PhyMarXbot::trackm = 0.05f;
485 const real PhyMarXbot::treaddepth = 0.004f;
486 const real PhyMarXbot::wheelr = 0.027f;
487 const real PhyMarXbot::wheelh = 0.0215f;
488 const real PhyMarXbot::wheelm = 0.02f;
489 const real PhyMarXbot::attachringh = 0.0285f;
490 const real PhyMarXbot::attachringm = 0.08f;
491 const real PhyMarXbot::ledsh = 0.010f;
492 const real PhyMarXbot::ledsradius = 0.080f;
493 const real PhyMarXbot::ledsm = 0.03f;
496 kinematicSimulation =
false;
523 QVector<PhyObject*> objs;
526 #ifdef MARXBOT_DETAILED
529 obj =
new PhyBox( basex, basey, basez, w );
530 tm.w_pos[2] = basez/2.0f + 0.015f;
536 obj->setMass( bodym );
538 tm.w_pos[2] = 0.015f + basez + bodyh/2.0f;
539 obj->setMatrix( tm );
542 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
544 tm.w_pos[0] = (basex + trackheight)/2.0f;
545 tm.w_pos[2] = trackradius + treaddepth;
546 obj->setMass( trackm );
547 obj->setMatrix( tm );
549 obj =
new PhyCylinder( trackradius, trackheight, w );
550 obj->setMass( wheelm );
551 tm.w_pos[1] = axledistance/2.0;
552 obj->setMatrix( tm );
554 obj =
new PhyCylinder( trackradius, trackheight, w );
555 obj->setMass( wheelm );
556 tm.w_pos[1] = -axledistance/2.0;
557 obj->setMatrix( tm );
560 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
562 tm.w_pos[0] = -(basex + trackheight)/2.0f;
563 tm.w_pos[2] = trackradius + treaddepth;
564 obj->setMass( trackm );
565 obj->setMatrix( tm );
567 obj =
new PhyCylinder( trackradius, trackheight, w );
568 obj->setMass( wheelm );
569 tm.w_pos[1] = axledistance/2.0;
570 obj->setMatrix( tm );
572 obj =
new PhyCylinder( trackradius, trackheight, w );
573 obj->setMass( wheelm );
574 tm.w_pos[1] = -axledistance/2.0;
575 obj->setMatrix( tm );
579 obj =
new PhyBox( basex+2.0f*trackheight, axledistance, basez+trackradius*2.0f, w );
580 obj->setMass( basem+bodym );
582 tm.w_pos[2] = (basez+trackradius*2.0f)/2.0f + treaddepth;
583 obj->setMatrix( tm );
589 base->setMaterial(
"marXbotLowerBody");
605 double xoffs[6] = { 1, -1, 1, -1, 1, -1 };
606 double yoffs[6] = { 0, 0, 1, 1, -1, -1 };
609 for(
int i=0; i<6; i++ ) {
613 xoffs[i] * (basex + trackheight)/2.0f + (yoffs[i]==0 ? xoffs[i]*(trackheight/2.0+wheelh/2.0f+0.006f) : 0.0f),
614 yoffs[i] * (axledistance/2.0f),
618 wtm.w_pos[2] = wheelr;
619 awheel =
new PhyCylinder( wheelr, wheelh, w,
"motorWheel" );
622 wtm.w_pos[2] = treaddepth-0.003f;
623 awheel =
new PhySphere( treaddepth, w,
"passiveWheel" );
625 wheelstm.append( wtm );
628 awheel->setMaterial(
"marXbotLowerBody" );
631 wheels.append( awheel );
638 wheels[i]->matrix().w_pos,
641 joint->
dofs()[0]->disableLimits();
645 wheels[i]->
matrix().w_pos,
650 wheelJoints.append( joint );
654 #ifdef MARXBOT_DETAILED
656 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
657 obj->setMass( attachringm );
659 tm.w_pos[0] = 0.005f;
660 obj->setMatrix( tm );
662 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
663 obj->setMass( attachringm );
665 tm.w_pos[0] = -0.005f;
666 obj->setMatrix( tm );
669 obj->setMass( ledsm );
670 obj->setTexture(
"marXbot_12leds" );
671 obj->setUseColorTextureOfOwner(
false );
672 tm.w_pos[0] = attachringh/2.0f + ledsh/2.0f + 0.0015f;
673 obj->setMatrix( tm );
677 obj =
new PhyCylinder( bodyr, attachringh+ledsh, w );
678 obj->setMass( attachringm );
680 tm.w_pos[0] = attachringh/2.0f-0.010f;
681 obj->setMatrix( tm );
686 attachring->setMaterial(
"marXbotUpperBody");
687 attachring->
setOwner(
this,
false );
690 attachringtm.w_pos[2] = 0.015f + basez + bodyh + attachringh/2.0f + 0.0015f;
691 attachring->
setMatrix( attachringtm * basetm );
693 forcesensor =
new PhyFixed( base, attachring, w );
694 forcesensor->
setOwner(
this,
false );
697 QVector<PhyDOF*> motors;
698 motors << wheelJoints[0]->dofs()[0] << wheelJoints[1]->dofs()[0];
700 wheelsCtrl->
setOwner(
this,
false );
702 #warning QUI DECIDERE PER LE VELOCITÀ MASSIME E MINIME DELLE RUOTE
711 QVector<SingleIR> sensors;
714 #warning QUI DECIDERE PER I RANGE/APERTURE E LE POSIZIONI (SPECIE PER I GROUND)
717 for (
unsigned int i = 0; i < 24; i++) {
718 const double curAngle = double(i) * (360.0 / 24.0) + ((360.0 / 24.0) / 2.0);
719 const double radius = bodyr;
722 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
723 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
724 mtr.w_pos.z = 0.015f + basez + bodyh/2.0f;
726 sensors.append(
SingleIR(base, mtr, 0.02, 0.1, 10.0, 5));
733 const double distFromBorder = 0.003;
736 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
737 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
738 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
739 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
740 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
741 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
742 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
743 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
750 for (
unsigned int i = 0; i < 8; i++) {
751 const double curAngle = double(i) * (360.0 / 8.0);
752 const double radius = bodyr - 0.003;
755 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
756 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
757 mtr.w_pos.z = 0.015f + basez;
759 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
766 w->pushObject(
this );
770 foreach(
PhyJoint* susp, wheelJoints ) {
781 delete groundBottomIR;
782 delete groundAroundIR;
792 if (kinematicSimulation) {
795 wheeledRobotsComputeKinematicMovement(mtr, leftWheelVelocity, rightWheelVelocity, wheelr, wheelstm[0].w_pos.x - wheelstm[1].w_pos.x,
world()->timeStep());
836 if (kinematicSimulation == k) {
840 kinematicSimulation = k;
841 if (kinematicSimulation) {
843 for (
int i = 0; i < wheelJoints.size(); i++) {
844 wheelJoints[i]->enable(
false);
846 forcesensor->
enable(
false);
850 for (
int i = 0; i < wheels.size(); i++) {
851 wheels[i]->setKinematic(
true,
true);
857 for (
int i = 0; i < wheels.size(); i++) {
858 wheels[i]->setKinematic(
false);
863 for (
int i = 0; i < wheelJoints.size(); i++) {
864 wheelJoints[i]->enable(
true);
865 wheelJoints[i]->updateJointInfo();
867 forcesensor->
enable(
true);
874 leftWheelVelocity = velocity;
879 rightWheelVelocity = velocity;
885 for(
int i=0; i<wheels.size(); i++ ) {
886 wheels[i]->setMatrix( wheelstm[i] * tm );
888 foreach(
PhyJoint* ajoint, wheelJoints ) {
891 attachring->
setMatrix( attachringtm * tm );