Projekte
workwind
NIBO2 - Terminal
main.c
Projekte
Forum
Doku
Öffentliche Projekte
Startseite
Beispielprogramme
Projekte von anderen
Welcome
Username
Passwort
Eingeloggt bleiben
Zugangsdaten vergessen?
Registrieren
Projektverwaltung
⇨ Please choose! ⇦
——————————————————
✎ Create new project...
★ Browse existing projects...
——————————————————
⚬ MotorTest#1
⚬ C Tutorial 8#1
⚬ NIBO2 C Project#1
⚙ C Tutorial 15#1
⚬ 2010_11_18_el_test001#1
NIBO2 - Terminal
main.c
niboprot.c
niboprot.h
niboprot_reg.h
Project details
Compiler settings
Nachrichten
Sie sind nicht eingeloggt.
Neuigkeiten
★
NiboRoboLib 3.6
2017-01-17: Neue Version 3.6
★
NiboRoboLib 3.4.1
2016-04-16: Neue Version 3.4.1
★
Coding Tutorial
2015-11-22: Jetzt auch für den NIBO burger!
Site-Statistic
7426 private projects
385 public projects
16180353 lines compiled
58212 builds
NIBO
@
nibo2_terminal/main.c [read only]
/* BSD-License: Copyright (c) 2013 by Nils Springob, nicai-systems, Germany All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name nicai-systems nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define NIBO_USE_UART0 #include <avr/interrupt.h> #include <avr/pgmspace.h> #include "nibo/niboconfig.h" #include "nibo/iodefs.h" #include "nibo/uart0.h" #include "nibo/leds.h" #include "nibo/pwm.h" #include "nibo/bot.h" #include "nibo/copro.h" #include "nibo/spi.h" #include "nibo/floor.h" #include "niboprot.h" static char buffer[256]; static uint16_t pos; static uint16_t len; static uint8_t mode; static uint8_t echo; #define READ_REG(x) nsp_register_flags[x]&(NSP_FLAG_REQUESTED|NSP_FLAG_REPORTED) #define WRITE_REG(x) nsp_register_flags[x]&NSP_FLAG_MODIFIED_REMOTE void update() { bot_update(); copro_update(); floor_update(); if (READ_REG(NSPREG_BOTID)) { nsp_registers[NSPREG_BOTID] = 0x4e32; // N2 NIBO 2 //nsp_registers[NSPREG_BOTID] = 0x4e62; // Nb NIBObee } if (READ_REG(NSPREG_VERSION)) { nsp_registers[NSPREG_VERSION] = 2; } if (READ_REG(NSPREG_VSUPPLY)) { uint32_t supply = bot_supply; supply *= 166; supply /= 10; supply -= 1190; nsp_registers[NSPREG_VSUPPLY] = supply; // [mV] } if (WRITE_REG(NSPREG_LEDSR)) { IO_LEDS_RED_PORT = nsp_registers[NSPREG_LEDSR]; } if (WRITE_REG(NSPREG_LEDSG)) { IO_LEDS_GREEN_PORT = nsp_registers[NSPREG_LEDSG]; } if (WRITE_REG(NSPREG_LEDSWPWM)) { leds_set_headlights (nsp_registers[NSPREG_LEDSWPWM]); } if (WRITE_REG(NSPREG_MOTPWML) || WRITE_REG(NSPREG_MOTPWMR) || WRITE_REG(NSPREG_MOTPIDL) || WRITE_REG(NSPREG_MOTPIDR) || WRITE_REG(NSPREG_MOTMODE) ) { switch (nsp_registers[NSPREG_MOTMODE]) { case 0: copro_stopImmediate(); break; case 1: copro_stop(); break; case 2: copro_setPWM (nsp_registers[NSPREG_MOTPWML], nsp_registers[NSPREG_MOTPWMR]); case 3: copro_setSpeed (nsp_registers[NSPREG_MOTPIDL], nsp_registers[NSPREG_MOTPIDR]); } } if (READ_REG(NSPREG_MOTCURL)) { nsp_registers[NSPREG_MOTCURL] = copro_current_l; } if (READ_REG(NSPREG_MOTCURR)) { nsp_registers[NSPREG_MOTCURR] = copro_current_r; } if (READ_REG(NSPREG_ODOL)) { nsp_registers[NSPREG_ODOL] = copro_ticks_l; } if (READ_REG(NSPREG_ODOR)) { nsp_registers[NSPREG_ODOR] = copro_ticks_r; } if (READ_REG(NSPREG_FLOORL)) { nsp_registers[NSPREG_FLOORL] = floor_relative[FLOOR_LEFT]; } if (READ_REG(NSPREG_FLOORR)) { nsp_registers[NSPREG_FLOORR] = floor_relative[FLOOR_RIGHT]; } if (READ_REG(NSPREG_LINEL)) { nsp_registers[NSPREG_LINEL] = floor_relative[LINE_LEFT]; } if (READ_REG(NSPREG_LINER)) { nsp_registers[NSPREG_LINER] = floor_relative[LINE_RIGHT]; } if (READ_REG(NSPREG_DIST_L)) { nsp_registers[NSPREG_DIST_L] = copro_distance[0]; } if (READ_REG(NSPREG_DIST_FL)) { nsp_registers[NSPREG_DIST_FL] = copro_distance[1]; } if (READ_REG(NSPREG_DIST_F)) { nsp_registers[NSPREG_DIST_F] = copro_distance[2]; } if (READ_REG(NSPREG_DIST_FR)) { nsp_registers[NSPREG_DIST_FR] = copro_distance[3]; } if (READ_REG(NSPREG_DIST_R)) { nsp_registers[NSPREG_DIST_R] = copro_distance[4]; } } static void send_help() { PGM_P text = PSTR(NSP_HELP_TEXT NSP_REGISTER_TEXT); char c=1; while (c) { if (!uart0_txfull()) { c=pgm_read_byte(text++); uart0_putchar(c); } } } int main(int argc, char * argv[]) { sei(); // enable interrupts bot_init(); spi_init(); pwm_init(); leds_init(); floor_init(); uart0_set_baudrate(9600); uart0_enable(); mode = 1; uart0_putchar('N'); uart0_putchar('I'); pos=0; uart0_putchar('B'); uart0_putchar('O'); copro_ir_startMeasure(); uart0_putchar('2'); uart0_putchar('\r'); uart0_putchar('\n'); while (1) { if (mode==1) { if (!uart0_rxempty()) { char c = uart0_getchar(); if (pos==0) { echo = (c!='$'); } if (echo) { uart0_putchar(c); } if (c!='\r') { buffer[pos++] = c; } if (c=='\n') { nsp_request(buffer, pos-1); update(); if (nsp_show_help()) { send_help(); } len = nsp_reply(buffer, sizeof(buffer)); pos = 0; mode = 2; } } } if (mode==2) { if (pos<len) { if (!uart0_txfull()) { uart0_putchar(buffer[pos++]); } } else { pos = 0; len = 0; mode = 1; } } } return 0; }
Compiler results:
Werbung
Online
manuelcambage9640
margiehake51716
renatocasey6977
simapartin211854249