Author Topic: matlab & electronic circuit whit server & important people in mechanics  (Read 2130 times)

0 Members and 1 Guest are viewing this topic.

Offline yyyTopic starter

  • Jr. Member
  • **
  • Posts: 45
  • Helpful? 0
Hallow friends
I have some question that I will glad to receives answers
1. i want to do a device that recognize the toe in the hand with matlab
And when it recognize the toe a motor turn three quarters rotation to open the door
I have some problems
a.How I can transfer the order from the matlab to the electronic circuit
(I know to transfer orders in C to the electronic circuit with burning but how I can do this with matlab)
b. I search after ideas that used print finger recognizer and control motor
(other ideas in addition to open door)
c. in with motor (AC, DC, STEPPER…) and with control (PID, pic…) it recommended to do the   three quarters rotation to open the door

2.  also I want to do a device with motor control that receive orders from the internet
With program sockets in C
a.I don't know how to build the electronic circuit for this I assume that this electronic circuit   have a server and other electrical component
b. I search after ideas that use one motor that do something and receive order from the internet

 I search after sites or books that can help me in this problems

3. I search after information of who to work with wire up board
And information (sites or books) that talk about the important people in mechanics like Archimedes, Galileo galilei, newton … (if you have more names of important people in mechanics I will glad to know)

thanks

Offline Half Shell

  • Robot Overlord
  • ****
  • Posts: 225
  • Helpful? 0
Re: matlab & electronic circuit whit server & important people in mechanics
« Reply #1 on: September 10, 2009, 01:58:23 PM »
Your english is very broken, so there are a lot of parts I don't understand. The good news, though, is that I have done extensive work with MATLAB controlling micro controllers, and in turn, electronic circuits. I've also made two robots communicate via WiFi before, though I used a local area network. The concept is still similar to go from a LAN to an internet capable robot.

So let's start from the top.

Your problem I)

In order to have MATLAB control an electronic circuit, you are going to need a micro controller (I recommend the Atmel AVR series, but if you are really new to electronics, Arduino or Axon can be far quicker, easier to approach solutions based on that chipset). We are going to use MATLAB's serial commands to open up communication, and build a simple communication program. I'll walk you through that, and then you can go from there, programming whatever communication protocol your application needs.

The code I am posting is some very rough, quickly made code as a proof of concept for you. Not my usual neat coding standards, but it should teach you the basics. The code is written for an AVR ATMEGA644p, and can easily be converted to many other Atmega chips.

The MATLAB code, response.m:

Code: [Select]
function [ output ] = response( serialDevice, input )
%RESPONSE Summary of this function goes here
%   Detailed explanation goes here
    tmp = fwrite(serialDevice, input);
    output = fread(serialDevice);

end

We will be using this code to request the value of a particular ADC value from the micro controller, read the response, and then return it. serialDevice must be declared already in the workspace. Run this command to create the appropiate serial device:

Code: [Select]
ser = serial('DEVICENAME','BaudRate',19200);

where DEVICENAME is /dev/ttyS1, or COM1, etc, depending on your OS and connection. I suggest 19200 as a nice, fast but still lots of error room connection speed between the AVR and MATLAB.

Be sure to run ser.open() BEFORE attempting to talk to it.

Then, compile and upload these files onto the micro controller:

main.c:
Code: [Select]
/*
 * main.c
 *
 *  Created on: Aug 24, 2009
 *      Author: Keith Chester
 */

#include "HardwareProfile.h"

int main(){

cli();
sei();

InitializeSerial();
InitializeA2D();

while(1){
}

return 0;
}

HardwareProfile.h
Code: [Select]
/*
 * HardwareProfile.h
 *
 *  Created on: Aug 24, 2009
 *      Author: Keith Chester
 */

#ifndef HARDWAREPROFILE_H_
#define HARDWAREPROFILE_H_

// Includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdlib.h>

#include "FunctionalHeader.h"

//System defines
#define BAUDRATE 19200
#define BAUD_CALC ((F_CPU/BAUDRATE/16)-1)

#endif /* HARDWAREPROFILE_H_ */

FunctionalHeader.h *Note: I usually have FunctionalHeader included in all, and hardware included in functional header so you can have multiple hardware profiles. This... was done backwards. I don't know why I did that.*
Code: [Select]
/*
 * FunctionalHeader.h
 *
 *  Created on: Aug 26, 2009
 *      Author: keith
 */

