Go to Post mama always said better safe than sorry - Brandon Holley [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 05-02-2008, 19:37
bronxbomber92 bronxbomber92 is offline
Registered User
FRC #1551 (Grapes of Wrath)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Naples
Posts: 75
bronxbomber92 is an unknown quantity at this point
Pointer to pwm

I just wanted to make sure this was safe to do.

Code:
typedef struct
{
     // stuff
     unsigned char* pwm;
} Motor;

void InitMotor( Motor* motor, unsigned char* pwm, /* more parameters */ )
{
     // stuff
     motor->pwm = pwm;
}

then if I want to change the motor speed
Motor myMotor; InitMotor( myMoter, pwm10 );
myMotor.pwm = 127; // set it to nuetral
Is that all right to do? I assume it is, but just want to make sure.

Thanks
  #2   Spotlight this post!  
Unread 05-02-2008, 19:56
dcbrown dcbrown is offline
Registered User
AKA: Bud
no team
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Hollis,NH
Posts: 236
dcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud ofdcbrown has much to be proud of
Re: Pointer to pwm

Code:
typedef struct
{
     // stuff
     unsigned char* pwm;
} Motor;

void InitMotor( Motor* motor, unsigned char* pwm, /* more parameters */ )
{
     // stuff
     motor->pwm = pwm;
}

then if I want to change the motor speed
Motor myMotor; InitMotor( &myMotor, &pwm10 );
*myMotor.pwm = 127; // set it to nuetral
need * to dereference the pointer and & to pass a pointer in the places shown

Last edited by dcbrown : 05-02-2008 at 20:12.
  #3   Spotlight this post!  
Unread 05-02-2008, 20:03
bronxbomber92 bronxbomber92 is offline
Registered User
FRC #1551 (Grapes of Wrath)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Naples
Posts: 75
bronxbomber92 is an unknown quantity at this point
Re: Pointer to pwm

Nope, you're right!

Thanks

Last edited by bronxbomber92 : 05-02-2008 at 20:24.
  #4   Spotlight this post!  
Unread 05-02-2008, 23:36
Jon Stratis's Avatar
Jon Stratis Jon Stratis is offline
Mentor, LRI, MN RPC
FRC #2177 (The Robettes)
Team Role: Mentor
 
Join Date: Feb 2007
Rookie Year: 2006
Location: Minnesota
Posts: 3,815
Jon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond reputeJon Stratis has a reputation beyond repute
Re: Pointer to pwm

that seems like an OK way to do it... what might end up being easier, though, is to just do something like:

#define leftMotor pwm01
#define rightMotor pwm02

then you can use your left and right motors wherever you want, and if someone plugs something in backwards and doesn't want to unplug it you just have to change it in the one location in the header file. Just another option to consider!
  #5   Spotlight this post!  
Unread 06-02-2008, 00:24
JohnC's Avatar
JohnC JohnC is offline
my other name is nigel
FRC #0360 (360 Revolution)
Team Role: Programmer
 
Join Date: Mar 2005
Rookie Year: 2005
Location: user_routines.c
Posts: 100
JohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the roughJohnC is a jewel in the rough
Send a message via AIM to JohnC
Re: Pointer to pwm

We use Left(int) and Right(int)
Code:
void Left(int speed) {
  pwm01 = speed;
  
  if(pwm01 > 254) {
    pwm01 = 254;
  } else if(pwm01 < 1) {
    pwm01 = 1;
  }
}
And the right one assigns 254-speed. Just yet another form of abstraction
__________________
What place are we at? ... TODAI!
  #6   Spotlight this post!  
Unread 07-02-2008, 15:57
bronxbomber92 bronxbomber92 is offline
Registered User
FRC #1551 (Grapes of Wrath)
Team Role: Programmer
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Naples
Posts: 75
bronxbomber92 is an unknown quantity at this point
Re: Pointer to pwm

Quote:
Originally Posted by eagle33199 View Post
that seems like an OK way to do it... what might end up being easier, though, is to just do something like:

#define leftMotor pwm01
#define rightMotor pwm02

then you can use your left and right motors wherever you want, and if someone plugs something in backwards and doesn't want to unplug it you just have to change it in the one location in the header file. Just another option to consider!
That's what I have currently, and I've debating if I should use a more OO approach, which I'm still not sure of. Just brain storming
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Suspicious pointer conversion ebowla Programming 2 26-01-2008 12:13
laser pointer 1574aviad Technical Discussion 9 20-02-2005 20:25
pwm 13-15 wayne 05 Programming 2 04-10-2003 12:08
PWM Antonio Technical Discussion 21 06-01-2003 14:44
Pwm VanWEric Programming 17 01-11-2002 16:07


All times are GMT -5. The time now is 19:08.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi