ROBOTC.net forumshttp://www.robotc.net/forums/ Roomexplorer and mapping NXT-robothttp://www.robotc.net/forums/viewtopic.php?f=15&t=7468 Page 1 of 1

Author:  Sigtrygg [ Mon Dec 23, 2013 11:42 am ]
Post subject:  Roomexplorer and mapping NXT-robot

Hi community!
I would like to introduce my new project “Room explorer with mapping functions”.
The robot based upon a standard REM-Bot but in addition equipped with a hitechnic gyro, hitechnic compass sensor and an omni-wheel (look at the Pictures I will send when the server of RobotC will work again).
First the robot moves about 360° to calibrate the compass using the gyro (thank you to Xander for code!).
Then the robot moves its sonar-head to the right, to the left and in front position to get the distances according to its position. After doing this it turns around to the wall with the minimum distance and drives in front of it until sonar sensor detected a minimum sensor distance, e.g. 20cm. Then the robot turns parallel to the wall, moves his sonar-head to the right detecting the distance to the wall and drives counter clockwise parallel to the wall balancing distance. A mapping-task records the compass and odometry data every second and calculate the polar coordinates to cartesian coordinates (x,y). The coordinates are written as “map.txt”-file. So you can use Excel or an other programm to draw the path which the robot had moved. In addition to that you can follow the path at the NXT-LCD-screen. I had to choose a scale for it, so you have to suit the scale to your room size.
If the robots touch sensor detected an obstacle the robot moves back and turn left for 90 degrees and continuous his explorer-duty allways running counter clockwise with wall to the right.
How to expect the end of path doesn’t suit exactly to the beginning because of inaccuracies of compass and odometry measures.
Have fun to test my programm and let me know if you have some hints for me.
Do anybody have experience with a hitechnic accelerator-sensor to measure/calculate the distance by integrating? Is this method an alternative and more accurate as odometry data?

Merry chrsitmas!

Sigtrygg

 Code:#pragma config(Sensor, S1,       touchSensor,       sensorTouch)#pragma config(Sensor, S2,       HTCOMPASS,          sensorI2CCustom)#pragma config(Sensor, S3,       HTGYRO,          sensorAnalogInactive)#pragma config(Sensor, S4,       sonarSensor,       sensorSONAR)#pragma config(Motor,    motorA,               sonarMotor,       tmotorNXT, PIDControl, encoder)#pragma config(Motor,    motorB,               rightMotor,       tmotorNXT, PIDControl, encoder)#pragma config(Motor,    motorC,               leftMotor,       tmotorNXT, PIDControl, encoder)//*!!Code automatically generated by 'ROBOTC' configuration wizard                      !!*////Roomexplorer and mapping robot by Sigtrygg, December 2013/* Credits :* Special thanks to to Xander Soldaat for gyro and compass-drivers and gyro/compass example codes!** License: You may use this code as you wish.*/#include "REM-Bot_Roomexplorer_functions_1.3.h" //all necessary functions are written in the header-file//*************************************************************************************************task mapping(){   eraseDisplay();   time10[T2]=0;   maxtime=(long)(nFileSize)*interval/(60*17);//in minutes   //Prepare file-handling   hFileHandle = 0;   Delete(sFileName, nIoResult);   OpenWrite(hFileHandle, nIoResult, sFileName, nFileSize);   while (mode_exit !=1)   {      odometryValueOld=nMotorEncoder[rightMotor];      //eraseDisplay();      valTime10 = time10[T2];      recordtime=(recordtime+valTime10/100)/60;      //nxtDisplayStringAt(0, 60,"Recordtime: %d",recordtime);      //nxtDisplayStringAt(0, 50,"Max.time: %d",maxtime);      //nxtDisplayStringAt(0, 40,"Sonar: %d",SensorValue(sonarSensor));      //nxtDisplayStringAt(0, 30,"Heading: %d",compassValue);      wait10Msec(interval*100);//write data according interval!      compassValue=HTMCreadHeading(HTCOMPASS);//get current heading      if (recordtime==maxtime || nNxtButtonPressed==3)//if recordtime is reached or the orange Key is pressed stop!      {         wait1Msec(500);         Close(hFileHandle, nIoResult);         mode_exit=1;//when reaching the max. recordtime, exit with closing file      }      if (touchflag==0)//only write coordinates if touch sensor is 0 and after robot has repositioned      {         odometryValueCurrent=nMotorEncoder[rightMotor];         odometryValueRadius=(odometryValueCurrent-odometryValueOld)*WHEELCIRCUMFERENCE/360;//radius in cm         //calculate cartesian coordinates according to start point         cartesX+=-(cosDegrees(compassValue)*odometryValueRadius);//calculating with float!!         cartesY+=(sinDegrees(compassValue)*odometryValueRadius);         //convert int values to string values for file-writing         StringFormat(scartesX, "%d", round(cartesX));//show only rounded integer         StringFormat(scartesY, "%d", round (cartesY));         //convert int values to string values for file-writing (Polar)         StringFormat(sodometryValueRadius, "%d", round(odometryValueRadius));         StringFormat(scompassValue, "%d", round(compassValue));         //write cartesian coordinates to file         WriteText(hFileHandle, nIoResult, "\r\n");         WriteText(hFileHandle, nIoResult, sodometryValueRadius);         WriteText(hFileHandle, nIoResult, ",");         WriteText(hFileHandle, nIoResult, scompassValue);         WriteText(hFileHandle, nIoResult, ",");         WriteText(hFileHandle, nIoResult, scartesX);         WriteText(hFileHandle, nIoResult, ",");         WriteText(hFileHandle, nIoResult, scartesY);         //Draw Map-Pixels on screen         Pixel_x=round((cartesX+PixelOffset_x)*DRAW_SCALE);         Pixel_y=round((cartesY+PixelOffset_y)*DRAW_SCALE);         nxtSetPixel(Pixel_x, Pixel_y);      }   }   sonarLeftPosition();   wait1Msec(500);   Close(hFileHandle, nIoResult);   while(nNxtButtonPressed!=0)//wait until escape button is pressed to take a look at the map   {      motor[rightMotor]=0;      motor[leftMotor]=0;   }}//*****************************************************************************************************************task main(){   //Calibrate the gyro, make sure you hold the sensor still   wait1Msec(2000);   HTGYROstartCal(HTGYRO); //returns offset of Gyro (e.g. 610), it depends on temperature and other environmental influences.   wait1Msec(1000);   //Calibrate the compass   compass_calibration();   //----------------------------- behavior ---------------------------------------------------------   //check in which direction the nearest wall is and drive to it. Then turn 90° left   for (int i=0; i<3; i++)   {      sonarangle[0]=0;      sonarturnvelocity[0]=0;      sonarangle[1]=92;      sonarturnvelocity[1]=15;      sonarangle[2]=-180;      sonarturnvelocity[2]=-15;      nMotorEncoder[sonarMotor] = 0;      nMotorEncoderTarget[sonarMotor] = sonarangle[i];      motor[sonarMotor] = sonarturnvelocity[i];      while (nMotorRunState[sonarMotor] != runStateIdle)      {         // do not continue      }      motor[sonarMotor] = 0;      //get the average of 10 measures      for (int t=0;t<10;t++)      {         wait1Msec(50);         distancevalue[i]=SensorValue(sonarSensor);         distancevaluesum+=distancevalue[i];      }      distancevalue[i]=distancevaluesum/10;      nxtDisplayCenteredBigTextLine(4, "%2d",distancevalue[i]);      wait1Msec(1500);      distancevaluesum=0;      eraseDisplay();      // measure end   }   //get minimum distance and its angle   minimumdistance=256;   for (int i=0; i<3; i++)   {      if (distancevalue[i]

