| Pages: [1] :: one page |
| Author |
Thread Statistics | Show CCP posts - 0 post(s) |

quickshot89
Caldari MEK Enterprises
|
Posted - 2009.05.10 02:01:00 -
[1]
first of, im using the lego nxt robot and robotC to program this
#pragma config(Sensor, S2, soundSensor, sensorSoundDB) #pragma config(Sensor, S3, lightSensor, sensorLightActive) #pragma config(Sensor, S4, sonarSensor, sensorSONAR) //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
int objectA = 0; //this is a count value used to count the amount of objects seen //int VarC = SensorValue(lightSensor); code disabled for program, test use only //int VarB = SensorValue(sonarSensor); code disabled for program, test use only //int Vara = SensorValue(soundSensor); code disabled for program, test use only int lightA[60]; //array for light values int soundA[60]; //array for sound values int sonarA[60]; //array for sonar values(distance) int count = 0; //this is used for the arrays counting int testC = 60; int len1 = 60;
void bubble1 (int array, int length)
{ int i, j, temp; int test; for (i = len1 -1; i > 0; i--) { test=0; for(j = 0; j > 1; j++) { if(soundA[j] > soundA[j+1]) { temp = soundA[j]; soundA[j] = soundA[j+1]; soundA[j+1] = temp; test=1; } } if(test==0) break; } }
void countvalue() //this part of the program is used to count values and store them into the array every second { lightA[count] = SensorValue(lightSensor); soundA[count] = SensorValue(soundSensor); sonarA[count] = SensorValue(sonarSensor); wait1Msec(1000); count++; //adds one to the count value so the previous value is not over-written, so value 2 goes into array 2, }
void noroam()
{ motor[motorC] = 0; motor[motorB] = 0; }
void roam() { while(time1[T1] < 60000) //this part of the code runs for 60 seconds, then stops but does not end the program
{ countvalue(); nMotorPIDSpeedCtrl[motorC] = mtrSpeedReg; //syncs the motors nMotorPIDSpeedCtrl[motorB] = mtrSpeedReg;
if(SensorValue(sonarSensor) > 26)//robot runs forward unless distance is less than 26 cm
{ motor[motorC]=30; //robot runs forward with a speed of 30 motor[motorB]=30; } //if an object is detected within 26cm, the following code runs else { motor[motorC] = -30; //robot reverses motor[motorB] = -30; wait1Msec(1000); //waits 1 second motor[motorC] = -20; //turns left motor[motorB] = 20; wait1Msec(1000); //waits 1 second objectA++; } } }
task main() { nNxtButtonTask = -2; //disables the exit button ClearTimer(T1); //clears the timer eraseDisplay(); //clears the display //runs the countvalue() subroutine roam(); noroam(); eraseDisplay(); nxtDisplayTextLine(2, "objects seen: %d",objectA); bubble1(lightA, 60); wait1Msec(5000); nxtDisplayTextLine(2, "objects seen: %d",testC); wait1Msec(5000); }
basically the bubble sort isnt working when i compile the program, anyone got a fix to this? it will probally be a quick fix if anything
|

Cpt Placeholder
|
Posted - 2009.05.10 02:29:00 -
[2]
1. I don't know any of the robot stuff 2. Bubble sort is awful 3. The second for loop should be for(j = 0; j < i; j++)
|

tank overide
Caldari b.b.k
|
Posted - 2009.05.10 03:15:00 -
[3]
Originally by: Cpt Placeholder
2. Bubble sort is awful
that ________________________________________________________
|

Jim McGregor
|
Posted - 2009.05.10 06:53:00 -
[4]
Originally by: tank overide
Originally by: Cpt Placeholder
2. Bubble sort is awful
that
When you only have 60 values and are building a hobby program, there is hardly any point in using a more complex algorithm.
---
Originally by: Roguehalo Can you nano Titans?
|

Wired
Caldari Provisions
|
Posted - 2009.05.10 07:37:00 -
[5]
Don't you have a debugger?
Getting good at using a debugger is a very useful skill to have. You had already identified there was a problem with the bubble sort so drop in a break point and away you go. =============================================
My sig got edited, and all i got was a lousy e-mail |

Whitehound
|
Posted - 2009.05.10 16:51:00 -
[6]
Edited by: Whitehound on 10/05/2009 16:52:04
Originally by: Cpt Placeholder 3. The second for loop should be for(j = 0; j < i; j++)
I support this, I think. -- If there is anything in your life you fear of losing, then keep your mouth shut once in a while. |

KingsGambit
Caldari Knights
|
Posted - 2009.05.11 10:57:00 -
[7]
Edited by: KingsGambit on 11/05/2009 11:00:41
Originally by: Cpt Placeholder The second for loop should be for(j = 0; j < i; j++)
This. At the moment you have j > 1 as the thing to test for. As it starts at zero and isn't incremented within the loop, it will never be true. While it's < i, it will go thru each int in the array the first time, all but the last the next, all but last two the 3rd time and so on, exactly what you are hoping for. -------------
|

Xelios
Minmatar Broski Enterprises Avarice.
|
Posted - 2009.05.11 12:14:00 -
[8]
In the future if you don't have a debugger (you should they're really useful) just put some println statements into the code to check variables or to see where the problem occurs. Put one at the entry point for every method and inside loops (have it print a . or something so you can count the iterations), then it's easy to see where the program goes wrong.
|

Sleepkevert
Amarr Rionnag Alba Against ALL Authorities
|
Posted - 2009.05.11 13:07:00 -
[9]
debugger and prntln are probably somewhat impossible on a lego microcontroller :P _
Add your own line! |

Feilamya
Minmatar
|
Posted - 2009.05.11 20:02:00 -
[10]
Originally by: Jim McGregor
Originally by: tank overide
Originally by: Cpt Placeholder
2. Bubble sort is awful
that
When you only have 60 values and are building a hobby program, there is hardly any point in using a more complex algorithm.
When you only have 60 values and are building a hobby program, there is hardly any point in rolling your own sort function when there are standard library functions you can use.
(This is also true in 99% of all cases where you have more than 60 values and are not building just a hobby program)
Why waste time on sorting when you can just use what is already there and working, and focus on the fun and interesting stuff instead?
|

Vistilantus
Caldari You're Doing It Wrong
|
Posted - 2009.05.11 21:02:00 -
[11]
i can't help with your problem, but just wanted to put THIS here to see if it would help in the development of your program, it's a lego microcontroller emulator so you can quickly test any changes to your program :D ___________________________________________________ ~Vistilantus |

Anarkia Evangel
Slacker Industries
|
Posted - 2009.05.11 22:02:00 -
[12]
Edited by: Anarkia Evangel on 11/05/2009 22:01:46 What are you trying to get your robot to do?
From what I can see its avoiding objects and recording them, and showing the count on the NXT display.
|
| |
|
| Pages: [1] :: one page |
| First page | Previous page | Next page | Last page |