View unanswered posts | View active topics It is currently Fri Aug 01, 2014 11:55 am






Reply to topic  [ 3 posts ] 
sinusoid code? 
Author Message
Rookie

Joined: Wed Apr 21, 2010 3:26 pm
Posts: 1
Post sinusoid code?
Hi all,
I'm new to robotics and C. I'm trying to drive my vex servo sinusoidally with the pic18F8520 vex microcontroller - from what i've seen so far online and in the help topics, it doesn't look like there is a function for this in robotC for ifi, but i thought i'd post to the forum and see if anyone had any experience or advice on how to write code which would drive the servo in a sine function, or just vary velocity over time smoothly. Any advice would be appreciated, thanks!


Wed Apr 21, 2010 3:39 pm
Profile
Rookie

Joined: Sat Nov 22, 2008 8:06 pm
Posts: 48
Post Re: sinusoid code?
It can be done, but it would be manually. If it didn't have to be sinusoidal and you just wanted it smooth, you could just average the old and new motor speed values. I would suggest about 3 to 1 average, old value to new, such that you would have code like this.

Code:
motor[leftMotor] = (int)(3*oldMVal+motorVal)/4;
oldMval = (int)(3*oldMVal+motorVal)/4;


oldMVal would and motorVal would just be standard character variables. You would change motorVal in your code to run the motor smoothly. I think the (int)s would be required to keep the values from overflowing.

Anyhow, this would do it, with just a short pause between loops. Maybe like 50 milliseconds. More if you want it even smoother.

If you really want perfect sinusoidal control, well, RobotC does have some built in trig commands.


Thu Apr 22, 2010 12:34 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3168
Location: Rotterdam, The Netherlands
Post Re: sinusoid code?
Using trig functions might use unnecessary amounts of processing time. Does it really need to be sinusoidal or does it just need to be smooth? I would go with Bluesaberist's solution. Remember, K.I.S.S.

Regards,
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]


Thu Apr 22, 2010 1:36 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.