This is my first time writing with NXC and/or object oriented programming in general. I am making a program that takes values from the Mindsensors PSP-Nx controller and moves servos using the Mindsensors NXTServo accordingly. Whenever I try to compile i find weird errors talking about parenthesis and semicolons being left out. I am not sure what it is directly talking about. Any ideas?
Code: Select all
#include "PSP-Nx-lib.nxc"
#include "NXTServo-lib.nxc"
const byte SensorPort = IN_1;
#define ADDR 0x02
#define ServoSensorPort S2
const byte ServoAddr = 0xb0;
int Servo1, Servo2, Servo3, Servo4, Servo5, Servo6, Servo7, Servo8;
int Pos_Rotate, Pos_Base, Pos_Mid, Pos_End, Pos_Gripper_Rotate, Pos_Gripper;
int Servo1Speed, Servo2Speed, Servo3Speed, Servo4Speed;
int Servo5Speed, Servo6Speed, Servo7Speed, Servo8Speed;
psp currState;
string msg, x;
task base_rotation () //This controls the rotating base
{
if (PSP_format_bin(currState.r_j_y) != 0) {
Servo1Speed = abs("PSP_format_bin(currState.r_j_y)");
NXTServo_SetSpeed("ServoSensorPort", "ServoAddr", "Servo1", "Servo1Speed");
while (PSP_format_bin(currState.r_j_y) > 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo1", "Pos_Rotate");
Pos_Rotate += 2;
Wait(100);
}
while (PSP_format_bin(currState.r_j_y < 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo1", "Pos_Rotate");
Pos_Rotate -= 2;
Wait (100);
}
}
}
task base_link () //This controls the first joint attached to base
{
if (PSP_format_bin(currState.r_j_x) != 0) {
Servo2Speed = abs("PSP_format_bin(currState.r_j_x)");
Servo3Speed = abs("PSP_format_bin(currState.r_j_x)');
NXTServoSpeed ("ServoSensorPort", "Servo2", "Servo2Speed");
NXTServoSpeed ("ServoSensorPort", "Servo3", "Servo3Speed");
while (PSP_format_bin(currState.r_j_x) > 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo2", "Pos_Base");
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo3", "Pos_Base");
Pos_Base += 2;
Wait (100);
}
while (PSP_format_bin(currState.r_j_x) < 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo2", "Pos_Base");
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo3", "Pos_Base");
Pos_Base -= 2;
Wait (100);
}
}
}
task middle_link () //This controls the middle joint
{
if (PSP_format_bin(currState.l_j_x) != 0) {
Servo4Speed = abs("PSP_format_bin(currState.l_j_x)");
Servo5Speed = abs("PSP_format_bin(currState.l_j_x)");
NXTServoSpeed ("ServoSensorPort", "Servo4", "Servo4Speed");
NXTServoSpeed ("ServoSensorPort", "Servo5", "Servo5Speed");
while (PSP_format_bin(currState.l_j_x) > 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo4", "Pos_Mid");
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo5", "Pos_Mid");
Pos_Mid += 2;
Wait (100);
}
while (PSP_format_bin(currState.l_j_x) < 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo4", "Pos_Mid");
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo5", "Pos_Mid");
Pos_Mid -= 2;
Wait (100);
}
}
}
task end_link () //This controls the end joint
{
if (PSP_format_bin(currState.l_j_y) != 0) {
Servo6Speed = abs("PSP_format_bin(currState.l_j_y)");
NXTServoSpeed ("ServoSensorPort", "Servo6", "Servo6Speed");
while (PSP_format_bin(currState.l_j_y) > 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort","ServoAddr", "Servo6", "Pos_End");
Pos_End += 2;
Wait (100);
}
while (PSP_format_bin(currState.l_j_y) < 0) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo6", "Pos_End");
Pos_End -= 2;
Wait (100);
}
}
}
task gripper_rotate () //This controls the gripper attachement rotation
{
while (PSP_format_bin(currState.R1) == 1) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo7", "Pos_Gripper_Rotate");
Pos_Gripper_Rotate ++
Wait (100);
}
while (PSP_format_bin(currState.L2) == 1) {
NXTServo_Quick_Servo_Setup("ServoSensorport", "ServoAddr", "Servo7", "Pos_Gripper_Rotate");
Pos_Gripper_Rotate --
Wait (100);
}
}
task gripper_control () //This controls the gripper attachment servo
{
while (PSP_format_bin(currState.L1) = 1) {
NXTServo_Quick_Servo_Setup("ServoSensorPort", "ServoAddr", "Servo8", "Pos_Gripper");
Pos_Gripper ++
Wait (100);
}
while (PSP_format_bin(currState.L2) = 1) {
NXTServo_Quick_Servo_Setup("ServoSensorPOrt", "ServoAddr", "Servo8", "Pos_Gripper");
Pos_Gripper --
Wait (100);
}
}
task main ()
{
Precedes(base_rotation, base_link, middle_link, end_link, gripper_control);
Servo1 = 1, Servo2 = 2, Servo3 = 3, Servo4 = 4, Servo5 = 5, Servo6 = 6, Servo7 = 7, Servo8 = 8;
while (true ) { //Monitor controller power and display it's status
PSP_ReadButtonState(SensorPort, ADDR, currState);
msg = "b1: Controller Active! ";
x = PSP_format_bin(currState.b1);
msg = StrReplace(msg, 3, x);
TextOut(0, LCD_LINE1, msg, false);
}
}