Troubleshooting Define Commands in C for Robot Motor Control

  • Thread starter Thread starter Lancelot59
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a define command in C programming related to robot motor control. Participants are addressing issues with the definition and usage of a macro for throttle values in the context of motor control functions.

Discussion Character

  • Technical explanation, Debugging

Main Points Raised

  • One participant describes a function for moving a robot forward and mentions the use of a throttle value defined in a header file.
  • Another participant requests error messages to better understand the issue.
  • A suggestion is made to remove the equals sign from the define command, indicating it should be written as #define THROTTLE fast.
  • A participant acknowledges the mistake and notes a syntax error encountered when the compiler processed the function using THROTTLE.
  • Another participant explains that the preprocessor directive performs text replacement and emphasizes the importance of not including an equals sign in simple preprocessor directives.
  • A later reply confirms understanding of the explanation provided.

Areas of Agreement / Disagreement

Participants generally agree on the correction regarding the use of the equals sign in the define command, with no significant disagreement noted.

Contextual Notes

The discussion does not address potential implications of the throttle value or the broader context of its use in the robot's motor control system.

Who May Find This Useful

Readers interested in C programming, particularly in the context of robotics and motor control, may find this discussion relevant.

Lancelot59
Messages
640
Reaction score
1
This is once again for my robot. My current issue is with a define command:

I have the following function defined in motor_control.c:

Code:
//*****************************************************************************
//Motor Control Functions
//*****************************************************************************
void forward(void)			//Go striaght forward
{
	motorR(THROTTLE,TRIM);
	motorL(THROTTLE,TRIM);
}
The throttle value controls speed, trim offsets the speed variable. Although it probably will be eliminated.

Anyhow, I have throttle defined in a header called system_config.h:

Code:
#define THROTTLE = fast 	//Default forward throttle value to use

The value for "fast" has been enumerated in the header for motor_control.c

I have included the system_config.h file in the motor_control.c library, so what can't I see it? As far as I'm aware it should be able to see that defined value.
 
Physics news on Phys.org
Show error messages.
 
Get rid of the equals sign.

#define THROTTLE fast
 
D H said:
Get rid of the equals sign.

#define THROTTLE fast

...That was a silly mistake. Thanks for the catch.

The only error message I got was a syntax error when the compiler got to the first function that tried to pass THROTTLE to a function. It didn't say anything else.

Thanks again for the help.
 
The code your compiler saw was this.
Code:
motorR(= fast,TRIM);
motorL(= fast,TRIM);

The reason for this is that the #define preprocessor directive does nothing more than text replacement. This is why you DON'T want to put = in simple preprocessor directives.
 
I see, that makes sense.
 

Similar threads

Replies
4
Views
2K
  • · Replies 11 ·
Replies
11
Views
4K
  • · Replies 46 ·
2
Replies
46
Views
14K