I spotted several problems.
First, your "{" and "}" characters don't match up. The final "}"
actually matches up with the "{" in the lines
> else
> {currentTram = 0;
while it should match up with the one for "FUNCTION(_) {". I am not
entirely sure how you intend your {} to match up, so I'm not sure how to
fix this, so I just added another "}" at the very end.
Second, you use the same name for a pin and a local variable ("pin in
bit tram" and "int ... tram"). This leads to the cryptic error
gear4.comp:73: error: expected identifier or ‘(’ before numeric constant
perhaps you should simply remove the declaration "int ... tram" in your
FUNCTION.
Third, you have used "=" (assignment) when you meant "==" (compare for
equality):
> if (tram = 1)
> SOL33=1;
Fourth, these macros
> #define SOL31 (*inst->sol31)
probably don't do what you want and are leading to compile errors as
well. Mabe you just want
#define SOL31 sol31
Fifth, you write speedDac in one place and speedDAC in another. These
have to have the same case.
Sixth, you use fprintf. You should use rtapi_print_msg instead.
Similarly, you can't call exit().
After a large number of changes, I do get the component to compile but I
don't know whether it works as you intend. It does still get warning
messages:
gear4.comp:68: warning: unused variable ‘programFeed’
gear4.comp:67: warning: unused variable ‘adaptiveFeed’
gear4.comp:71: warning: ‘programRPM’ is used uninitialized in this function
gear4.comp:134: warning: ‘spindleEncoder’ is used uninitialized in this function
See attached for my modified source code.
Jeff
component gear4 "Select gear range from requested spindle speed";
/* This component if for a 4 speed gearbox with a separate tram shifter.
* This has 5 solenoids to shift the gears and 5 limit switches to
indicate the gearbox state.
* It will sense the spindle speed near zero from the encoder
feedback and inhibit the
* tram shifting until the spindle is slow enough.
* It will drive the spindle very slow to allow gear mesh.
*/
pin in float spincmd "spindle command from EMC";
pin in float spinspeed "spindle speed from encoder";
pin out float spinon "spindle speed command to VFD";
pin in float spinslow "gear mesh speed";
pin out bit sol31;
pin out bit sol32;
pin out bit sol33;
pin out bit sol34;
pin out bit sol35;
pin in float minSpeed;
pin in float maxGear1;
pin in float maxGear2;
pin in float maxGear3;
pin in float maxGear4;
pin in float zeromax "max spindle speed to be considered zero for tram";
pin in bit ls1;
pin in bit ls2;
pin in bit ls3;
pin in bit ls4;
pin in bit tram;
variable int skippy;
variable int range;
variable int shifting;
function _;
license "GPL";
;;
//FUNCTION(_) {
/*gear program*/
/*read*/
/* #include <stdio.h>
#include <stdlib.h> */
#include "rtapi.h"
#include "rtapi_app.h"
#include "rtapi_string.h"
#include "hal.h"
#define fperiod (period * 1e-9)
#define spincmd (0+*inst->spincmd)
#define spinspeed (0+*inst->spinspeed)
#define spinon (*inst->spinon)
#define spinslow (0+*inst->spinslow)
#define SOL31 sol31
#define SOL32 sol32
#define SOL33 sol33
#define SOL34 sol34
#define SOL35 sol35
#define MINSPEED minSpeed
#define GEAR1MAX maxGear1
#define GEAR2MAX maxGear2
#define GEAR3MAX maxGear3
#define GEAR4MAX maxGear4
FUNCTION(_) {
int gear, currentGear, currentTram;
float scale, currentScale, spindleEncoder, speedDAC, adaptiveFeed,
transition = 2, programRPM, programFeed;
//set desired gear and scale needed
if (programRPM > MINSPEED && programRPM < GEAR1MAX)
{
gear = 1;
scale = 15.2;
}
else if (programRPM > GEAR3MAX)
{
gear = 4;
scale = 1;
}
else if (programRPM > GEAR2MAX)
{
gear = 3;
scale = 1.9;
}
else
{
gear = 2;
scale = 8;
}
//spindle encoder read and current gear set
/* initialize the solenoids to the startup state of the gearbox */
if (SOL31 == 1 && SOL34 == 1)
{
currentGear = 1;
currentScale = 15.2;
}
else if (SOL31 == 1 && SOL35 == 1)
{
currentGear = 2;
currentScale = 8;
}
else if (SOL32 == 1 && SOL34 == 1)
{
currentGear = 3;
currentScale = 1.9;
}
else
{
currentGear = 4;
currentScale = 1;
}
// set tram
if (sol33 == 1)
{
currentTram = 1;
currentGear = 5;
}
else
{currentTram = 0;
//if no shift needed
if (currentGear == gear)
spindleEncoder = programRPM * scale;
//if shift needed
else
{
//set speed to slow down for transition
speedDAC = transition * currentScale;
//turn on gear solinoids once spindle speed is less than
transition speed
if (spindleEncoder <= transition * currentScale)
switch (gear)
{
case 1: SOL31=1;
SOL32=0;
SOL34=1;
SOL35=0;
break;
case 2: SOL31=1;
SOL32=0;
SOL34=0;
SOL35=1;
break;
case 3: SOL31=0;
SOL32=1;
SOL34=1;
SOL35=0;
break;
case 4: SOL31=0;
SOL32=1;
SOL34=0;
SOL35=1;
break;
default: rtapi_print_msg (RTAPI_MSG_ERR, "ERROR in Gear
Switch\n") ;
break;
if (tram == 1)
SOL33=1;
}
}
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Emc-users mailing list
Emc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-users