I’m having trouble programming my Ultrasonic sensors to both work In EasyC Ver.2.9.3.0
A Brief explanation of my program.
Motors always drive the robot forward until an Ultrasonic Sensor sees something 10 cm away and reverses. each sensor controls two motors
UltraL controls Motors 3 & 4
UltraR controls Motors 1 & 2
(note: Omni Directional Wheels are used)
I can get one to work but not two in the same program.
GetUltrasonic returns an unsigned int, not int.
It even says that right in the pulldown block.
Thanks for posting your version. I have EasyC V2 Version 2.9.3.5
so you might consider updating from 2.9.3.0 from the website.
You haven’t told us what your robot looks like,
so I’ll assume holo + config with an ultrasound on front and left.
“Doesn’t work” is a completely useless description to ask for help.
We can’t tell from your description what program you show actually does.
As I read the code, if it ‘worked’ I predict that it should drive itself into a corner +10 from wall, and jitter around there.
Note that all the motors are always going full speed, either forward or backward.
Since the motors/friction are unlikely to be matched on opposite sides, your robot will likely spin some what with each jitter as well.
To help you debug, you could use a unique PrintToScreen after each IF and ELSE, to report the ultrasonic value.
Use one of these at each motorset 1 or motorset 3
PrintToScreen(“moving L because UltraL is %u\n”, UltraL );
PrintToScreen(“moving R because UltraL is %u\n”, UltraL );
PrintToScreen(“moving F because UltraR is %u\n”, UltraR );
PrintToScreen(“moving B because UltraR is %u\n”, UltraR );
I’m new to all this so bare with me. What may seem obvious to yourself is not necessarily obvious to me. I think the best way is to start again to avoid any confusion. Could somebody post some working code?
1 Ultrasonic Sensor driving 2 motors.
If the distance is less than 10cm then it will reverse these two motors.
Another Ultrasonic Sensor driving 2 Different motors to the first sensor.
If the distance is less than 10cm then it will reverse these two motors.
Motors and wheels on your robot undescribed are.
Ultrasonics have I only one.
A good skill debugging your own code is to have, essential even.
Does what your robot now with the code posted?
Still not clear your intent is.
Bounce off an invisible 10cm wall you want (requires a sw latch)?
Or hover near the 10cm corner you want?
As you can see from the directional arrow, this is the direction of the travel (Diagonal from the corner). I have tested this in autonomous mode and it will drive in this direction.
I changed the integer to an unsigned integer as suggested.
I placed in the Printscreens you mentioned and in the original code i get the following readings;
**
When UltraL is 1,11
& UltraR is 2,12**
Moving L because Ultra L is 2
Moving B because Ultra R is 59 <–STAGNANT READING
Moving L because Ultra L is 2
Moving B because Ultra R is 59
Moving L because Ultra L is 1
Moving B because Ultra R is 59
Moving L because Ultra L is 1
Moving B because Ultra R is 59
Moving L because Ultra L is 4
Moving B because Ultra R is 59
Moving R because Ultra L is 53
Moving B because Ultra R is 59
Moving R because Ultra L is 53
Moving B because Ultra R is 59
to see if my sensor is working properly i swapped the ports so; UltraL is 2,12
& UltraR is 1,11
Moving R because Ultra L is 68 <—STAGNANT READING
Moving B because Ultra R is 29
Moving R because Ultra L is 68
Moving B because Ultra R is 11
Moving R because Ultra L is 68
Moving B because Ultra R is 10
Moving R because Ultra L is 68
Moving F because Ultra R is 9
Moving R because Ultra L is 68
Moving F because Ultra R is 7
Moving R because Ultra L is 68
Moving F because Ultra R is 7
Moving R because Ultra L is 68
Moving F because Ultra R is 9
Moving R because Ultra L is 68
Moving F because Ultra R is 8
Moving R because Ultra L is 68
Moving F because Ultra R is 8
Moving R because Ultra L is 68
Moving F because Ultra R is 8
I want the robot to avoid the wall at all times (I will alter the distance accordingly so i’m using 10 for now). The motors are currently on full power, I was trying to get both ultrasonics responding before i ‘fine tuned’ the Speed, but the code i have seems to be confusing one/and or not reading.
If any more information is needed let me know and i will post it.
Avoiding the wall can easily be accomplished by setting all motors to 127 so that the robot doesn’t move. You will have to provide many more words to describe your actual intent. Maybe this “avoid the wall” is part of a bigger plan you are not sharing?
The printscreens show that one sensor appears stuck.
I have yet to see a description of what the robot does, to see if it matches the behavior suggested by the print screens. Can you describe the movement of the robot?
When you moved the sensors between ports, the stuck sensor reading moved with them. So whatever is plugged into ports 2,12 is stuck. That suggests an issue with config of those ports. Can you print your config screen?
If you move the robot by hand and re-run, so that the stuck port value should be different, is it different?
When all else fails, try adding wait(20); after each Stop (there are 2 stop).
Your printscreen example 1 shows UltraL reading sequence of 2,2,1,1,4,53
That seems unlikely to be reasonable unless the robot is spinning.
Maybe try unplugging the motors, and moving the robot by hand in response to the print screens. Put a wait(1000) at the top of the while loop to give you time to move the robot by hand.
Your printscreen example 2 shows ultraR reading sequence of 29,11,7,7,9,8,8,8 Somewhat more reasonable example of overshoot.
sorry, those values were achived by placing my robot on it’s side so it didn’t go anywhere, and put my hand infront of the sensor the robot wasn’t actually running on the floor. I thought i mentioned it in my post but i guess i didn’t.
I added a wait of 20 after BOTH stops and get the following readings by waving my hand infront of the sensor.
moving R because UltraL is 53 (Moving Right because nothing is > 10 away)
moving L because UltraR is 0 (Stagnant Reading)
moving F because UltraR is 4 (My hand detected)
moving L because UltraL is 0 (Stagnant Reading)
moving F because UltraR is 5 (My hand detected)
moving L because UltraL is 0 (Stagnant Reading)
moving F because UltraR is 4 (My hand detected)
moving L because UltraL is 0 (Stagnant Reading)
moving F because UltraR is 3 (My hand detected)
moving L because UltraL is 0 (Stagnant Reading)
moving F because UltraR is 54(Moving Right because nothing is > 10 away)
moving L because UltraL is 0 (Stagnant Reading)
moving F because UltraR is 52(Moving Right because nothing is > 10 away)
The best way i can describe the motion of the robot;
Opposite motors i.e Front and Rear will make it travel either forward or backwards.
When all four motors are rotating in the ‘forward direction’ (opposite motors travel the opposite ways) it can travel diagonally. If something is detected on e.g. UltraL less than 10cm away, then the motors in control of Ultra right drive forward as normal without interruption and the motors in Control of UltraL move away from the object until it is no longer in sight. It’s more of an object avoiding robot than a ‘wall follower’
I have tried Ports 3,13 instead of 2,11 for UltraR but get the same ‘Stagnant readings’.
Perhaps your PIC is broken, or needs reload of master code?
You could try using each of the other 5 possible INTERRUPT ports until you find another one that works, instead of just Int1.
If you comment out all of the working UltraL commands, does the UltraR start working, even when using Int2?
RE robot movement, I understand how standard holo moves in general.
I keep trying to ask about the motions your robot makes when running this program, but we aren’t connecting.
As for intent, If you connect just one set of motors with one Ultrasonic, I expect the robot with this program to drive forward toward the wall at full speed, until the ultrasonic trigger point is hit, and then back away from it at full speed untill the trigger is not hit, and then repeat. So your program logic enforces hovering at 10 from the wall. right?
there is no “StopUltrasonic”, try add/remove to see if it makes values 1 time update only.
Return time of these procedures if there is nothing plugged in could be several seconds, which may lead to poor control of robot.
The goal of Start/Stop inside the loop (previous posted code) was to avoid confusing signals from two US. Maybe that isn’t necessary? I can’t test for interference between two active US, since I have only one US.
Yes, “This is the Code I am Looking For…”, ( Said to the Storm Trooper beside me… ) and Thanks…
Here is where you can Share Your Code, so it is easy for others to locate it in the future…
BTW, what is the Title of the Song you used for that Video??? I find that kind of Music “very helpful”, when programming… ( That kind of Music and Dub Step seems to be a real Productivity Booster… Must be something about the 140 BPM, and Familiar but Repetitive Beat and Progressions… Interesting but not Distracting… )
I will share my code on the link you have provided
The Music on the video is not listed in the credits as I am not 100% sure what it is, A friend of a friend had it on in his car, I thought it was awesome so I borrowed It & made a copy. All that was on it was “Soltice Enlightened” handwritten on in some sort of marker. I have been unable to track it down as an album, but I believe it is a Concert ripped into 11 track. The Track in question is about 2.9MB and I would be happy to send it to you via email?
The Genre of the Track is Goa Psy Trance. These are the most ‘Floaty’ of the trances I think. I’ve always referred to Psy Trance as the modern classical Lyrics in songs are distracting I love alot of different types of music, but thinking time is always Trance for me.
May I suggest http://www.di.fm/ Just click on the Listen now tab and there’s lots of free Radio Genres to choose from
Happy Listening!