bunte kästen und Namen

This commit is contained in:
Rene Hopf
2014-11-03 12:35:53 +01:00
parent cb3687e675
commit 54200d448f
10 changed files with 1712 additions and 1670 deletions
+438 -438
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -49,9 +49,9 @@ void pid_init(hal_pid_t *pid){
pid->cmd_d = 0; /* opt. pin: differentiated command */
pid->cmd_dd = 0; /* opt. pin: 2nd derivative of command */
pid->bias = 0; /* param: steady state offset */
pid->pgain = 2; /* pin: proportional gain */
pid->igain = 40; /* pin: integral gain */
pid->dgain = 0.02; /* pin: derivative gain */
pid->pgain = 4; /* pin: proportional gain */
pid->igain = 0.02; /* pin: integral gain */
pid->dgain = 0.01; /* pin: derivative gain */
pid->bgain = 0.0; /* pin: derivative gain */
// pid->ff0gain = 0; /* pin: feedforward proportional */
pid->ff1gain = 0.006; /* pin: feedforward derivative */
+276 -276
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+73 -73
View File
@@ -1,73 +1,73 @@
//--------------------------------------------------------------
// File : stm32_ub_encoder_tim3.h
//--------------------------------------------------------------
//--------------------------------------------------------------
#ifndef __STM32F4_UB_ENCODER_TIM3_H
#define __STM32F4_UB_ENCODER_TIM3_H
//--------------------------------------------------------------
// Includes
//--------------------------------------------------------------
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
//--------------------------------------------------------------
// Zwei Kanäle [0 und 1] werden für den Rotary-Encoder benötigt
//--------------------------------------------------------------
typedef enum
{
ENC_T3_A = 0, // Encoder Kanal-A
ENC_T3_B = 1 // Encoder Kanal-B
}ENC_TIM3_NAME_t;
//--------------------------------------------------------------
// Mode vom Encoder
//--------------------------------------------------------------
typedef enum {
ENC_T3_MODE_2A = 0, // Counter Zählt bei jeder Flanke von Eingang_A
ENC_T3_MODE_2B = 1, // Counter Zählt bei jeder Flanke von Eingang_B
ENC_T3_MODE_4AB = 2 // Counter Zählt bei jeder Flanke von Eingang_A UND Eingang_B
}ENC_TIM3_MODE_t;
//--------------------------------------------------------------
// Richtung vom Encoder
//--------------------------------------------------------------
typedef enum {
ENC_T3_TYP_NORMAL = 0, // Counter incrementiert bei rechts
ENC_T3_TYP_REVERS = 1 // Counter decrementiert bei rechts
}ENC_TIM3_TYP_t;
//--------------------------------------------------------------
// Struktur von einem Encoder-Kanal
//--------------------------------------------------------------
typedef struct {
ENC_TIM3_NAME_t ENC_NAME; // Name
const uint8_t CHANNEL; // Channel [1...2]
GPIO_TypeDef* ENC_PORT; // Port
const uint16_t ENC_PIN; // Pin
const uint32_t ENC_CLK; // Clock
const uint8_t ENC_SOURCE; // Source
}ENC_TIM3_t;
//--------------------------------------------------------------
// Globale Funktionen
//--------------------------------------------------------------
void UB_ENCODER_TIM3_Init(ENC_TIM3_MODE_t mode, ENC_TIM3_TYP_t typ, uint16_t maxwert);
uint16_t UB_ENCODER_TIM3_ReadPos(void);
//--------------------------------------------------------------
#endif // __STM32F4_UB_ENCODER_TIM3_H
//--------------------------------------------------------------
// File : stm32_ub_encoder_tim3.h
//--------------------------------------------------------------
//--------------------------------------------------------------
#ifndef __STM32F4_UB_ENCODER_TIM3_H
#define __STM32F4_UB_ENCODER_TIM3_H
//--------------------------------------------------------------
// Includes
//--------------------------------------------------------------
#include "stm32f4xx.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
//--------------------------------------------------------------
// Zwei Kanäle [0 und 1] werden für den Rotary-Encoder benötigt
//--------------------------------------------------------------
typedef enum
{
ENC_T3_A = 0, // Encoder Kanal-A
ENC_T3_B = 1 // Encoder Kanal-B
}ENC_TIM3_NAME_t;
//--------------------------------------------------------------
// Mode vom Encoder
//--------------------------------------------------------------
typedef enum {
ENC_T3_MODE_2A = 0, // Counter Zählt bei jeder Flanke von Eingang_A
ENC_T3_MODE_2B = 1, // Counter Zählt bei jeder Flanke von Eingang_B
ENC_T3_MODE_4AB = 2 // Counter Zählt bei jeder Flanke von Eingang_A UND Eingang_B
}ENC_TIM3_MODE_t;
//--------------------------------------------------------------
// Richtung vom Encoder
//--------------------------------------------------------------
typedef enum {
ENC_T3_TYP_NORMAL = 0, // Counter incrementiert bei rechts
ENC_T3_TYP_REVERS = 1 // Counter decrementiert bei rechts
}ENC_TIM3_TYP_t;
//--------------------------------------------------------------
// Struktur von einem Encoder-Kanal
//--------------------------------------------------------------
typedef struct {
ENC_TIM3_NAME_t ENC_NAME; // Name
const uint8_t CHANNEL; // Channel [1...2]
GPIO_TypeDef* ENC_PORT; // Port
const uint16_t ENC_PIN; // Pin
const uint32_t ENC_CLK; // Clock
const uint8_t ENC_SOURCE; // Source
}ENC_TIM3_t;
//--------------------------------------------------------------
// Globale Funktionen
//--------------------------------------------------------------
void UB_ENCODER_TIM3_Init(ENC_TIM3_MODE_t mode, ENC_TIM3_TYP_t typ, uint16_t maxwert);
uint16_t UB_ENCODER_TIM3_ReadPos(void);
//--------------------------------------------------------------
#endif // __STM32F4_UB_ENCODER_TIM3_H
+167 -167
View File
File diff suppressed because it is too large Load Diff
+546 -546
View File
File diff suppressed because it is too large Load Diff
+16 -5
View File
@@ -1,11 +1,14 @@
#include "basicdrawpane.hpp"
const wxPen BasicDrawPane::pen[] = {*wxRED_PEN, *wxBLUE_PEN, *wxGREEN_PEN, *wxYELLOW_PEN};
BasicDrawPane::BasicDrawPane(wxFrame* parent, int ch) : wxPanel(parent){
time = 0;
diff = 0;
Bind(wxEVT_PAINT, &BasicDrawPane::paintEvent, this);
xpos = 0;
channels = ch;
for (int i = 0; i<channels; i++) {
data.push_back(std::vector<float>());
for (int j = 0; j<1024/2; j++) {
@@ -14,6 +17,15 @@ BasicDrawPane::BasicDrawPane(wxFrame* parent, int ch) : wxPanel(parent){
}
}
void BasicDrawPane::Clear(){
for (int i = 0; i<channels; i++) {
for (auto &d : data[i]){
d = 0;
}
}
xpos = 0;
}
/*
* Called by the system of by wxWidgets when the panel needs
* to be redrawn. You can also trigger this call by
@@ -84,15 +96,10 @@ void BasicDrawPane::render(wxDC& dc)
// ursprung oben links
// draw some text
const wxPen pen[] = {*wxRED_PEN, *wxYELLOW_PEN, *wxGREEN_PEN, *wxBLUE_PEN};
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetPen(*wxGREY_PEN);
dc.DrawLine( 0, h/2, w, h/2 );
dc.SetPen(*wxBLACK_PEN);
dc.DrawText(wxString::Format(wxT("%i"),diff*50), 40, 60);
dc.DrawLine( 40, 60, 40+50, 60 );
@@ -112,5 +119,9 @@ void BasicDrawPane::render(wxDC& dc)
x += xstep;
}
}
//mittellinie
dc.SetPen(*wxGREY_PEN);
dc.DrawLine( 0, h/2, w, h/2 );
// Look at the wxDC docs to learn how to draw other stuff
}
+2
View File
@@ -22,8 +22,10 @@ public:
void paintNow();
void plotvalue(int[]);
void plotvalue(int);
void Clear();
void render(wxDC& dc);
int channels;
static const wxPen pen[];
private:
wxLongLong time;
wxLongLong diff;
+47 -18
View File
@@ -43,16 +43,38 @@ MainFrame::MainFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title){
drawpanel = new BasicDrawPane((wxFrame*)top,4);
topsizer->Add(drawpanel, 1,wxEXPAND,0);
wxArrayString waves;
waves.push_back("-");
waves.push_back("error");
waves.push_back("error_d");
waves.push_back("error_dd");
waves.push_back("soll_pos");
waves.push_back("pid.cmd_d");
waves.push_back("pid.cmd_dd");
waves.push_back("ist");
waves.push_back("feedbackv");
waves.push_back("voltage_scale");
waves.push_back("saturated_count");
waves.push_back("mag_pos");
waves.push_back("startpos");
waves.push_back("res_offset");
//channels
for(int i = 0;i<drawpanel->channels;i++){
channelchoice.push_back(new wxChoice (top, wxID_ANY));
channelchoice.back()->SetClientData(new int(i));
channelchoice.back()->Bind(wxEVT_CHOICE,&MainFrame::OnChannelChange, this, wxID_ANY);
channelchoice.back()->Append(wxT("-"));
for(int j = 1; j < 15; j++){
channelchoice.back()->Append(std::to_string(j));
}
channelchoice.back()->Set(waves);
wxPanel *c_panel;
c_panel = new wxPanel(top, wxID_NEW, wxPoint(150, 20), wxSize(20, 20), wxBORDER_NONE);
c_panel->SetBackgroundColour(drawpanel->pen[i].GetColour());
channelleiste->Add(c_panel, 0,wxALIGN_LEFT|wxALL,3);
channelleiste->Add(channelchoice.back(), 0,wxALIGN_LEFT|wxALL,3);
}
topsizer->Add(channelleiste);
top->SetSizer(topsizer);
@@ -95,21 +117,23 @@ void MainFrame::OnKeyDown(wxKeyEvent& event){
}
void MainFrame::OnChannelChange(wxCommandEvent& event){
std::cout << *(int*)event.GetClientData() << "->" << event.GetSelection() << std::endl;
std::string df = "wave";
df += std::to_string(*(int*)event.GetClientData() + 1);
df += " = ";
df += std::to_string(event.GetSelection());
if((history.size()==0 || history.back() != df) && df != wxEmptyString){
history.push_back(df);
}
histpos = history.size();
int ret1 = sp_nonblocking_write(port, df.c_str(), df.length());
int ret2 = sp_nonblocking_write(port, "\r", 1);
if(ret1 != df.length() || ret2!=1){
wxMessageBox( wxT("Fehler beim senden"), wxT("Error"), wxICON_EXCLAMATION);
disconnect();
if(connected){
std::cout << *(int*)event.GetClientData() << "->" << event.GetSelection() << std::endl;
std::string df = "wave";
df += std::to_string(*(int*)event.GetClientData() + 1);
df += " = ";
df += std::to_string(event.GetSelection());
if((history.size()==0 || history.back() != df) && df != wxEmptyString){
history.push_back(df);
}
histpos = history.size();
int ret1 = sp_nonblocking_write(port, df.c_str(), df.length());
int ret2 = sp_nonblocking_write(port, "\r", 1);
if(ret1 != df.length() || ret2!=1){
wxMessageBox( wxT("Fehler beim senden"), wxT("Error"), wxICON_EXCLAMATION);
disconnect();
}
}
}
@@ -175,6 +199,7 @@ void MainFrame::listports(){
void MainFrame::OnClear(wxCommandEvent& WXUNUSED(event)){
text->Clear();
drawpanel->Clear();
}
void MainFrame::OnConnect(wxCommandEvent& WXUNUSED(event)){
@@ -201,6 +226,8 @@ void MainFrame::connect(){
connectbutton->SetLabel(wxT("&Disonnect"));
refresh->Disable();
choose_port->Disable();
uhu->Disable();
stmbl->Disable();
textinput->SetFocus();
}else{
wxMessageBox( wxT("Fehler beim Öffnen"), wxT("Error"), wxICON_EXCLAMATION);
@@ -214,6 +241,8 @@ void MainFrame::disconnect(){
connectbutton->SetLabel(wxT("&Connect"));
refresh->Enable();
choose_port->Enable();
uhu->Enable();
stmbl->Enable();
}
}