Lol the funny thing is whenever i post a question here in a few minutes i figure out what i did wrong haha
... but anyways does this code look right?
#include "hardware.h"
// Initialise the hardware
void appInitHardware(void) {
initHardware();
}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
// -------- Start Switch/Button-------
// Switch/Button - see switch.h
// To test if it is pressed then
if(SWITCH_pressed(&button)){
// pressed
}
// To test if it is released then
if(SWITCH_released(&button)){
// released
}
// -------- End Switch/Button-------
// -------- Start Marquee-------
// Marquee - see 'segled.h'
// Before using the Marquee you need to redirect rprintf to write to it
// This can be done using
Writer old = rprintfInit(marqueeGetWriter(&marquee));
// All rprintf output will then be sent to the marquee but will not
// display until an end-of-line eg "\n" has been sent. Example:-
// rprintf("Hello World\n");
// If the endDelay is non-zero then the marquee will scroll
// forever or until you call: marqueeStop(&marquee);
// If the endDelay is zero then the marquee will stop once
// the entire line has been shown ('one-shot' mode)
// In 'one-shot' mode then you may want to make sure that
// a previous line has finished before you display a second line.
// This can be done as follows:-
marqueeSetEndDelay(&marquee,0); // Make sure we are in one-shot mode
if(marqueeIsActive(&marquee)==FALSE){
if(loopCount==1){
rprintf("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
}else{
rprintf("Loop=%u\n",(unsigned)loopCount); // Put the loop count
}
}
// Restore rprintf back to its previous location
rprintfInit(old);
// -------- End Marquee-------
// -------- Start Actuators -------
// To control your.motors/servos then see actuators.h in the manual
// To retrieve the required speed of wheel_left use:
// DRIVE_SPEED speed=act_getSpeed(wheel_left);
// To set the required speed of wheel_left use:
// act_setSpeed(wheel_left,speed);
// This example will move the motors back and forth using the loopStart time:
TICK_COUNT ms = loopStart / 1000; // Get current time in ms
int16_t now = ms % (TICK_COUNT)10000; // 10 sec for a full swing
if(now >= (int16_t)5000){ // Goes from 0ms...5000ms
now = (int16_t)10000 - now; // then 5000ms...0ms
}
// Map it into DRIVE_SPEED range
DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
// Set speed for all motors/servos
act_setSpeed(&wheel_left,speed);
act_setSpeed(&wheel_right,speed);
// -------- End Actuators -------
return 0;
}
/*
This file has been auto-generated by WebbotLib tools V1.1
** DO NOT MODIFY BY HAND **
*/
#ifndef _HARDWARE_H_
#define _HARDWARE_H_
#if !defined (_LIB_HARDWARE_C_) && !defined(_LIB_HARDWARE_CPP_)
#define BUILDING_LIBRARY
#define _LIB_HARDWARE_C_
#endif
#ifndef F_CPU
#warning No CPU speed specified - assuming running at 16000000
#define F_CPU 16000000
#endif
#if F_CPU != 16000000
# warning "Board runs at 16000000 but you have defined a different value"
#endif
#if defined (__AVR_ATmega640__)
#else
# error You must set the device to the ATmega640
#endif
#define FLASH_SIZE 65536
#define RAM_SIZE 8192
#define EEPROM_SIZE 4096
#define _NUM_PCINT_PINS 9
// Include library files
#include <libdefs.h>
#include <core.h>
#include <timer.h>
#include <a2d.h>
#include <rprintf.h>
#include <led.h>
#include <stdlib.h>
#include <avr/eeprom.h>
#include <switch.h>
#include <errors.h>
#include <uart.h>
#include <buffer.h>
#include <segled.h>
#include <servos.h>
#include "lib/lib_timerdef.h"
#include "lib/lib_iopins.h"
#ifdef __cplusplus
extern "C" {
#endif
// ------------------- uart1 -------------------
extern MAKE_WRITER(uart1SendByte);
extern MAKE_READER( uart1GetByte);
// Create hardware UART uart1
extern HW_UART _uart1;
#define uart1 &_uart1
#define UART1 uart1
// ------------------- Voice_Recognition -------------------
extern MAKE_WRITER(Voice_RecognitionSendByte);
extern MAKE_READER( Voice_RecognitionGetByte);
// Create hardware UART Voice_Recognition
extern HW_UART _Voice_Recognition;
#define Voice_Recognition &_Voice_Recognition
#define UART0 Voice_Recognition
// ----------- Define the ADC channels ----------
#define ADC0 ADC_NUMBER_TO_CHANNEL(0)
#define ADC1 ADC_NUMBER_TO_CHANNEL(1)
#define ADC2 ADC_NUMBER_TO_CHANNEL(2)
#define ADC3 ADC_NUMBER_TO_CHANNEL(3)
#define ADC4 ADC_NUMBER_TO_CHANNEL(4)
#define ADC5 ADC_NUMBER_TO_CHANNEL(5)
#define ADC6 ADC_NUMBER_TO_CHANNEL(6)
#define ADC7 ADC_NUMBER_TO_CHANNEL(7)
#define ADC8 ADC_NUMBER_TO_CHANNEL(
#define ADC9 ADC_NUMBER_TO_CHANNEL(9)
#define ADC10 ADC_NUMBER_TO_CHANNEL(10)
#define ADC11 ADC_NUMBER_TO_CHANNEL(11)
#define ADC12 ADC_NUMBER_TO_CHANNEL(12)
#define ADC13 ADC_NUMBER_TO_CHANNEL(13)
#define ADC14 ADC_NUMBER_TO_CHANNEL(14)
#define ADC15 ADC_NUMBER_TO_CHANNEL(15)
extern const uint8_t NUM_ADC_CHANNELS;
// ----------- My devices -----------------------
extern SWITCH button;
extern SEGLED led_display;
extern MARQUEE marquee;
extern SERVO wheel_left;
extern SERVO wheel_right;
extern SERVO_DRIVER bank1;
void initHardware(void);
#ifdef __cplusplus
}
#endif
#endif
// undefine all ports so the user cannot change them directly
#undef PORTA
#undef DDRA
#undef PINA
#undef PORTB
#undef DDRB
#undef PINB
#undef PORTC
#undef DDRC
#undef PINC
#undef PORTD
#undef DDRD
#undef PIND
#undef PORTE
#undef DDRE
#undef PINE
#undef PORTF
#undef DDRF
#undef PINF
#undef PORTG
#undef DDRG
#undef PING
#undef PORTH
#undef DDRH
#undef PINH
#undef PORTJ
#undef DDRJ
#undef PINJ
#undef PORTK
#undef DDRK
#undef PINK
#undef PORTL
#undef DDRL
#undef PINL
// Undefine timer registers to stop users changing them
#undef TCNT0
#undef TCCR0B
#undef OCR0A
#undef OCR0B
#undef TCNT1
#undef TCCR1B
#undef OCR1A
#undef OCR1B
#undef OCR1C
#undef TCNT2
#undef TCCR2B
#undef OCR2A
#undef OCR2B
#undef TCNT3
#undef TCCR3B
#undef OCR3A
#undef OCR3B
#undef OCR3C
#undef TCNT4
#undef TCCR4B
#undef OCR4A
#undef OCR4B
#undef OCR4C
#undef TCNT5
#undef TCCR5B
#undef OCR5A
#undef OCR5B
#undef OCR5C
//allows for printing with features, but uses more memory
#define RPRINTF_FLOAT
#define RPRINTF_COMPLEX
#include "hardware.h"
#include "VR_library.h" //voice recognition library
// Initialise the hardware
void appInitHardware(void) {
initHardware();
}
// Initialise the software
TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
servosDisconnect(&bank1);
delay_ms(1200);//Axon II bootup time
rprintf("\n\nAxon Initiated\n");
VR_Module_init();
return 0;
}
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
int8_t voice_command=-2;
//start voice recognition (note: it times out)
VR_Module_start_recognition(VR_group);//group B
while(voice_command == -2)
voice_command = VR_Module_get_result();
if(voice_command >= 0)
{
rprintf("\nvoice command is: ");
//turn on servos (I turn off to prevent noise interference)
act_setConnected(&wheel_left, TRUE);
act_setConnected(&wheel_right, TRUE);
delay_ms(30);
//swap languages - not used in this example, as both languages are set to do the same
/*if(VR_group==1 && voice_command==0)
{
rprintf(" ENGLISH");
VR_group=2;
}
else if(VR_group==2 && voice_command==0)
{
rprintf(" THAI");
VR_group=1;
}*/
VR_group=1;//use above code instead of this, if you want to swap languages
//other commands
if(voice_command==0)
{
act_setSpeed(&wheel_left,DRIVE_SPEED_MAX);
act_setSpeed(&wheel_right,DRIVE_SPEED_MIN);
rprintf(" LEFT");
delay_ms(700);
}
else if(voice_command==1)
{
act_setSpeed(&wheel_left,DRIVE_SPEED_MIN);
act_setSpeed(&wheel_right,DRIVE_SPEED_MAX);
rprintf(" RIGHT");
delay_ms(700);
}
else if(voice_command==2)
{
act_setSpeed(&wheel_left,DRIVE_SPEED_MAX);
act_setSpeed(&wheel_right,DRIVE_SPEED_MAX);
rprintf(" FORWARD");
delay_ms(1500);
}
else if(voice_command==3)
{
act_setSpeed(&wheel_left,0);
act_setSpeed(&wheel_right,0);
rprintf(" STOP");
delay_ms(50);
}
else if(voice_command==4)
{
act_setSpeed(&wheel_left,DRIVE_SPEED_MIN);
act_setSpeed(&wheel_right,DRIVE_SPEED_MIN);
rprintf(" REVERSE");
delay_ms(1000);
}
else if(voice_command==5)
{
rprintf(" DANCE");
//forward
act_setSpeed(&wheel_left,DRIVE_SPEED_MAX);
act_setSpeed(&wheel_right,DRIVE_SPEED_MAX);
delay_ms(800);
//reverse
act_setSpeed(&wheel_left,DRIVE_SPEED_MAX);
act_setSpeed(&wheel_right,DRIVE_SPEED_MAX);
delay_ms(800);
//spin right
act_setSpeed(&wheel_left,DRIVE_SPEED_MIN);
act_setSpeed(&wheel_right,DRIVE_SPEED_MAX);
delay_ms(1200);
//spin left
act_setSpeed(&wheel_left,DRIVE_SPEED_MAX);
act_setSpeed(&wheel_right,DRIVE_SPEED_MIN);
delay_ms(1200);
}
else if(voice_command==6)
{
LED_off(&statusLED);
rprintf(" LED");
delay_ms(2000);
LED_on(&statusLED);
}
/*
else if(voice_command==5)
rprintf(" WAI PRA");
else if(voice_command==6)
rprintf(" WORSHIP");
else if(voice_command==7)
rprintf(" ARM");
else if(voice_command==8)
rprintf(" ATTACK");
else if(voice_command==9)
{
rprintf(" SHUTDOWN");
servosDisconnect(&bank1);
}
else if(voice_command==10)
{
rprintf(" POWER_UP");
servosConnect(&bank1);
}
else if(voice_command==12)
{
act_setSpeed(&elbow,80);
rprintf(" UP");
}
else if(voice_command==13)
{
act_setSpeed(&elbow,-80);
rprintf(" DOWN");
}
else if(voice_command==14)
{
act_setSpeed(&gripper,-50);
rprintf(" GRAB");
}
else if(voice_command==15)
{
act_setSpeed(&gripper,50);
rprintf(" RELEASE");
}
*/
//stop further motion and turn off servos
act_setSpeed(&wheel_left,0);
act_setSpeed(&wheel_right,0);
act_setConnected(&wheel_left, FALSE);
act_setConnected(&wheel_right, FALSE);
}
rprintf("\n");
delay_ms(100);
return 0;
}
/*
Group 1:
0 PASA_THAI
1 LEFT
2 RIGHT
3 FORWARD
4 DANCE
5 WAI PRA
6 WORSHIP
7 ARM
8 ATTACK
9 SHUTDOWN
10 POWER_UP
11 LED
12 UP
13 DOWN
14 GRAB
15 RELEASE
Group 2:
0 PASA_ANGRIT
1 LEO_SAI
2 LEO_KWA
3 DTRONG_BAI
4 DTEN LOY
5 WAI PRA
6 KOWROP BUUCHAA
7 KAEN
8 HAA REUNG
9 BID FAI
10 BERD FAI
11 LED
12 KEUN
13 LONG
14 JAB MAN
15 BLOY MAN
*/
------ Rebuild All started: Project: VOICE-REC-ROBOT-5, Configuration: Debug AVR ------
Build started.
Project "VOICE-REC-ROBOT-5.cppproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Program Files (x86)\Atmel\AVR Studio 5.1\Vs\Compiler.targets" from project "C:\Users\bhat family\Documents\MY_ROBOT\VOICE-REC-ROBOT-5\VOICE-REC-ROBOT-5\VOICE-REC-ROBOT-5.cppproj" (target "ReBuild" depends on it):
Task "RunCompilerTask"
C:\Program Files (x86)\Atmel\AVR Studio 5.1\make\make.exe clean all
rm -rf VOICE-REC-ROBOT-5.o VOICE-REC-ROBOT-5.d
rm -rf "VOICE-REC-ROBOT-5.hex" "VOICE-REC-ROBOT-5.lss" "VOICE-REC-ROBOT-5.eep" "VOICE-REC-ROBOT-5.map"
VOICE-REC-ROBOT-5.cpp
Invoking: AVR8/GNU C++ Compiler
"C:\Program Files (x86)\Atmel\AVR Studio 5.1\extensions\Atmel\AVRGCC\3.3.1.27\AVRToolchain\bin\avr-g++.exe" -funsigned-char -funsigned-bitfields -O1 -fpack-struct -fshort-enums -g2 -Wall -c -MD -MP -MF "VOICE-REC-ROBOT-5.d" -MT"VOICE-REC-ROBOT-5.d" -mmcu=atmega640 -o"VOICE-REC-ROBOT-5.o" ".././VOICE-REC-ROBOT-5.cpp"
Finished building: .././VOICE-REC-ROBOT-5.cpp
Building target: VOICE-REC-ROBOT-5.elf
Invoking: AVR8/GNU C++ Linker
"C:\Program Files (x86)\Atmel\AVR Studio 5.1\extensions\Atmel\AVRGCC\3.3.1.27\AVRToolchain\bin\avr-g++.exe" -o VOICE-REC-ROBOT-5.elf VOICE-REC-ROBOT-5.o -Wl,-Map="VOICE-REC-ROBOT-5.map" -Wl,-lm -mmcu=atmega640
Finished building target: VOICE-REC-ROBOT-5.elf
"C:\Program Files (x86)\Atmel\AVR Studio 5.1\extensions\Atmel\AVRGCC\3.3.1.27\AVRToolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "VOICE-REC-ROBOT-5.elf" "VOICE-REC-ROBOT-5.hex"
"C:\Program Files (x86)\Atmel\AVR Studio 5.1\extensions\Atmel\AVRGCC\3.3.1.27\AVRToolchain\bin\avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "VOICE-REC-ROBOT-5.elf" "VOICE-REC-ROBOT-5.eep" || exit 0
"C:\Program Files (x86)\Atmel\AVR Studio 5.1\extensions\Atmel\AVRGCC\3.3.1.27\AVRToolchain\bin\avr-objdump.exe" -h -S "VOICE-REC-ROBOT-5.elf" > "VOICE-REC-ROBOT-5.lss"
"C:\Program Files (x86)\Atmel\AVR Studio 5.1\extensions\Atmel\AVRGCC\3.3.1.27\AVRToolchain\bin\avr-size.exe" -C --mcu=atmega640 "VOICE-REC-ROBOT-5.elf"
AVR Memory Usage
----------------
Device: atmega640
Program: 258 bytes (0.4% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
Done executing task "RunCompilerTask".
Done building target "CoreRebuild" in project "VOICE-REC-ROBOT-5.cppproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "ReBuild" in file "C:\Program Files (x86)\Atmel\AVR Studio 5.1\Vs\Avr.common.targets" from project "C:\Users\bhat family\Documents\MY_ROBOT\VOICE-REC-ROBOT-5\VOICE-REC-ROBOT-5\VOICE-REC-ROBOT-5.cppproj" (entry point):
Done building target "ReBuild" in project "VOICE-REC-ROBOT-5.cppproj".
Done building project "VOICE-REC-ROBOT-5.cppproj".
Build succeeded.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========