예제 #1
0
int gmx_wheel(int argc, char *argv[])
{
    const char       *desc[] = {
        "[THISMODULE] plots a helical wheel representation of your sequence.",
        "The input sequence is in the [REF].dat[ref] file where the first line contains",
        "the number of residues and each consecutive line contains a residue "
        "name."
    };
    gmx_output_env_t *oenv;
    static real       rot0  = 0;
    static gmx_bool   bNum  = TRUE;
    static char      *title = NULL;
    static int        r0    = 1;
    t_pargs           pa [] = {
        { "-r0",  FALSE, etINT, {&r0},
          "The first residue number in the sequence" },
        { "-rot0", FALSE, etREAL, {&rot0},
          "Rotate around an angle initially (90 degrees makes sense)" },
        { "-T",   FALSE, etSTR, {&title},
          "Plot a title in the center of the wheel (must be shorter than 10 characters, or it will overwrite the wheel)" },
        { "-nn",  FALSE, etBOOL, {&bNum},
          "Toggle numbers" }
    };
    t_filenm          fnm[] = {
        { efDAT, "-f", NULL,  ffREAD  },
        { efEPS, "-o", NULL,  ffWRITE }
    };
#define NFILE asize(fnm)

    int    i, nres;
    char **resnm;

    if (!parse_common_args(&argc, argv, 0, NFILE, fnm, asize(pa), pa,
                           asize(desc), desc, 0, NULL, &oenv))
    {
        return 0;
    }

    for (i = 1; (i < argc); i++)
    {
        if (std::strcmp(argv[i], "-r0") == 0)
        {
            r0 = std::strtol(argv[++i], NULL, 10);
            fprintf(stderr, "First residue is %d\n", r0);
        }
        else if (std::strcmp(argv[i], "-rot0") == 0)
        {
            rot0 = strtod(argv[++i], NULL);
            fprintf(stderr, "Initial rotation is %g\n", rot0);
        }
        else if (std::strcmp(argv[i], "-T") == 0)
        {
            title = gmx_strdup(argv[++i]);
            fprintf(stderr, "Title will be '%s'\n", title);
        }
        else if (std::strcmp(argv[i], "-nn") == 0)
        {
            bNum = FALSE;
            fprintf(stderr, "No residue numbers\n");
        }
        else
        {
            gmx_fatal(FARGS, "Incorrect usage of option %s", argv[i]);
        }
    }

    nres = get_lines(ftp2fn(efDAT, NFILE, fnm), &resnm);
    if (bNum)
    {
        wheel(ftp2fn(efEPS, NFILE, fnm), nres, resnm, r0, rot0, title);
    }
    else
    {
        wheel2(ftp2fn(efEPS, NFILE, fnm), nres, resnm, rot0, title);
    }

    return 0;
}
예제 #2
0
int main(){
	pwm_init();
	MSS_GPIO_init();
	range_init();
	MSS_GPIO_config(MSS_GPIO_31, MSS_GPIO_OUTPUT_MODE);
	UART_init(&g_uart, COREUARTAPB0_BASE_ADDR, 162, (DATA_8_BITS | NO_PARITY));

	uint8_t buff[BUFFER_SIZE];
	int offset = 0;
	size_t received;
	int joyx, joyy, cx, cy, start, fire;
	int startDown = 0;
	int mode = 0; // 0 for manual, 1 for automatic
	uint8_t tx[100];
	int txSize;
	firing = 0;
	curr_angle = 0;

	MSS_GPIO_set_output(MSS_GPIO_31, 0);

	/*while(1) {
		wheel2(255);
		//wheel4(255);
		//wheel2(-255);
		//wheel3(255);
		//wheel4(-255);
	}*/
	while (1) {
		while (!(received = UART_get_rx(&g_uart, buff+offset, sizeof(buff)-offset)));
		offset += received;
		//printf("Received: %d\n\r", received);
		if (buff[offset-1] == '\0') { // message fully received
			//printf("%s\n\r", buff);
			if (6 != sscanf(buff, "%d %d %d %d %d %d", &joyx, &joyy, &cx, &cy, &fire, &start)) {
				bzero(buff, BUFFER_SIZE);
				continue;
			}
			offset = 0;

			if (start && !startDown) {
				mode = !mode;
				startDown = 1;
			}
			if (!start && startDown)
				startDown = 0;

			joyx = joyx * .65;
			joyy = joyy * .65;

			if (joyx < 0)
				joyx -= 150;
			else if (joyx > 0)
				joyx += 150;
			if (joyy < 0)
				joyy -= 150;
			else if (joyy > 0)
				joyy += 150;

			printf("JoyX: %3d, JoyY: %3d, CX: %3d, CY: %3d, Fire: %d, Start: %d\n\r", joyx, joyy, cx, cy, fire, start);

			wheel1(joyy);
			wheel2(joyx);
			wheel3(joyy);
			wheel4(joyx);

			moveTurret(cy);

			if (fire && !firing) {
				start_gun();
			}

			if (firing && fire_counter <= FIRE_TIME)
				fire_counter++;
			if (!fire && firing && fire_counter >= FIRE_TIME)
				stop_gun();

		}
		else continue;
		txSize = sprintf(tx, "%d %d", mode, get_range()) + 1;
		UART_send(&g_uart, tx, txSize);
	}
	/*while(1){
		set_gun_angle(0);
		wheel1(-255);
    }*/
    return 0;
}