/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd.			    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/*---------------------------------------------------------------------------
 *		
 * MODULE NAME:	setManip
 *
 * DESCRIPTION:	functions used by the trajectory generator for assigning 
 *		variables in the MANIP structure.
 *
 *		What is going on here is the following:
 *
 *		There is one trajectory task on each CPU. Each task 
 *		(or more specifically, each CPU) has a private copy
 *		of the MANIP structure for every robot on the system.
 *		This is necessary because the MANIP structire contains
 *		pointers to sharde objects, and the values of these can
 *		be different between CPUs. The problem this creates,
 *		however, is that when we want to change one of the resident
 *		fields in a MANIP structure, we have to set that field
 *		in each copy of that MANIP structure on each CPUs.
 *
 *		That is exactly what these routines do, for various resident
 *		fields in the MANIP structure. Pointers to the MANIP 
 *		structure on each CPU are contained in the 'mpb->mnps' field.
 * 
 * CAVEATS:	As the casual reader of this code will observe, I am
 *		somewhat conscious about execution speed.
 *
 * AUTHOR/DATE:	John Lloyd, Fall 1988
 *
 * MODIFICATION HISTORY:
 *
 *--------------------------------------------------------------------------*/

#include "../h/rcclDefs.h"

#include "../rccl/setpoint.h"

setManipCompleted (mpb, value)
MOTION_PARAMETER_BLOCK *mpb;
int value;
{
	/* set the 'completed' field in each copy of MANIP */

	register MANIP *mnp;
	int k;
	
#if MAX_CPUS > 0
	if (mnp = mpb->mnps[0])
	 { mnp->completed = value;
	 }
#endif
#if MAX_CPUS > 1
	if (mnp = mpb->mnps[1])
	 { mnp->completed = value;
	 }
#endif
#if MAX_CPUS > 2
	if (mnp = mpb->mnps[2])
	 { mnp->completed = value;
	 }
#endif
#if MAX_CPUS > 3
	if (mnp = mpb->mnps[3])
	 { mnp->completed = value;
	 }
#endif
#if MAX_CPUS > 4
	for (k=4; k<MAX_CPUS; k++)
	 { if (mnp = mpb->mnps[k])
	    { mnp->completed = value;
	    }
	 }
#endif
}

setManipConf (mpb, value)
MOTION_PARAMETER_BLOCK *mpb;
int value;
{
	/* set the 'conf' field in each copy of MANIP */

	register MANIP *mnp;
	int k;
	
#if MAX_CPUS > 0
	if (mnp = mpb->mnps[0])
	 { mnp->conf = value;
	 }
#endif
#if MAX_CPUS > 1
	if (mnp = mpb->mnps[1])
	 { mnp->conf = value;
	 }
#endif
#if MAX_CPUS > 2
	if (mnp = mpb->mnps[2])
	 { mnp->conf = value;
	 }
#endif
#if MAX_CPUS > 3
	if (mnp = mpb->mnps[3])
	 { mnp->conf = value;
	 }
#endif
#if MAX_CPUS > 4
	for (k=4; k<MAX_CPUS; k++)
	 { if (mnp = mpb->mnps[k])
	    { mnp->conf = value;
	    }
	 }
#endif
}

setManipCondition (mpb, value)
MOTION_PARAMETER_BLOCK *mpb;
int value;
{
	/* set the 'condition' field in each copy of MANIP */

	register MANIP *mnp;
	int k;
	
#if MAX_CPUS > 0
	if (mnp = mpb->mnps[0])
	 { mnp->condition = value;
	 }
#endif
#if MAX_CPUS > 1
	if (mnp = mpb->mnps[1])
	 { mnp->condition = value;
	 }
#endif
#if MAX_CPUS > 2
	if (mnp = mpb->mnps[2])
	 { mnp->condition = value;
	 }
#endif
#if MAX_CPUS > 3
	if (mnp = mpb->mnps[3])
	 { mnp->condition = value;
	 }
#endif
#if MAX_CPUS > 4
	for (k=4; k<MAX_CPUS; k++)
	 { if (mnp = mpb->mnps[k])
	    { mnp->condition = value;
	    }
	 }
#endif
}

setManipMid (mpb, value)
MOTION_PARAMETER_BLOCK *mpb;
int value;
{
	/* set the 'mid' field in each copy of MANIP */

	register MANIP *mnp;
	int k;
	
#if MAX_CPUS > 0
	if (mnp = mpb->mnps[0])
	 { mnp->mid = value;
	 }
#endif
#if MAX_CPUS > 1
	if (mnp = mpb->mnps[1])
	 { mnp->mid = value;
	 }
#endif
#if MAX_CPUS > 2
	if (mnp = mpb->mnps[2])
	 { mnp->mid = value;
	 }
#endif
#if MAX_CPUS > 3
	if (mnp = mpb->mnps[3])
	 { mnp->mid = value;
	 }
#endif
#if MAX_CPUS > 4
	for (k=4; k<MAX_CPUS; k++)
	 { if (mnp = mpb->mnps[k])
	    { mnp->mid = value;
	    }
	 }
#endif
}

setManipHandPos (mpb, value)
MOTION_PARAMETER_BLOCK *mpb;
int value;
{
	/* set the 'handPos' field in each copy of MANIP */

	register MANIP *mnp;
	int k;
	
#if MAX_CPUS > 0
	if (mnp = mpb->mnps[0])
	 { mnp->handPos = value;
	 }
#endif
#if MAX_CPUS > 1
	if (mnp = mpb->mnps[1])
	 { mnp->handPos = value;
	 }
#endif
#if MAX_CPUS > 2
	if (mnp = mpb->mnps[2])
	 { mnp->handPos = value;
	 }
#endif
#if MAX_CPUS > 3
	if (mnp = mpb->mnps[3])
	 { mnp->handPos = value;
	 }
#endif
#if MAX_CPUS > 4
	for (k=4; k<MAX_CPUS; k++)
	 { if (mnp = mpb->mnps[k])
	    { mnp->handPos = value;
	    }
	 }
#endif
}


