/* * libkhepctrl : A library to control Khepera II robots * Copyright (C) 2007 Guillaume Libersat * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ #include #include "raw.h" #include "twoway_cmds.h" /******** * * Here are all commands that reply something. * They are sorted by Native Comand Character. * ********/ /** * E : Read speed of motors */ khep_cmd_ret_t khep_cmd_read_speed(khep_hand_t hand) { khep_rawcmd_ret_t raw; khep_cmd_ret_t res; raw = khep_cmd_raw(hand, "E"); res.result = raw.result; if ( raw.result == KHEP_CMD_OK ) { res.data.motor[KHEP_MOT_L] = atoi(raw.args[1]); res.data.motor[KHEP_MOT_R] = atoi(raw.args[2]); khep_free_answer(&raw); } return res; } /** * H : Read position of motors */ khep_cmd_ret_t khep_cmd_read_position(khep_hand_t hand) { khep_rawcmd_ret_t raw; khep_cmd_ret_t res; raw = khep_cmd_raw(hand, "H"); res.result = raw.result; if ( raw.result == KHEP_CMD_OK ) { res.data.motor[KHEP_MOT_L] = atoi(raw.args[1]); res.data.motor[KHEP_MOT_R] = atoi(raw.args[2]); khep_free_answer(&raw); } return res; } /** * N : Read proximity sensors */ khep_cmd_ret_t khep_cmd_proximity_sensors(khep_hand_t hand) { khep_rawcmd_ret_t raw; khep_cmd_ret_t res; raw = khep_cmd_raw(hand, "N"); res.result = raw.result; if ( raw.result == KHEP_CMD_OK ) { res.data.sensor[KHEP_SENS_LEFT90] = atoi(raw.args[1]); res.data.sensor[KHEP_SENS_LEFT45] = atoi(raw.args[2]); res.data.sensor[KHEP_SENS_LEFT10] = atoi(raw.args[3]); res.data.sensor[KHEP_SENS_RIGHT10] = atoi(raw.args[4]); res.data.sensor[KHEP_SENS_RIGHT45] = atoi(raw.args[5]); res.data.sensor[KHEP_SENS_RIGHT90] = atoi(raw.args[6]); res.data.sensor[KHEP_SENS_BACKR] = atoi(raw.args[7]); res.data.sensor[KHEP_SENS_BACKL] = atoi(raw.args[8]); khep_free_answer(&raw); } return res; } /** * O : Read ambient light sensors */ khep_cmd_ret_t khep_cmd_ambient_sensors(khep_hand_t hand) { khep_rawcmd_ret_t raw; khep_cmd_ret_t res; raw = khep_cmd_raw(hand, "O"); res.result = raw.result; if ( raw.result == KHEP_CMD_OK ) { res.data.sensor[KHEP_SENS_LEFT90] = atoi(raw.args[1]); res.data.sensor[KHEP_SENS_LEFT45] = atoi(raw.args[2]); res.data.sensor[KHEP_SENS_LEFT10] = atoi(raw.args[3]); res.data.sensor[KHEP_SENS_RIGHT10] = atoi(raw.args[4]); res.data.sensor[KHEP_SENS_RIGHT45] = atoi(raw.args[5]); res.data.sensor[KHEP_SENS_RIGHT90] = atoi(raw.args[6]); res.data.sensor[KHEP_SENS_BACKR] = atoi(raw.args[7]); res.data.sensor[KHEP_SENS_BACKL] = atoi(raw.args[8]); khep_free_answer(&raw); } return res; }