#include <stdlib.h>
#include "ch.h"
#include "hal.h"
#include "clawbot.h"
};
};
#define MotorDriveR kVexMotor_1
#define MotorArm kVexMotor_8
#define MotorClaw kVexMotor_9
#define MotorDriveL kVexMotor_10
#define armPot kVexAnalog_1
#define clawPot kVexAnalog_2
void
{
long drive_l_motor;
long drive_r_motor;
drive_l_motor = forward + turn;
drive_r_motor = forward - turn;
int max = abs(drive_l_motor);
if (abs(drive_r_motor) > max)
max = abs(drive_r_motor);
if (max>127) {
drive_l_motor = 127 * drive_l_motor / max;
drive_r_motor = 127 * drive_r_motor / max;
}
}
{
short forward, turn;
(void)arg;
while(1)
{
else
forward = 0;
else
turn = 0;
}
}
static int armRequestedValue;
#define ARM_UPPER_LIMIT 2000
#define ARM_LOWER_LIMIT 600
#define ARM_PRESET_H 2000
#define ARM_PRESET_L 650
static void
SetArmPosition( int position )
{
else
else
armRequestedValue = position;
}
static int
GetArmPosition(void)
{
return( armRequestedValue );
}
{
int armSensorCurrentValue;
int armError;
float armDrive;
static float pid_K = 0.3;
(void)arg;
while( true )
{
armError = armRequestedValue - armSensorCurrentValue;
armDrive = (pid_K * (float)armError);
if( armDrive > 127 )
armDrive = 127;
else
if( armDrive < (-127) )
armDrive = (-127);
}
}
typedef enum {
#define CLAW_OPEN_HIGH_SPEED 80
#define CLAW_CLOSE_HIGH_SPEED -80
#define CLAW_OPEN_LOW_SPEED 20
#define CLAW_CLOSE_LOW_SPEED -15
static void
ClawClose(void)
{
}
static void
ClawOpen(void)
{
}
static void
ClawStop(void)
{
}
{
int hold_delay = 0;
(void)arg;
while(1)
{
switch( clawCmd )
{
else
break;
else
{
if(hold_delay++ > 20)
{
}
else
}
break;
break;
default:
break;
}
hold_delay = 0;
}
}
{
(void)arg;
while( true )
{
else
ClawOpen();
else
ClawClose();
else
ClawStop();
}
}
void
{
}
void
{
}
msg_t
{
(void)arg;
SetArmPosition( 2000 );
ClawOpen();
SetArmPosition( 700 );
ClawClose();
SetArmPosition( 1000 );
ClawOpen();
ClawStop();
while(1)
{
}
return (msg_t)0;
}
msg_t
{
(void)arg;
while(!chThdShouldTerminate())
{
}
return (msg_t)0;
}