![]() |
hey need some help with writing a code please help me here
i need to write a code that stops when u hit the wall turns and than goes on by changin it's direction. Anyone has any idea of what i can do or a sample of code please send it to me it will be very helpful. my e-mail address is jigarjuhi@yahoo.ca thanks guys for your time and co-operation
|
Re: hey need some help with writing a code please help me here
well, what sort of sensors are you using and in what places? is it just a limit switch on the front? if so, how are you trying to make sure you go the right direction? Or is it just trial and error? Assuming trial and error with limitswtches on the fron i would do something like this:
Code:
char turning=0; //in the global vars section-Kesich |
Re: hey need some help with writing a code please help me here
I'm board so I figured I would clean up the code a little bit.
Code:
unsigned int turning = 0; /* Put at the top of user_routines.c just under the #includes. */ |
Re: hey need some help with writing a code please help me here
okay thanks for that code and since yoiu ask you need detail. what i wan't is basically a code so if i place swith around by robot and when that switch is triggered (when it hits the wall) i want robot to move in opposite direction.
for eg. if i am driving my robot in reverse and it hits the wall as soon as it hits the wall the swithc should trigger and the robot should move forward. by the way thanks guys for all the help you game me it was excellent info. |
Re: hey need some help with writing a code please help me here
opps, thats right, no then in C. My bad. I'm sorry, late night, long day, why am i making excusues? but couldnt you leave the turning=40 and the pwm01=pwm02=200 lines without brackets around them seeing as they are single line statements after a conditional? or are the brackets just to clean it up and make it more easily understandable?
one more thing: pwm02 -= 254 does work. if I'm not mistaken. then that statement expands to pwm02=pwm02-254 whic will alwyas give you a negative value which does not work (or a really large value if pwm02 is unsigned). so souldn't it be redone to be pwm02=254-pwm02? but hey, i may be mistaken, correct me if i am for either part. -Kesich |
Re: hey need some help with writing a code please help me here
Quote:
Quote:
|
Re: hey need some help with writing a code please help me here
I would just be safe and make it pwm02=254-pwm02, who cares if it takes a little longer to type. plus doinging it with and unsgined char and just rolling over throws you off by 1, which could end up giving you 255 as an output which would be an ugly thing.
And regarding the brackets versus braces thing, i'll try to remember later on to use the correct terms (I've just always called braces curly brackets or "little swoopty doptie thingies that i never use"). |
Re: hey need some help with writing a code please help me here
so does anyone has the correct code so i can look at it and understand. thanks guys for valuable information and time.
|
Re: hey need some help with writing a code please help me here
Code:
char turning=0; //in the global vars section |
Re: hey need some help with writing a code please help me here
...painful experience has taught me that if you are going to reverse the motor in software, first, limit the pwm from 1 to 254. Then subtract that value from 255.
so in c... /* ** Max the PWM ...see p 51. in Kernighan and Richie :"the c programming ** language" */ pwm02 = (pwm02 <= 254) ? pwm02 : 254 ; /* Min the PWM*/ pwm02 = (pwm02 >= 1 ) ? pwm02 : 1 ; /* reverse it in software */ pwm02 = 255 - pwm02 ; ...or with if's if ( pwm02 > 254) { pwm02 = 254 ; } else if (pwm02 < 1) { pwm02 = 1 ; } pwm02 = 255 - pwm02 ; Or, we've also reversed the wiring on the motor ;) But, we prefer to reverse it in software. Really though, since Anthony and echos code hardwires the values, you know that you don't have to protect for a rollover and can get away with pwm02 = 254 - pwm02. Thanks, Eric |
| All times are GMT -5. The time now is 22:32. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi