/* * functions.h * This file is part of the project "Remote control for CPG-based robots" * * Copyright (C) 2010 - Gabriel CUENDET */ #ifndef FUNCTIONS_H #define FUNCTIONS_H typedef enum{STARTED, IN_CHARGE, STOPPED, MENU, RC_AUTONOMOUS, ERROR=9} state; typedef enum{WALKING, SWIMMING} locomotion_mode; typedef enum{AMPHIBOT2=1, SALAMANDRA1, AMPHIBOT3PIC, SALAMANDRA2, AMPHIBOT3ARM} robot; /** * Definition of the menus **/ typedef enum {INFOS_RC_MAIN=0, SELECT_ROBOT_MAIN, ROBOT_MAIN} main_menu; typedef enum {NO_SUB=0, BATT_VOLTAGE_SUB=1, VERSION_RADIO_SUB, RESET_RADIO_SUB, RESET_SUB, FAVORITES_SUB=1, ENTER_CHANNEL_SUB, SCAN_CHANNELS_SUB, START_SUB=1, STOP_SUB, START_CHARGING_SUB, STOP_CHARGING_SUB} sub_menu; typedef void (*tab_fct)(void); /***************************** * REMOTE CONTROL PARAMETERS * *****************************/ #define LCDADDR 0x76 #define BATADDR 0x68 #define BTN_ENTER PIN_B0 #define BTN_CANCEL PIN_B1 #define BTN_PLUS PIN_B4 #define BTN_MINUS PIN_B5 #define REG_INTF_VER 0x3C0 //< Radio interface's version #define REG_INTF_CH 0x3C1 //< Local (radio interface) channel number /******************************** * UNIVERSAL ROBOT'S REGISTERS * ********************************/ /// Definitions of the registers for the robot #define REG_RWL_VER 0x3E0 //< Remote radio firmware's version #define REG_RWL_CH 0x3E1 /*< Remote channel number (= REG_INTF_CH, if the communication is set) */ /********************** * ROBOT'S REGISTERS * **********************/ #define REGB_MODE 0 #define REGB_ELCOUNT 8 #define REGB_VER 26 #define REGB_FREQ 1 #define REGB_FREQ_B 1 #define REGB_FREQ_L 5 #define REGB_AMPL 3 #define REGB_AMPL_B 3 #define REGB_AMPL_L 6 #define REGB_TURN 2 #define REGB_PHASE 4 #define REGB_LED 7 #define REGMB_GAINS 0 /******************** * SALAMANDRA MODES * ********************/ #define MODE_IDLE 0 #define MODE_INIT 1 #define MODE_RUN 2 #define MODE_STOP 3 #define MODE_BATTERY_CHARGE 4 #define MODE_RUN_NO_DRIVE 5 #define MODE_RUN_IR_FOLLOW 6 /************************ * REGISTERS OPERATIONS * ************************/ // Generic register operations function int1 reg_op(int8 op, int16 addr, int8 *data, int len); // Getter for the registers int1 get_reg_b(int16 addr, int8* result); int1 get_reg_w(int16 addr, int8* result); int1 get_reg_dw(int16 addr, int8* result); int1 get_reg_mb(int16 addr, int8 &len, int8* result); // Setter for the register int1 set_reg_b(int16 addr, int8 data); int1 set_reg_w(int16 addr, int16 data); int1 set_reg_dw(int16 addr, int32 data); int1 set_reg_mb(int16 addr, int8 *data, int8 len); /************************ * MISC * ************************/ // Synchronization function int1 sync(); // Channel scan function int1 scan(int8* local_channel); void err(char* description); /******************** * ROBOT LOCOMOTION * ********************/ // Locomotion parameters //void set_freq_b(float freq); //void set_freq_l(float freq); //void set_ampl_b(float ampl); //void set_ampl_l(float ampl); int8 from_turn(float d); //void set_turn(float turn_front, float turn_rear); //void set_flat_gains(int8 cnt, double gain); void set_phase(float phase); int1 set_flat_gains(float gain); // Start-stop robot int1 start_salamander(); int1 start_amphibot(); int1 start_amphibot_mathieu(); int1 stop_salamander(); int1 stop_amphibot(); int1 stop_amphibot_mathieu(); // Direction and speed //void walk(unsigned int8 spd); // update functions for the different robots int1 update_salamander(float spd, float dir); int1 update_amphibot(float spd, float dir); int1 update_amphibot_mathieu(float spd, float dir); /********************* * DISPLAY FUNCTIONS * *********************/ // Initialization of the display void init_display(); void set_pos_display(int8 pos); void clear_display(); void display(char* str,int8 pos); void char_display(char* character,int8 pos); /********************** * BATTERY MANAGEMENT * **********************/ float battery_voltage(); float battery_temp(); float battery_current(); float battery_accumulated_current(); /****************** * USER INTERFACE * ******************/ int1 enter_value(char* label, int8* value); void display_menus(); // Ask the user for a confirmation (ENTER) or a cancellation (CANCEL) int1 enter_cancel(int8 delay); void press_button(char button); /******************* * MENU FONCTIONS * *******************/ // Functions to fill the menu table. Must be : // void function(void); void show_version_radio(); void show_batt_voltage(); void reset_radio(); void reset_main(); void menu_favorites(); void menu_enter_channel(); void menu_scan_channels(); void menu_start_robot(); void menu_stop_robot(); void menu_start_charging(); void menu_stop_charging(); #endif