#ifndef FUNCTIONALHEADER_H_
#define FUNCTIONALHEADER_H_

//Serial Functions
void InitializeSerial(void);
void serialSendByte( unsigned char output );
void serialSendUInt( unsigned int output);


//ADC Functions
void InitializeA2D();
unsigned int getADC(unsigned char adc_channel);

#endif /* FUNCTIONALHEADER_H_ */

ADC.c
Code: [Select]
/** \brief Reads the analog to digital convertor for the requested channel.
 *
 * \file ADC.c
 *
 * Initializes, maintains, and handles all ADC functions.
 *
 * \author [email protected]
 * \version 1
 */

#include "HardwareProfile.h"

/** \fn void InitializeA2D()
 * \brief Initialize the Analog to Digital Convertor.
 * \param void
 * \return void
 */
void InitializeA2D(){
ADCSRA &= ~(1 << ADATE);
    ADCSRA |= (1 << ADEN) | (1 << ADPS0 ) | (1 << ADPS1 );
ADCSRA &= ~(1 << ADPS2 );
}


/** \fn unsigned int getADC(unsigned char adc_channel)
 * \brief Accepts the adc channel desired to be read and returns the current voltage on that channel.
 * \param unsigned char adc_channel
 * \return unsigned int adc_high_byte * 256 + adc_low_byte
 */
unsigned int getADC(unsigned char adc_channel){
if(adc_channel > 6) return 0;
unsigned char adc_low_byte = 0, adc_high_byte = 0;
ADMUX = adc_channel;
ADCSRA |= (1 << ADSC);
while((ADCSRA & (1 << ADIF))  == 0){}; //Wait until the adc grab is complete
adc_low_byte = ADCL;
adc_high_byte = ADCH;
ADCSRA |= (1 << ADIF);

return (int) adc_high_byte * 256 + adc_low_byte; //Convert high and low bit to single value.
}

Serial.c
Code: [Select]
/*
 * Serial.c
 *
 *  Created on: Aug 24, 2009
 *      Author: Keith Chester
 */

#include "HardwareProfile.h"

/** \fn void InitializeSerial()
 * \brief Initializes the USART0.
 * \param void
 * \return void
 */
void InitializeSerial(void)
{
UBRR0H = (unsigned char)(BAUD_CALC>>8);//Set baud rate
UBRR0L = (unsigned char)BAUD_CALC;//Set baud rate
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0);
UCSR0C = (1<<USBS0)|(3<<UCSZ00);//Set frame format
}

/** \fn void serialSendByte( unsigned char output )
 * \brief Transmits an individual byte over serial.
 * \param unsigned char output
 * \return void
 */
void serialSendByte( unsigned char output )
{
while ( !( UCSR0A & (1<<UDRE0)) ){ }
UDR0 = output;//Sends data through buffer
}

/** \fn void serialSendUInt( unsigned int output )
 * \brief Transmits the low then high bit of a unsigned int.
 * \param unsigned int output
 * \return void
 */
void serialSendUInt( unsigned int output){
serialSendByte( output );
serialSendByte( output >> 8 );
}

/** \fn ISR(USART0_RX_vect)
 * \brief Handles serial receive interrupts.
 * \param void
 * \return void
 */
ISR(USART0_RX_vect){
char channel;
unsigned int valueRead;

channel = UDR0;
valueRead = getADC(channel);

serialSendUInt(valueRead);
}

If you need help with specific hardware control, such as motor or stepper control, this is available elsewhere on the site, or I can help more if asked.

~~~

Your Problem 2)

Much like we connected to the micro controller serially through MATLAB, so too must you connect to the micro controller if you're using the internet. I suggest python - it is incredibly easy to quickly develop your program, and has a module for both serial communication (pyserial) and a module is available that allows you to control your python program over the internet (who's name is escaping me, sorry, I never used it beyond a super simple proof of concept demo over a year ago).


~~~

Your problem 3)

I have no idea what you're asking for, sorry.

Offline yyyTopic starter

  • Jr. Member
  • **
  • Posts: 45
  • Helpful? 0
Re: matlab & electronic circuit whit server & important people in mechanics
« Reply #2 on: September 11, 2009, 07:16:00 AM »
Thanks half shell
I don't understand how to do the communication between Matlab and the electronic circuit
and I don't understand how to connect LAN internet to the robot
If you know about a book or chapter or specific site or electronic circuit sketch that explain this I will glad if you can wrote this in this chining

 


data_list