View unanswered posts | View active topics It is currently Thu Apr 17, 2014 12:30 am






Reply to topic  [ 5 posts ] 
180 Degree Sweep 
Author Message
Rookie

Joined: Fri Feb 12, 2010 4:16 pm
Posts: 9
Post 180 Degree Sweep
The source code attached does the following when stepped through in debug mode: The sensor servo turns 45 degrees to the left, waits, then turns another 45 degrees to the left. Once it is at 90 degrees to the left from center it goes back to the right 90 degrees to be at center. Next it does the same thing to the right.

When the program is ran, the servo will turn 90 degrees to the right, then 45 degrees to the left and stop.

I've also attached a picture of the bot and a link to the video of the behavior when the code is ran.

http://www.youtube.com/watch?v=DWaA7QrIDNk

Thanks!


Attachments:
SourceCode2.c [2.34 KiB]
Downloaded 183 times
BotPicture.jpg
BotPicture.jpg [ 598.61 KiB | Viewed 2323 times ]
Wed Jan 05, 2011 12:31 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: 180 Degree Sweep
Todd,

I can confirm this issue. It goes to about -25 degrees and just stops. I have tested it with motor A, B and C. I've condensed the code to demonstrate just this issue and removed all extra code. I will mail the developers with the code and a reference to this thread.

Just some pointers (pardon the pun):

  • Don't bother resetting the tachos when you're using the encoderTarget mechanism, it's a relative heading. Resetting the tachos can actually mess it up, unless you put a 50-100ms wait in between it.
  • when doing a for() loop, don't use iCount =< 1, it's more conventional to use iCount < 2. It totally overlooked the =< operator and was wondering why the heck you would make a for() loop when you're only executing it once.
  • Never do tight while() loops (i.e. no code in them). It is better to put a EndTimeSlice(); in there or a wait1Msec(1); that signals the scheduler that it's OK to switch to another task while you're waiting for something to change.
  • Add a space between your variable, = and assigned value, it's much harder to tell if there's a - in front of the assigned value if it's right after a =
  • Always write your code with the thought in mind that someone else may need to read and understand it quickly.

I've attached the code I'll be sending to the developers.

- Xander


Attachments:
SourceCode2.c [1.36 KiB]
Downloaded 164 times

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Wed Jan 05, 2011 2:58 am
Profile WWW
Rookie

Joined: Fri Feb 12, 2010 4:16 pm
Posts: 9
Post Re: 180 Degree Sweep
Thanks Xander!

Been wrestling with this for a while, thinking I was misunderstanding something more than usual, lol. A couple questions/comments:

1. The tach reset was done in an effort to try to troubleshoot. Been having problems with the encoder reaching the target and for some reason it would work when going from 0 to 45 and 90 to 0 but not 45 to 90

2. Thank you for the recommendation on putting the pause in the while statement and on syntax to improve code readability. That's always a rough one for me.

3. I'm using just the stock Mindstorm kit. What benefits what I gain from using your driver set?


Wed Jan 05, 2011 10:43 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3105
Location: Rotterdam, The Netherlands
Post Re: 180 Degree Sweep
Todd wrote:
2. Thank you for the recommendation on putting the pause in the while statement and on syntax to improve code readability. That's always a rough one for me.

You'll find that if your code is well documented you will have fewer "WTF?" moments in a few months' time when you go through your old code. Remember quality of code is measured in WTFs per minute. This not made up stuff, trust me.

Quote:
3. I'm using just the stock Mindstorm kit. What benefits what I gain from using your driver set?

My driver suite is for people who want to access all of the functionality that a lot of the 3rd party sensors provide. ROBOTC supports a lot of sensors out of the box, but usually only the most commonly used stuff. An example of this would be the HiTechnic compass sensor. With the built-in driver, you can only read the current heading. With my driver you can not only read the current heading but you can calibrate it, get a relative heading and use together with the HiTechnic Sensor MUX. If you're not using any 3rd party sensors made by companies like HiTechnic, Mindsensors or Dexter Industries then you may not find the drivers will be of much benefit to you.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Wed Jan 05, 2011 10:50 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Post Re: 180 Degree Sweep
Thank you for the WTFs per minute comment Xander. You just made my week.

_________________
sudo rm -rf /


Wed Jan 05, 2011 8:15 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.