Good evening ladies and gentlemen, and viewing robots of all ages!
Over the past few days, I have been trying to work on the gyroscope of my robot in PROS. If any of you have experience with PROS code, please continue to read this forum!
The intention of my program it to be able to make the robot turn based on a Gyro, a simple task at heart.
Given that I am a beginner to the PROS workspace and coding environment I tried to take my code from my previous program software and translate it into PROS, most of this worked except for the gyroscope.
Note: It had previously worker on the different software.
I’ll give you the code I used below with a quick description:
The below is code from my var.h file that deals with all global variables such as motor ports, sensor ports, and soon to be much more:
#include <API.h>
Gyro gyro1;
//Motors
#define FlatbedMotorLeft 10 //Flatbed motor on spot 10
#define ArmMotorRightUp 9 //Arm motor on spot 9
#define ArmMotorRightY 8 //Arm motor on spot 8
#define RFW 6 //Right front wheel motor on spot 7
#define RBW 7 //Right back wheel motor on spot 6
#define LBW 4 //Left back wheel motor on spot 5
#define LFW 5 //Left front wheelmotor on spot 4
#define ArmMotorLeftY 3 //Arm motor on spot 3
#define ArmMotorLeftUp 2//Arm motor on spot 2
#define FlatbedMotorRight 1//Flatbed motor on spot 1
//Sensors (Digital)
#define DownBumpP 12
#define FBBumpP 8
#define ArmStableBump 10
#define ArmVertBump 9
#define BackBump 11
//Sensors (Analog)
#define GYR 2
#define AutoPot 1
#define LineTracker 3
As you can see, at the top of the program gyro1 is declared as type Gyro, and GYR (later used) is defined under the Analog Sensors section of variables.
Below is the code from the init.c file:
void initialize() {
gyro1 = gyroInit(GYR, 0);
lcdInit(uart1);
lcdClear(uart1);
}
As you can see, gyro1 is defined as the initialization of GYR (port of gyroscope) and the default setting for the gyro, which is 0.
Below is the function used to turn the robot a certain degrees based on my asking:
void FuncRotateGyro(int speed, int GyroRequest) { //based on starting point; not added on
int Target = GyroRequest;
int pos = gyroGet(gyro1);
if(pos > Target) { //required to decrease (turn left)
while(pos > Target + 150 && pos < Target - 150) {
DriveRotateLeftSpeed(speed, speed, 0, 0); }
pos = gyroGet(gyro1);
while(pos > Target + 10 && pos < Target - 10) {
DriveRotateLeftSpeed(2*speed/3, 2*speed/3, 0, 0);
pos = gyroGet(gyro1); }
driveSet(0, 9);
}
if(gyroGet(gyro1) < Target) {
while(pos > Target + 150 && pos < Target - 150) {
DriveRotateRightSpeed(speed, speed, 0, 0);
pos = gyroGet(gyro1); }
while(pos > Target + 10 && pos > Target - 10) {
DriveRotateRightSpeed(2*speed/3, 2*speed/3, 0, 0);
pos = gyroGet(gyro1); }
driveSet(0, 0);
}
}
On top of that, I also made a program in simpler forms that uses a while loop and makes everything much simpler. I had no success.
On top of that, I made a test program with the same definitions of init.c and var.h except one minor tweak:
if(joystickGetDigital(1, 7, 4) == 1) {
while(1 == 1) {
int gyrogyro = gyroGet(gyro1);
printf("%d\n", gyrogyro);
}
}
The main issue with all of this is that the gyro returns a value of 0 or it remains to spin for ever and ever. If anyone could help me on this, please do. More information (if needed) will be given later on by request.