Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 20:9f4ba1b3d06e, committed 2017-05-31
- Comitter:
- joosthartkamp
- Date:
- Wed May 31 08:43:43 2017 +0000
- Parent:
- 19:25663276160d
- Commit message:
- ongetest;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue May 23 11:36:21 2017 +0000
+++ b/main.cpp Wed May 31 08:43:43 2017 +0000
@@ -28,7 +28,76 @@
int position = 0;
int pos;
+bool robotrun;
+int radarspeedsetleft;
+int radarspeedsetright;
+
+/*
+******* main loop ********************************
+hier maakt de robot de beslissingen wat hij moet doen in bepaalde situaties
+dit staat in het programmaoverzicht beschreven
+
+
+*/
+int main ()
+{
+ while(robotrun == 1);
+ {
+ if(lijnsensor > 0) {
+ switch(lijnsensor) {
+ case 1: {
+ Hbrug(255, 128, 2);
+ break;
+ }
+ case 2: {
+ Hbrug(128, 255, 2);
+ break;
+ }
+ case 3: {
+ Hbrug(255, 255, 2);
+ break;
+ }
+ case 4: {
+ Hbrug(255, 128, 1);
+ break;
+ }
+ case 8: {
+ Hbrug(128, 255, 1);
+ break;
+ }
+ case 12: {
+ Hbrug(255, 255, 1);
+ break;
+ }
+ wait_ms(200);
+ }
+ else {
+ if (lidardirection < 90) {
+ radarspeedsetleft = 255;
+ radarspeedsetright = 255-(lidardirection/90)*255;
+ Hbrug(radarspeedsetleft, radarspeedsetright, 1);
+ }
+ else if (lidardirection > 270) {
+ radarspeedsetleft = 255;
+ radarspeedsetright = ((lidardirection-270)/90)*255;
+ Hbrug(radarspeedsetleft, radarspeedsetright, 1);
+ }
+ else if (lidardirection > 270) {
+ radarspeedsetleft = 255;
+ radarspeedsetright = ((lidardirection-270)/90)*255;
+ Hbrug(radarspeedsetleft, radarspeedsetright, 1);
+ }
+ else if (lidardirection > 270) {
+ radarspeedsetleft = 255;
+ radarspeedsetright = ((lidardirection-270)/90)*255;
+ Hbrug(radarspeedsetleft, radarspeedsetright, 1);
+ }
+ }
+ }
+ }
+
+}
int mapcurrent(float input = 0.00,float inputmin = 0.00, float inputmax = 0.00,int outputmin = 0, int outputmax = 0)
{
return (input - inputmin) * (outputmax - outputmin) / (inputmax - inputmin) + outputmin;
@@ -37,6 +106,31 @@
// twee poar neemn
// twee tettn in n envelop
//neuken tot de vellen er bij hangen
+/*
+******* radar direction ********************************
+deze functie bepaalt de hoek waarin een andere robot is gedetecteerd
+deze functie geeft een waarde terug van 0 tot 360
+
+*/
+int lidardirection()
+{
+ bool objectfound;
+ int startangle;
+ int stopangle;
+ int outputangle;
+ if (afstandzoeker == 1&&objectfound == 0) {
+ objectfound = 1;
+ int startangle = pos;
+
+ }
+ if (afstandzoeker == 0&&objectfound == 1) {
+ objectfound = 0;
+ stopangle = pos;
+ outputangle = startangle + (stopangle-startangle/2)
+ }
+ return outputangle;
+}
+
int stepper()
{
@@ -96,10 +190,10 @@
int lijnsensor ()
{
- bool a = 0;
- bool b = 0;
- bool c = 0;
- bool d = 0;
+ bool a = 0;// sensor linksvoor
+ bool b = 0;// sensor rechtsvoor
+ bool c = 0;// sensor linksachter
+ bool d = 0;// sensor rechtsachter
int output;
if (Sensor1 > 0.01) {
@@ -141,55 +235,55 @@
bool MotorR2 = 0;
switch (stapmode) {
- case 0:
+ case 0:// stilstaan
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
MotorR2 = 0;
break;
- case 1:
+ case 1:// vooruit
+ MotorL1 = 0;
+ MotorL2 = 1;
+ MotorR1 = 0;
+ MotorR2 = 1;
+ break;
+ case 2:// achteruit
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
MotorR2 = 0;
break;
- case 2:
- MotorL1 = 0;
- MotorL2 = 0;
- MotorR1 = 0;
- MotorR2 = 0;
- break;
- case 3:
+ case 3:// naar linksvoor
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
MotorR2 = 0;
break;
- case 4:
+ case 4:// naar rechtsvoor
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
MotorR2 = 0;
break;
- case 5:
+ case 5:// naar linksachter
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
MotorR2 = 0;
break;
- case 6:
+ case 6: // naar rechtsachter
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
MotorR2 = 0;
break;
- case 7:
+ case 7: // links om as
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
MotorR2 = 0;
break;
- case 8:
+ case 8: // rechts om as
MotorL1 = 0;
MotorL2 = 0;
MotorR1 = 0;
@@ -202,8 +296,4 @@
MotorR1pin = MotorR1;
MotorR2pin = MotorR2;
-}
-
-int main (){
-
- }
\ No newline at end of file
+}
\ No newline at end of file