I have a very simple drive code for my cortex and whenever I try to build the opcontrol file, it reads “make: nothing to be done for ‘quick’”. When I try to upload the code, the cortex is unresponsive after connecting to the controller. I think it is a problem with the building process but I have attached the code in case there are issues in it. I am using C by the way.
#include “main.h”
#define LEFTDRIVE_PORT 2&3
#define RIGHTDRIVE_PORT 4&5
void opcontrol() {
while (true) {
int Joy2 = ((100*(joystickGetAnalog(1, 2)))/127) ; // percent power from joystick
int Joy3 = ((100*(joystickGetAnalog(1, 3)))/127) ; // percent power from joystick
int leftdrive = 0 ;
int rightdrive = 0 ;
int k = 0 ;
int rspeed = (((Joy2^3)/1000)/100) ; // takes percent and applies equation
int lspeed = (((Joy3^3)/1000)/100) ; // takes percent and applies equation
if (abs(Joy2) < k) {
rightdrive = 0 ;
}
else if (abs(Joy2) > k) {
rightdrive = 127*rspeed ;
}
else {
rightdrive = 0 ;
}
if (abs(Joy3) > k) {
leftdrive = 0 ;
}
else if (abs(Joy3) < k) {
leftdrive = 127*lspeed ;
}
else {
leftdrive = 0 ;
}
motorSet(RIGHTDRIVE_PORT, rightdrive) ;
motorSet(LEFTDRIVE_PORT, leftdrive) ;
delay(2);
}
}
I moved the delay 20 milliseconds inside the while loop but it still rendered no movement after uploading and connecting to the controller. Is the notation for naming the motor ports correct?
Well, lets see.
Documentation for motorSet is here
https://pros.cs.purdue.edu/cortex/api/index.html#motorset
void motorSet ( unsigned char channel, int speed )
and channel is defined as
channel - the motor channel to fetch from 1-10
and you have defined LEFTDRIVE_PORT in an unusual way
#define LEFTDRIVE_PORT 1&2
That means bitwise AND operator acting on one and two, which would be 0
so no, that won’t work.
you have to use motorSet for each motor individually.
1 Like
I also uploaded a very simple autonomous test to check for a response and there was no movement.
void autonomous() {
motorSet(2, 127) ;
motorSet(3, 127) ;
motorSet(4, -127) ;
motorSet(5, -127) ;
}
The motor port change did also not change the result of the program.
#include “main.h”
#define LEFTDRIVE_PORT1 2
#define LEFTDRIVE_PORT2 3
#define RIGHTDRIVE_PORT1 4
#define RIGHTDRIVE_PORT2 5
void opcontrol() {
while (true) {
int Joy2 = ((100*(joystickGetAnalog(1, 2)))/127) ; // percent power from joystick
int Joy3 = ((100*(joystickGetAnalog(1, 3)))/127) ; // percent power from joystick
int leftdrive = 0 ;
int rightdrive = 0 ;
int k = 0 ;
int rspeed = (((Joy2^3)/1000)/100) ; // takes percent and applies equation
int lspeed = (((Joy3^3)/1000)/100) ; // takes percent and applies equation
if (abs(Joy2) < k) {
rightdrive = 0 ;
}
else if (abs(Joy2) > k) {
rightdrive = 127*rspeed ;
}
else {
rightdrive = 0 ;
}
if (abs(Joy3) > k) {
leftdrive = 0 ;
}
else if (abs(Joy3) < k) {
leftdrive = 127*lspeed ;
}
else {
leftdrive = 0 ;
}
motorSet(RIGHTDRIVE_PORT1, rightdrive) ;
motorSet(RIGHTDRIVE_PORT2, rightdrive) ;
motorSet(LEFTDRIVE_PORT1, leftdrive) ;
motorSet(LEFTDRIVE_PORT2, leftdrive) ;
delay(2);
}
}
You’re still using ^ incorrectly, as it is bit-wise XOR. You might want to brush up on C++ operators. There is no operator for exponentiation. To boot, even if it was correct, 100 cubed divided by 100,000 is 10. You’re also doing an integer operation, so any result when later multiplied by 127 means you will either have 0 or 127+ going to the motors, giving you no control other than full speed or stationary.
Apologies, I had forgot to upload my most recent version of this code. I’m still having problems with control after uploading to the cortex.
#include “main.h”
void opcontrol() {
while (true) {
int Joy2 = ((100*(joystickGetAnalog(1, 2)))/127) ; // percent power from joystick as integer ; output range: [-100,100]
int Joy3 = ((100*(joystickGetAnalog(1, 3)))/127) ; // percent power from joystick as integer output range: [-100,100]
int leftdrive = 0 ;
int rightdrive = 0 ;
int k = 0 ; // dead zone value
float rspeed = (((powf(Joy2,3))/10000)/100) ; // takes percent and applies cubic equation ; output range: [-1,1]
float lspeed = (((powf(Joy3,3))/10000)/100) ; // takes percent and applies cubic equation ; output range: [-1,1]
if (abs(Joy2) < k) {
rightdrive = 0 ;
}
else if (abs(Joy2) > k) {
rightdrive = 127*rspeed ;
}
else {
rightdrive = 0 ;
}
if (abs(Joy3) < k) {
leftdrive = 0 ;
}
else if (abs(Joy3) > k) {
leftdrive = 127*lspeed ;
}
else {
leftdrive = 0 ;
}
motorSet(2, -rightdrive) ;
motorSet(2, -rightdrive) ;
motorSet(3, leftdrive) ;
motorSet(4, leftdrive) ;
delay(20);
}
}
The float to int conversion when assigning to rightdrive and leftdrive might be giving you problems. Given that you’re trying to produce a number between 0 and 1, it might be looking at int = int * float
and performing the cast before multiplication. You might see if doing int = (int)(float * float)
works (i.e., rightdrive = (int)(127.0 * rspeed);
).
Ok I think I may have fixed that problem although raising Joy2 and Joy3 to the 3rd power is still giving alerts by PROS. Is the notation for exponentiation correct?
#include “main.h”
void opcontrol() {
while (true) {
int Joy2 = ((100*(joystickGetAnalog(1, 2)))/127) ; // percent power from joystick as integer ; output range: [-100,100]
int Joy3 = ((100*(joystickGetAnalog(1, 3)))/127) ; // percent power from joystick as integer output range: [-100,100]
int leftdrive = 0 ;
int rightdrive = 0 ;
int k = 0 ; // dead zone value
float rspeed = (((powf(Joy2,3))/10000)/100) ; // takes percent and applies cubic equation ; output range: [-1,1]
float lspeed = (((powf(Joy3,3))/10000)/100) ; // takes percent and applies cubic equation ; output range: [-1,1]
if (abs(Joy2) < k) {
rightdrive = 0 ;
}
else if (abs(Joy2) > k) {
rightdrive = (int)(127.0 * rspeed) ;
}
else {
rightdrive = 0 ;
}
if (abs(Joy3) < k) {
leftdrive = 0 ;
}
else if (abs(Joy3) > k) {
leftdrive = (int)(127.0 * lspeed) ;
}
else {
leftdrive = 0 ;
}
motorSet(2, -rightdrive) ;
motorSet(2, -rightdrive) ;
motorSet(3, leftdrive) ;
motorSet(4, leftdrive) ;
delay(20);
}
}
I made a simpler drive code which also doesn’t seem to work and this makes me think that I am uploading the code incorrectly.
void operatorControl() {
while (1) {
motorSet(2, -joystickGetAnalog(1,2)) ;
motorSet(3, -joystickGetAnalog(1,2)) ;
motorSet(4, joystickGetAnalog(1,3)) ;
motorSet(5, joystickGetAnalog(1,3)) ;
}
}
Are you first compiling (Building), then uploading?
Remember that simply uploading will not upload any changes to your code unless you compile first.
When I build it says “make: Nothing to be done for ‘quick’” so I’m assuming the program was built? I don’t think its a wiring issue as the ROBOTC code seems to work just fine.
Only if you have not made any changes.
How the compile process works is that for performance reasons, it only compiles files that have changed, and caches the rest.
If you make a change to your code and save, does it still tell you “nothing to be done”?
Are you making changes to a header (h/hpp) file?
1 Like
When I make a change and then compile, it starts to compile and then it stops compiling so I assume that the build process occurred. There is no confirmation on if the compile process was successful so its a bit unclear
Ok so I think I may have compiled correctly because the joystick controls just started working.
Does it tell you any warnings?
Ok the simple dummy drive code was working but not the cubic drive. There may still be some issues as it gives me a warning about the power notation.
Lol, that is probably preventing you from compiling.
Don’t ignore any warnings, they are there for a reason.
Just use std::pow
, not sure if powf
is available without including some headers.
hehe I don’t know if that works because I’m in C not C++