My team are looking at improving our autonomous using sensors to improve it’s accuracy. However, we can’t find any tutorials or help out there on the internet. I think I have a rough understanding of how some sensors work but I cannot work out how to programme them on easyc. We seem to find lots of robotc tutorials but no easyc ones
Does anyone have any help they could give me or any code I could look at? We are particularly interested in potentiometers and optical shaft encoders
Thanks in advance
I don’t use Easy C anymore but there are a number of previous years projects (and other projects) posted here. in particular the one titled: 2010 Programming Skills Challenge World Championship Code is an awesome example of Easy C coding Josh won the programming skills and drivers skills at Worlds with this code.
Is there anything easier I can look at? I couldn’t look at the code you suggested as it was on easyc pro and my school have V4. However, I looked at another example. It was very complicated and I didn’t really understand any of to be honest.
Sorry I did some autonomous programming last year but never anything anywhere nearly as complicated as that
I’m not sure I have any examples in easy C that would be easier. Most of my work in EasyC was over 2 years ago, and those robots have long been rebuilt into other models. I was learning to code for the robots and struggled with good practices. There was a bug with Easy C at the time in which comment blocks would cause my Easy C program to crash unexpectedly, so my commenting was limited to end of line comments.
I think if you really want help if you can explain how your robot is built and how you would like it to operate. I might be able to guide you through 'pseudo code examples which you could try in easy C. For example. do you have a 2 motor drive (left and right) with Quad shaft encoders on each wheel and would you like to drive forward 10 inches and make a hard left turn?
If you understand the problems you can break it down step by step and look for samples / example and tutorials for each of the various problems .
Have you attempted to work through all the tutorials in the tutorial directory?
You say you have Easy C V4? is it version 126.96.36.199? if so when you go to file-> open easy C project there is a region on the lower left of the dialog box that you can click on Samples and Tutorials. These are about the easiest components of the various sensor examples. If you have a specific problem or portion of a problem to attack I might be able to suggest methods to attack the problem.
Thanks so much for your help our team all really appreciate it,
Ok so I looked through some of the sample codes. I found out a few useful bits of information, I also found a YouTube video showing how you can user a potentiometer to select autonomous routines (is this similar to lifting an arm?)
My plan is to have an autonomous where our optical shaft encoders allow us to move forward a set distance then the potentiometers lift the arm to the troughs height.
My school have been given the chance to use robotc now instead of easyc do you think this would be a better idea? I have a little bit of an idea how it works as I have used the free trial, but I wouldn’t say I’m confident
Well, o.k. do you have your robot built with the OSEs in place? have you tried following the example to get readings from the OSE’s to show up in printout? I assume you know how to print to the debug screen? if not look up the example included with Easy C & try to modify it so you can get readings from both wheels.
If you don’t have the encoders on the robot yet, you can load the sample code and try it for yourself with an OSE device hooked up to the cortex, and just using an axle to spin the shaft encoder by hand you should be able to verify you get readings from the OSE.
Once you are sure you have readings from the OSE’s you’ll need to design how you can use the information.
You can do the same process with the potentiometer. Note that you need to be careful with the potentiometers as they have a limited range of motion ~270 degrees. so you should hand test the range of motion by using an axle and hand rotating the shaft back and forth until you find the 2 stops. Then mount the potentiometer on your robot such that the part it is measuring will only rotate between those 2 stops. if you force a potentiometer past the stops you can damage it to the point it won’t work, you might get lucky and it’ll pop back into place, but best to keep from driving it past it’s stops.
Let me know when you get this far. I’ll try to put together an example in Easy C to drive a distance an stop, then suggest how you could improve it eh?
I’ve put together a sample which is based upon the concept the robot has 2 drive motors (left and right) and each drive motor has an encoder connected. The code initializes the Optical Shaft encoders, then in the while loop it checks to see if the OSE has reached 500 if not it turns on the motor for that side if the OSE is equal or more than 500 it will shut off the motor. This is pretty basic but will likely do the job with a little testing and tuning.
First you need to test if you have the encoders set up to increment when driving forward or not, and also to check for the motor forward command the wheels turn in a direction to move the robot forward.
Let me know if you have any questions on this or if you get this to work, and if you still need help on the arm lifting based upon potentiometer feedback.
Also if you’d like to know how to make this ‘better’ we could discuss that here too.
I ported the code to my PIC (EASY C Pro) for testing as I have a PIC on the simple robot chassis. it worked after I checked the 2 things listed above I had to fix one OSE direction and one motor direction.
AutonomousDriveSample.zip (2.25 KB)
Ok, today I’m going to try the sensors thing you suggested first, to check if they are working. Our robot is having a bit of a re-build at the moment but once it is done I will try the shaft encoder thing. In the mean time I will try to write the same thing for potentiometers.
I have had a quick look at what you have written and it looks really helpful, I just couldn’t work out how to get started!
I’ll let u know how I get on thanks again
Some things to keep in mind, keep you variable names meaningful so you can tell what they are intended for when you see them in the pull down lists. Be careful not to re-use a variable in your code for other than it’s primary purpose as that can really be confusing.
For the arm, depending on how the arm is constructed, you may need to provide some upward ‘push’ from the motors when it gets to it’s destination. to counteract gravity. That is usually o.k. in our robot scale as long as the ‘hold’ power is small, but the hold power is a ‘stall’ current which heats up the motor’s PTC (Thermal fuse) So as your team re-builds try to influence the design such that they don’t need much power to hold up the arm. There is a ton of information on the forums on arm design and use of mechanical assists to counteract gravity.
Ok, I gave it ago at writing a simple autonomous routine. The robot drives forward then lifts up and tips the tray scoring the pre loaded sack.
Your code was very helpfull thanks
AutonomousDriveSample.zip (3.03 KB)
Awesome, Glad to be of help. Hope to see you at worlds. Feel free to ask if there’s anything else you need some help with.