Author:  Sigtrygg [ Sat Dec 28, 2013 5:16 am ]
Post subject:  Re: Roomexplorer and mapping NXT-robot

Here you can take a look at the construction of robot...
The upper sensor is the compass sensor.
Let me know, if anything doesn't work.

Bye,

Sigtrygg

 Attachments: File comment: Picture 2 CIMG3125.JPG [ 234.23 KiB | Viewed 28224 times ] File comment: Picture 1 CIMG3122.JPG [ 232.57 KiB | Viewed 28224 times ]

 Author: mightor [ Sat Dec 28, 2013 5:49 am ] Post subject: Re: Roomexplorer and mapping NXT-robot Hey there!This is a great project. Do you think you could make some screenshots of your Excel sheet/NXT screen so we can see what it looks like in action? I'd love to see a video of it.= Xander

Author:  Sigtrygg [ Sat Dec 28, 2013 12:54 pm ]
Post subject:  Re: Roomexplorer and mapping NXT-robot

Hello Xander!

Thank you for response.
At the first picture you can see the screenshot of datasheet made with Open Office. The second Picture is the LCD-screen of NXT.
The inaccuracy between start and end is about 22 cm. Maybe there is a method to reduce this?!

Bye,

Sigtrygg

 Attachments: File comment: Screenshot of data-sheet Screenshot open office.png [ 261.56 KiB | Viewed 28207 times ] File comment: LCD-Screenshot LCD-Screenshot.jpg [ 276.5 KiB | Viewed 28207 times ]

 Author: Ford Prefect [ Sat Dec 28, 2013 2:52 pm ] Post subject: Re: Roomexplorer and mapping NXT-robot could you pls make your photos smaller, e.g. 320x240 ? For the moment, I ain't see nothing yet ...

 Author: mightor [ Sat Dec 28, 2013 2:57 pm ] Post subject: Re: Roomexplorer and mapping NXT-robot Buy a bigger monitor The size you suggest is far too small to see anything in great detail. I am reading this in a non-full screen window on 1080p sized screen and it looks fine.= Xander

 Author: Ford Prefect [ Sat Dec 28, 2013 3:12 pm ] Post subject: Re: Roomexplorer and mapping NXT-robot haha, I already have 1920X1080but maybe 640x480 will do as well.

 Author: Sigtrygg [ Wed Jul 09, 2014 12:33 pm ] Post subject: Re: Roomexplorer and mapping NXT-robot Hello community!I have made a little video of the roomexplorer NXT robot, now. You can watch it at:https://www.youtube.com/watch?v=-ThYSIfo1aUBye,Sigtrygg

 Author: mightor [ Thu Jul 10, 2014 1:34 am ] Post subject: Re: Roomexplorer and mapping NXT-robot That is really awesome, nice job!= Xander

 Author: Sigtrygg [ Thu Jul 10, 2014 4:52 am ] Post subject: Re: Roomexplorer and mapping NXT-robot Thank you!I am glad, that you like it. There aren't many People who are able to evaluate such project in my surroundings

 Author: mightor [ Sat Jul 19, 2014 10:04 am ] Post subject: Re: Roomexplorer and mapping NXT-robot Your robot has been pimped out on the ROBOTC blog and MINDSTORMS group on Facebook = Xander

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/