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;
406 if (kinematicSimulation == k) {
410 kinematicSimulation = k;
411 if (kinematicSimulation) {
413 for (
int i = 0; i < wheelJoints.size(); i++) {
414 wheelJoints[i]->enable(
false);
416 forcesensor->
enable(
false);
417 if (attachdevjoint != NULL) {
418 attachdevjoint->
enable(
false);
423 for (
int i = 0; i < wheels.size(); i++) {
424 wheels[i]->setKinematic(
true,
true);
427 if (attachdev != NULL) {
433 for (
int i = 0; i < wheels.size(); i++) {
434 wheels[i]->setKinematic(
false);
437 if (attachdev != NULL) {
442 for (
int i = 0; i < wheelJoints.size(); i++) {
443 wheelJoints[i]->enable(
true);
444 wheelJoints[i]->updateJointInfo();
446 forcesensor->
enable(
true);
448 if (attachdevjoint != NULL) {
449 attachdevjoint->
enable(
true);
457 leftWheelVelocity = velocity;
462 rightWheelVelocity = velocity;
468 for(
int i=0; i<wheels.size(); i++ ) {
469 wheels[i]->setMatrix( wheelstm[i] * tm );
471 foreach(
PhyJoint* ajoint, wheelJoints ) {
476 if ((attachdev != NULL) && (attachdevjoint != NULL)) {
477 attachdev->
setMatrix( attachdevtm * tm );
483 const real PhyMarXbot::basex = 0.034f;
484 const real PhyMarXbot::basey = 0.143f;
485 const real PhyMarXbot::basez = 0.048f;
486 const real PhyMarXbot::basem = 0.4f;
487 const real PhyMarXbot::bodyr = 0.085f;
488 const real PhyMarXbot::bodyh = 0.0055f;
489 const real PhyMarXbot::bodym = 0.02f;
490 const real PhyMarXbot::axledistance = 0.104f;
491 const real PhyMarXbot::trackradius = 0.022f;
492 const real PhyMarXbot::trackheight = 0.0295f;
493 const real PhyMarXbot::trackm = 0.05f;
494 const real PhyMarXbot::treaddepth = 0.004f;
495 const real PhyMarXbot::wheelr = 0.027f;
496 const real PhyMarXbot::wheelh = 0.0215f;
497 const real PhyMarXbot::wheelm = 0.02f;
498 const real PhyMarXbot::attachringh = 0.0285f;
499 const real PhyMarXbot::attachringm = 0.08f;
500 const real PhyMarXbot::ledsh = 0.010f;
501 const real PhyMarXbot::ledsradius = 0.080f;
502 const real PhyMarXbot::ledsm = 0.03f;
505 kinematicSimulation =
false;
532 QVector<PhyObject*> objs;
535 #ifdef MARXBOT_DETAILED
538 obj =
new PhyBox( basex, basey, basez, w );
539 tm.w_pos[2] = basez/2.0f + 0.015f;
545 obj->setMass( bodym );
547 tm.w_pos[2] = 0.015f + basez + bodyh/2.0f;
548 obj->setMatrix( tm );
551 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
553 tm.w_pos[0] = (basex + trackheight)/2.0f;
554 tm.w_pos[2] = trackradius + treaddepth;
555 obj->setMass( trackm );
556 obj->setMatrix( tm );
558 obj =
new PhyCylinder( trackradius, trackheight, w );
559 obj->setMass( wheelm );
560 tm.w_pos[1] = axledistance/2.0;
561 obj->setMatrix( tm );
563 obj =
new PhyCylinder( trackradius, trackheight, w );
564 obj->setMass( wheelm );
565 tm.w_pos[1] = -axledistance/2.0;
566 obj->setMatrix( tm );
569 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
571 tm.w_pos[0] = -(basex + trackheight)/2.0f;
572 tm.w_pos[2] = trackradius + treaddepth;
573 obj->setMass( trackm );
574 obj->setMatrix( tm );
576 obj =
new PhyCylinder( trackradius, trackheight, w );
577 obj->setMass( wheelm );
578 tm.w_pos[1] = axledistance/2.0;
579 obj->setMatrix( tm );
581 obj =
new PhyCylinder( trackradius, trackheight, w );
582 obj->setMass( wheelm );
583 tm.w_pos[1] = -axledistance/2.0;
584 obj->setMatrix( tm );
588 obj =
new PhyBox( basex+2.0f*trackheight, axledistance, basez+trackradius*2.0f, w );
589 obj->setMass( basem+bodym );
591 tm.w_pos[2] = (basez+trackradius*2.0f)/2.0f + treaddepth;
592 obj->setMatrix( tm );
598 base->setMaterial(
"marXbotLowerBody");
614 double xoffs[6] = { 1, -1, 1, -1, 1, -1 };
615 double yoffs[6] = { 0, 0, 1, 1, -1, -1 };
618 for(
int i=0; i<6; i++ ) {
622 xoffs[i] * (basex + trackheight)/2.0f + (yoffs[i]==0 ? xoffs[i]*(trackheight/2.0+wheelh/2.0f+0.006f) : 0.0f),
623 yoffs[i] * (axledistance/2.0f),
627 wtm.w_pos[2] = wheelr;
628 awheel =
new PhyCylinder( wheelr, wheelh, w,
"motorWheel" );
631 wtm.w_pos[2] = treaddepth-0.003f;
632 awheel =
new PhySphere( treaddepth, w,
"passiveWheel" );
634 wheelstm.append( wtm );
637 awheel->setMaterial(
"marXbotLowerBody" );
640 wheels.append( awheel );
647 wheels[i]->matrix().w_pos,
650 joint->
dofs()[0]->disableLimits();
654 wheels[i]->
matrix().w_pos,
659 wheelJoints.append( joint );
663 #ifdef MARXBOT_DETAILED
665 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
666 obj->setMass( attachringm );
668 tm.w_pos[0] = 0.005f;
669 obj->setMatrix( tm );
671 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
672 obj->setMass( attachringm );
674 tm.w_pos[0] = -0.005f;
675 obj->setMatrix( tm );
678 obj->setMass( ledsm );
679 obj->setTexture(
"marXbot_12leds" );
680 obj->setUseColorTextureOfOwner(
false );
681 tm.w_pos[0] = attachringh/2.0f + ledsh/2.0f + 0.0015f;
682 obj->setMatrix( tm );
686 obj =
new PhyCylinder( bodyr, attachringh+ledsh, w );
687 obj->setMass( attachringm );
689 tm.w_pos[0] = attachringh/2.0f-0.010f;
690 obj->setMatrix( tm );
695 attachring->setMaterial(
"marXbotUpperBody");
696 attachring->
setOwner(
this,
false );
699 attachringtm.w_pos[2] = 0.015f + basez + bodyh + attachringh/2.0f + 0.0015f;
700 attachring->
setMatrix( attachringtm * basetm );
702 forcesensor =
new PhyFixed( base, attachring, w );
703 forcesensor->
setOwner(
this,
false );
706 QVector<PhyDOF*> motors;
707 motors << wheelJoints[0]->dofs()[0] << wheelJoints[1]->dofs()[0];
709 wheelsCtrl->
setOwner(
this,
false );
711 #warning QUI DECIDERE PER LE VELOCITÀ MASSIME E MINIME DELLE RUOTE
720 QVector<SingleIR> sensors;
723 #warning QUI DECIDERE PER I RANGE/APERTURE E LE POSIZIONI (SPECIE PER I GROUND)
726 for (
unsigned int i = 0; i < 24; i++) {
727 const double curAngle = double(i) * (360.0 / 24.0) + ((360.0 / 24.0) / 2.0);
728 const double radius = bodyr;
731 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
732 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
733 mtr.w_pos.z = 0.015f + basez + bodyh/2.0f;
735 sensors.append(
SingleIR(base, mtr, 0.02, 0.1, 10.0, 5));
742 const double distFromBorder = 0.003;
745 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
746 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
747 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
748 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
749 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
750 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
751 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
752 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
759 for (
unsigned int i = 0; i < 8; i++) {
760 const double curAngle = double(i) * (360.0 / 8.0);
761 const double radius = bodyr - 0.003;
764 mtr.w_pos.x = radius * cos(deg2rad(curAngle));
765 mtr.w_pos.y = radius * sin(deg2rad(curAngle));
766 mtr.w_pos.z = 0.015f + basez;
768 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
775 w->pushObject(
this );
779 foreach(
PhyJoint* susp, wheelJoints ) {
790 delete groundBottomIR;
791 delete groundAroundIR;
801 if (kinematicSimulation) {
804 wheeledRobotsComputeKinematicMovement(mtr, leftWheelVelocity, rightWheelVelocity, wheelr, wheelstm[0].w_pos.x - wheelstm[1].w_pos.x,
world()->timeStep());
845 if (kinematicSimulation == k) {
849 kinematicSimulation = k;
850 if (kinematicSimulation) {
852 for (
int i = 0; i < wheelJoints.size(); i++) {
853 wheelJoints[i]->enable(
false);
855 forcesensor->
enable(
false);
859 for (
int i = 0; i < wheels.size(); i++) {
860 wheels[i]->setKinematic(
true,
true);
866 for (
int i = 0; i < wheels.size(); i++) {
867 wheels[i]->setKinematic(
false);
872 for (
int i = 0; i < wheelJoints.size(); i++) {
873 wheelJoints[i]->enable(
true);
874 wheelJoints[i]->updateJointInfo();
876 forcesensor->
enable(
true);
883 leftWheelVelocity = velocity;
888 rightWheelVelocity = velocity;
894 for(
int i=0; i<wheels.size(); i++ ) {
895 wheels[i]->setMatrix( wheelstm[i] * tm );
897 foreach(
PhyJoint* ajoint, wheelJoints ) {
900 attachring->
setMatrix( attachringtm * tm );