Coding for partner controller

  1. 7 months ago

    blatwell

    14 Jan 2018 Event Partner Indianapolis 621A

    @Chaotic Squirrel posted this in the official Q&A not realizing only certain people can answer so I thought I would re-post his question here. I am the mentor but know nothing about coding. I know he is using RobotC.

    Squirrel here! just wondering if anyone can help we (621C,B)have been trying to code for a partner controller and it is being really crappy but I believe we have a good start here is the code:

    task usercontrol()
    {
    while(true){
    if( (nVexRCReceiveState & vrXmit2) ) {
    motor[port5] = vexRT[Ch2Xmtr2];
    motor[port6] = vexRT[Ch2Xmtr2];
    if(vexRT[Btn6UXmtr2]){
    motor[port7] = 90;

    }

    else if(vexRT[Btn6DXmtr2]) {
    motor[port7] = -60;

    }

    else {

    motor[port7]=0;
    }
    }

    else {
    motor[port5] = vexRT[Ch2];
    motor[port6] = vexRT[Ch2];
    if(vexRT[Btn6U]){
    motor[port7] = 90;

    }

    else if(vexRT[Btn6D]) {
    motor[port7] = -60;

    }

    else {

    motor[port7]=0;
    }
    }

    motor[port2] = vexRT[Ch3] + vexRT[Ch4];
    motor[port3] = vexRT[Ch3] - vexRT[Ch4];
    motor[port9] = vexRT[Ch3] + vexRT[Ch4];
    motor[port8] = vexRT[Ch3] - vexRT[Ch4];
    // motor[port4] = vexRT[Ch2];
    if(vexRT[Btn5U]){
    motor[port4] = 90;

    }

    else if(vexRT[Btn5D] && SensorValue [mogoP]>1680){
    motor[port4] = -60;

    }

    else {

    motor[port4]=0;

    }

    }
    }

  2. Easton

    14 Jan 2018 GA, USA 1958A

    @Chaotic Squirrel if it's "being really crappy" could you specify what the issues are? I'm not a good programmer but if I know what to look for I can find basic issues sometimes

  3. blatwell

    14 Jan 2018 Event Partner Indianapolis 621A

    @Easton @Chaotic Squirrel if it's "being really crappy" could you specify what the issues are? I'm not a good programmer but if I know what to look for I can find basic issues sometimes

    LOL. He was not too descriptive. As I recall, he was wanting to be able to have one controller do everything unless the partner controller is plugged in and then he wanted the partner controller to control the claw and the chainbar. The chainbar is on ports 5 and 6 and the claw is port 7.

    He does not get to get online much at home so I thought I would stand in for him to get his question answered. I am not a programmer and am too old to learn. As the mentor, I basically heard cats.

  4. Easton

    14 Jan 2018 GA, USA 1958A

    @blatwell LOL. He was not too descriptive. As I recall, he was wanting to be able to have one controller do everything unless the partner controller is plugged in and then he wanted the partner controller to control the claw and the chainbar. The chainbar is on ports 5 and 6 and the claw is port 7.

    He does not get to get online much at home so I thought I would stand in for him to get his question answered. I am not a programmer and am too old to learn. As the mentor, I basically heard cats.

    Ok. Unfortunately I am not advanced enough to do stuff like this. Maybe @nenik can help?

  5. nenik

    14 Jan 2018 V5 Beta Tester

    The code looks OK to me, what kind of problem do you see? Also, it helps if the code is posted as a [ c o d e ] section, so it becomes more readable. I have reformatted it here for reference:

    task usercontrol() {
        while(true){
            if( (nVexRCReceiveState & vrXmit2) ) {
                motor[port5] = vexRT[Ch2Xmtr2];
                motor[port6] = vexRT[Ch2Xmtr2];
                if(vexRT[Btn6UXmtr2]){
                    motor[port7] = 90;
                } else if(vexRT[Btn6DXmtr2]) {
                    motor[port7] = -60;
                } else {
                    motor[port7]=0;
               }
            } else {
                motor[port5] = vexRT[Ch2];
                motor[port6] = vexRT[Ch2];
                if(vexRT[Btn6U]){
                    motor[port7] = 90;
                } else if(vexRT[Btn6D]) {
                    motor[port7] = -60;
                } else {
                    motor[port7]=0;
                }
            }
    
            motor[port2] = vexRT[Ch3] + vexRT[Ch4];
            motor[port3] = vexRT[Ch3] - vexRT[Ch4];
            motor[port9] = vexRT[Ch3] + vexRT[Ch4];
            motor[port8] = vexRT[Ch3] - vexRT[Ch4];
            // motor[port4] = vexRT[Ch2];
            if(vexRT[Btn5U]){
                motor[port4] = 90;
            } else if(vexRT[Btn5D] && SensorValue [mogoP]>1680){
                motor[port4] = -60;
            } else {
                motor[port4]=0;
            }
        }
    }

    As I said, the code as such looks good, though you may want to allow both the driver and the partner to operate those mechanisms, not exclusively hand it over to the partner.

  6. blatwell

    14 Jan 2018 Event Partner Indianapolis 621A

    As I recall, the issue was that when the partner controller was plugged in, the master/main controller controlled things and not the partner, but when the partner controller was not plugged in, nothing controlled the arm and intake (ports 5,6,7).

    I will try to find out if there was anything else. I am guessing it is something very simple.

    At one point, I think they had it where either could control it, but it made the arm very jittery. It was like it was going back and forth between what the two controllers were saying. One would have zero values and the other higher values and it was like it was going back and forth and a very high frequency.

  7. nenik

    15 Jan 2018 V5 Beta Tester

    The conditions, as they are written look fine for 2nd transmitter controlling ports 5, 6 & 7.
    You could also try adding some debugging code at the start (before the loop), such as:

    task usercontrol() {
        clearDebugStream()
        if (nVexRCReceiveState & vrXmit1) {
            writeDebugStreamLine("First controller detected");
        }
        if (nVexRCReceiveState & vrXmit2) {
            writeDebugStreamLine("Second controller detected");
        }
        while(true) {
    [...]

    As for both controlling it concurrently, yeah, you'd need to handle collisions and only set the motor control value once per loop iteration. Perhaps like:

            motor[port5] = vexRT[Ch2] + vexRT[Ch2Xmtr2];
            motor[port6] = vexRT[Ch2] + vexRT[Ch2Xmtr2];
            if(vexRT[Btn6U] || vexRT[Btn6UXmtr2]){
                motor[port7] = 90;
            } else if(vexRT[Btn6D] || vexRT[Btn6DXmtr2]) {
                motor[port7] = -60;
            } else {
                motor[port7]=0;
           }

    This is optimized for only one of the drivers touching relevant controls, but avoids conflicts and has reasonable conflict resolution - Up (open?) on claw has precedence over down (close?), chainbar allows countering the analog value or speeding up when working in agreement.

  8. blatwell

    15 Jan 2018 Event Partner Indianapolis 621A

    @nenik Thank you. I will have him try this tonight when we meet.

 

or Sign Up to reply!