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.8f;
57 const real PhyMarXbot::attachdevy = turreth * 0.4f;
58 const real PhyMarXbot::attachdevz = turreth * 0.2f;
59 const real PhyMarXbot::attachdevm = 0.03f;
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");
180 forcesensor =
new PhyFixed( basev, turretv, w );
181 forcesensor->
setOwner(
this,
false );
185 attachdevjoint = NULL;
189 attachdevCtrl->
setOwner(
this,
false );
192 QVector<PhyDOF*> motors;
193 motors << wheelJoints[0]->dofs()[0] << wheelJoints[1]->dofs()[0];
195 wheelsCtrl->
setOwner(
this,
false );
196 #if defined(__GNUC__) && defined(DEVELOPER_WARNINGS)
197 #warning QUI DECIDERE PER LE VELOCITÀ MASSIME E MINIME DELLE RUOTE
206 QVector<SingleIR> sensors;
208 #if defined(__GNUC__) && defined(DEVELOPER_WARNINGS)
209 #warning QUI DECIDERE PER I RANGE/APERTURE E LE POSIZIONI (SPECIE PER I GROUND)
212 for (
unsigned int i = 0; i < 24; i++) {
213 const double curAngle = double(i) * (360.0 / 24.0) + ((360.0 / 24.0) / 2.0);
214 const double radius = bodyr;
217 mtr.w_pos.x = radius * cos(
toRad(curAngle));
218 mtr.w_pos.y = radius * sin(
toRad(curAngle));
219 mtr.w_pos.z = 0.005f + basez + bodyh + turreth / 2.0f + 0.0015f;
221 sensors.append(
SingleIR(basev, mtr, 0.0, 0.1, 10.0, 5));
228 const double distFromBorder = 0.003;
231 mtr.w_pos =
wVector(basex / 2.0f + trackheight - distFromBorder, axledistance / 2.0f - distFromBorder, treaddepth);
232 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
233 mtr.w_pos =
wVector(basex / 2.0f + trackheight - distFromBorder, -axledistance / 2.0f + distFromBorder, treaddepth);
234 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
235 mtr.w_pos =
wVector(-basex / 2.0f - trackheight + distFromBorder, axledistance / 2.0f - distFromBorder, treaddepth);
236 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
237 mtr.w_pos =
wVector(-basex / 2.0f - trackheight + distFromBorder, -axledistance / 2.0f + distFromBorder, treaddepth);
238 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
245 for (
unsigned int i = 0; i < 8; i++) {
246 const double curAngle = double(i) * (360.0 / 8.0);
247 const double radius = bodyr - 0.003;
250 mtr.w_pos.x = radius * cos(
toRad(curAngle));
251 mtr.w_pos.y = radius * sin(
toRad(curAngle));
252 mtr.w_pos.z = 0.005f + basez + bodyh + turreth / 2.0f + 0.0015f;
254 sensors.append(
SingleIR(basev, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
261 w->pushObject(
this );
268 attachdevCtrl->attachmentDeviceAboutToBeDestroyed();
271 delete attachdevCtrl;
273 delete groundBottomIR;
274 delete groundAroundIR;
275 foreach(
PhyJoint* susp, wheelJoints ) {
282 delete attachdevjoint;
298 if (kinematicSimulation) {
301 wheeledRobotsComputeKinematicMovement(mtr, leftWheelVelocity, rightWheelVelocity, wheelr, wheelstm[0].w_pos.x - wheelstm[1].w_pos.x,
world()->timeStep());
353 displacement.w_pos =
wVector(0.0, 0.0, basez + trackradius * 2.0f + treaddepth + turreth - 0.010f + 0.0001f);
363 return (frontMarker != NULL);
374 attachdev =
new PhyBox(attachdevx, attachdevy, attachdevz,
world());
375 attachdev->
setMass(attachdevm);
376 attachdevtm = turretv->
matrix();
377 attachdevtm.w_pos.y -= attachdevr;
383 attachdevjoint->
dofs()[0]->disableLimits();
384 attachdevjoint->
dofs()[0]->setDesiredPosition(0.0);
385 attachdevjoint->
dofs()[0]->setStiffness(0.1f);
386 attachdevjoint->
setOwner(
this,
false);
389 attachdevCtrl->attachmentDeviceAboutToBeDestroyed();
391 delete attachdevjoint;
392 attachdevjoint = NULL;
409 if (kinematicSimulation == k) {
413 kinematicSimulation = k;
414 if (kinematicSimulation) {
416 for (
int i = 0; i < wheelJoints.size(); i++) {
417 wheelJoints[i]->enable(
false);
419 forcesensor->
enable(
false);
420 if (attachdevjoint != NULL) {
421 attachdevjoint->
enable(
false);
426 for (
int i = 0; i < wheels.size(); i++) {
427 wheels[i]->setKinematic(
true,
true);
430 if (attachdev != NULL) {
436 for (
int i = 0; i < wheels.size(); i++) {
437 wheels[i]->setKinematic(
false);
440 if (attachdev != NULL) {
445 for (
int i = 0; i < wheelJoints.size(); i++) {
446 wheelJoints[i]->enable(
true);
447 wheelJoints[i]->updateJointInfo();
449 forcesensor->
enable(
true);
451 if (attachdevjoint != NULL) {
452 attachdevjoint->
enable(
true);
458 #if defined(__GNUC__) && defined(DEVELOPER_WARNINGS)
459 #warning PROBLEMA RELATIVO AI LED DEL MARXBOT: NON C È L'ATTACHRING, SOLO LA TORRETTA CHE PERÒ È FISSA. NEL ROBOT REALE I LED SONO SULL' ATTACHRING, QUINDI RUOTANO (CONTROLLARE!!!), QUI SONO SULLA TORRETTA QUINDI SONO FISSI
463 if (c.size() != 12) {
470 QList<PhyCylinder::SegmentColor> s;
471 const real startAngle = (PI_GRECO / 2.0f) - (PI_GRECO / 12.0f);
472 for (
int i = 0; i < 12; i++) {
473 const real rangeMin = (
real(i) * PI_GRECO / 6.0) + startAngle;
474 const real rangeMax = (
real(i + 1) * PI_GRECO / 6.0) + startAngle;
484 if (ledColorsv.isEmpty()) {
486 for (
int i = 0; i < 12; i++) {
497 if (ledColorsv.isEmpty()) {
498 uniformColor[0].color =
color();
507 leftWheelVelocity = velocity;
512 rightWheelVelocity = velocity;
518 for(
int i=0; i<wheels.size(); i++ ) {
519 wheels[i]->setMatrix( wheelstm[i] * tm );
521 foreach(
PhyJoint* ajoint, wheelJoints ) {
526 if ((attachdev != NULL) && (attachdevjoint != NULL)) {
527 attachdev->
setMatrix( attachdevtm * tm );
533 const real PhyMarXbot::basex = 0.034f;
534 const real PhyMarXbot::basey = 0.143f;
535 const real PhyMarXbot::basez = 0.048f;
536 const real PhyMarXbot::basem = 0.4f;
537 const real PhyMarXbot::bodyr = 0.085f;
538 const real PhyMarXbot::bodyh = 0.0055f;
539 const real PhyMarXbot::bodym = 0.02f;
540 const real PhyMarXbot::axledistance = 0.104f;
541 const real PhyMarXbot::trackradius = 0.022f;
542 const real PhyMarXbot::trackheight = 0.0295f;
543 const real PhyMarXbot::trackm = 0.05f;
544 const real PhyMarXbot::treaddepth = 0.004f;
545 const real PhyMarXbot::wheelr = 0.027f;
546 const real PhyMarXbot::wheelh = 0.0215f;
547 const real PhyMarXbot::wheelm = 0.02f;
548 const real PhyMarXbot::attachringh = 0.0285f;
549 const real PhyMarXbot::attachringm = 0.08f;
550 const real PhyMarXbot::ledsh = 0.010f;
551 const real PhyMarXbot::ledsradius = 0.080f;
552 const real PhyMarXbot::ledsm = 0.03f;
555 kinematicSimulation =
false;
582 QVector<PhyObject*> objs;
585 #ifdef MARXBOT_DETAILED
588 obj =
new PhyBox( basex, basey, basez, w );
589 tm.w_pos[2] = basez/2.0f + 0.015f;
595 obj->setMass( bodym );
597 tm.w_pos[2] = 0.015f + basez + bodyh/2.0f;
598 obj->setMatrix( tm );
601 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
603 tm.w_pos[0] = (basex + trackheight)/2.0f;
604 tm.w_pos[2] = trackradius + treaddepth;
605 obj->setMass( trackm );
606 obj->setMatrix( tm );
608 obj =
new PhyCylinder( trackradius, trackheight, w );
609 obj->setMass( wheelm );
610 tm.w_pos[1] = axledistance/2.0;
611 obj->setMatrix( tm );
613 obj =
new PhyCylinder( trackradius, trackheight, w );
614 obj->setMass( wheelm );
615 tm.w_pos[1] = -axledistance/2.0;
616 obj->setMatrix( tm );
619 obj =
new PhyBox( trackheight, axledistance, trackradius*2.0f, w );
621 tm.w_pos[0] = -(basex + trackheight)/2.0f;
622 tm.w_pos[2] = trackradius + treaddepth;
623 obj->setMass( trackm );
624 obj->setMatrix( tm );
626 obj =
new PhyCylinder( trackradius, trackheight, w );
627 obj->setMass( wheelm );
628 tm.w_pos[1] = axledistance/2.0;
629 obj->setMatrix( tm );
631 obj =
new PhyCylinder( trackradius, trackheight, w );
632 obj->setMass( wheelm );
633 tm.w_pos[1] = -axledistance/2.0;
634 obj->setMatrix( tm );
638 obj =
new PhyBox( basex+2.0f*trackheight, axledistance, basez+trackradius*2.0f, w );
639 obj->setMass( basem+bodym );
641 tm.w_pos[2] = (basez+trackradius*2.0f)/2.0f + treaddepth;
642 obj->setMatrix( tm );
648 base->setMaterial(
"marXbotLowerBody");
664 double xoffs[6] = { 1, -1, 1, -1, 1, -1 };
665 double yoffs[6] = { 0, 0, 1, 1, -1, -1 };
668 for(
int i=0; i<6; i++ ) {
672 xoffs[i] * (basex + trackheight)/2.0f + (yoffs[i]==0 ? xoffs[i]*(trackheight/2.0+wheelh/2.0f+0.006f) : 0.0f),
673 yoffs[i] * (axledistance/2.0f),
677 wtm.w_pos[2] = wheelr;
678 awheel =
new PhyCylinder( wheelr, wheelh, w,
"motorWheel" );
681 wtm.w_pos[2] = treaddepth-0.003f;
682 awheel =
new PhySphere( treaddepth, w,
"passiveWheel" );
684 wheelstm.append( wtm );
687 awheel->setMaterial(
"marXbotLowerBody" );
690 wheels.append( awheel );
697 wheels[i]->matrix().w_pos,
700 joint->
dofs()[0]->disableLimits();
704 wheels[i]->
matrix().w_pos,
709 wheelJoints.append( joint );
713 #ifdef MARXBOT_DETAILED
715 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
716 obj->setMass( attachringm );
718 tm.w_pos[0] = 0.005f;
719 obj->setMatrix( tm );
721 obj =
new PhyCone( bodyr, attachringh+0.010f, w );
722 obj->setMass( attachringm );
724 tm.w_pos[0] = -0.005f;
725 obj->setMatrix( tm );
728 obj->setMass( ledsm );
729 obj->setTexture(
"marXbot_12leds" );
730 obj->setUseColorTextureOfOwner(
false );
731 tm.w_pos[0] = attachringh/2.0f + ledsh/2.0f + 0.0015f;
732 obj->setMatrix( tm );
736 obj =
new PhyCylinder( bodyr, attachringh+ledsh, w );
737 obj->setMass( attachringm );
739 tm.w_pos[0] = attachringh/2.0f-0.010f;
740 obj->setMatrix( tm );
745 attachring->setMaterial(
"marXbotUpperBody");
746 attachring->
setOwner(
this,
false );
749 attachringtm.w_pos[2] = 0.015f + basez + bodyh + attachringh/2.0f + 0.0015f;
750 attachring->
setMatrix( attachringtm * basetm );
752 forcesensor =
new PhyFixed( base, attachring, w );
753 forcesensor->
setOwner(
this,
false );
756 QVector<PhyDOF*> motors;
757 motors << wheelJoints[0]->dofs()[0] << wheelJoints[1]->dofs()[0];
759 wheelsCtrl->
setOwner(
this,
false );
760 #if defined(__GNUC__) && defined(DEVELOPER_WARNINGS)
761 #warning QUI DECIDERE PER LE VELOCITÀ MASSIME E MINIME DELLE RUOTE
770 QVector<SingleIR> sensors;
772 #if defined(__GNUC__) && defined(DEVELOPER_WARNINGS)
773 #warning QUI DECIDERE PER I RANGE/APERTURE E LE POSIZIONI (SPECIE PER I GROUND)
776 for (
unsigned int i = 0; i < 24; i++) {
777 const double curAngle = double(i) * (360.0 / 24.0) + ((360.0 / 24.0) / 2.0);
778 const double radius = bodyr;
781 mtr.w_pos.x = radius * cos(
toRad(curAngle));
782 mtr.w_pos.y = radius * sin(
toRad(curAngle));
783 mtr.w_pos.z = 0.015f + basez + bodyh/2.0f;
785 sensors.append(
SingleIR(base, mtr, 0.02, 0.1, 10.0, 5));
792 const double distFromBorder = 0.003;
795 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
796 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
797 mtr.w_pos =
wVector(basex / 2.0f - distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
798 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
799 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, basey / 2.0f - distFromBorder, 0.015f);
800 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
801 mtr.w_pos =
wVector(-basex / 2.0f + distFromBorder, -basey / 2.0f + distFromBorder, 0.015f);
802 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
809 for (
unsigned int i = 0; i < 8; i++) {
810 const double curAngle = double(i) * (360.0 / 8.0);
811 const double radius = bodyr - 0.003;
814 mtr.w_pos.x = radius * cos(
toRad(curAngle));
815 mtr.w_pos.y = radius * sin(
toRad(curAngle));
816 mtr.w_pos.z = 0.015f + basez;
818 sensors.append(
SingleIR(base, mtr, 0.0, mtr.w_pos.z + 0.005, 0.0, 1));
825 w->pushObject(
this );
829 foreach(
PhyJoint* susp, wheelJoints ) {
840 delete groundBottomIR;
841 delete groundAroundIR;
851 if (kinematicSimulation) {
854 wheeledRobotsComputeKinematicMovement(mtr, leftWheelVelocity, rightWheelVelocity, wheelr, wheelstm[0].w_pos.x - wheelstm[1].w_pos.x,
world()->timeStep());
895 if (kinematicSimulation == k) {
899 kinematicSimulation = k;
900 if (kinematicSimulation) {
902 for (
int i = 0; i < wheelJoints.size(); i++) {
903 wheelJoints[i]->enable(
false);
905 forcesensor->
enable(
false);
909 for (
int i = 0; i < wheels.size(); i++) {
910 wheels[i]->setKinematic(
true,
true);
916 for (
int i = 0; i < wheels.size(); i++) {
917 wheels[i]->setKinematic(
false);
922 for (
int i = 0; i < wheelJoints.size(); i++) {
923 wheelJoints[i]->enable(
true);
924 wheelJoints[i]->updateJointInfo();
926 forcesensor->
enable(
true);
933 leftWheelVelocity = velocity;
938 rightWheelVelocity = velocity;
944 for(
int i=0; i<wheels.size(); i++ ) {
945 wheels[i]->setMatrix( wheelstm[i] * tm );
947 foreach(
PhyJoint* ajoint, wheelJoints ) {
950 attachring->
setMatrix( attachringtm * tm );