C/C++ :: Trapezoidal Motion Profile Using Discrete Method?
Mar 9, 2015
I'm trying to program an arduino to generate a Trapezoidal Motion Profile to control a DC motor with a quadrature encoder.
Essentially, the user will input the desired Target Position, Max Velocity and Acceleration (decel = -accel) and the code will calculate the target position versus time which will then be compared with the actual position. The result will then be subject to a PID calculation
My initial assumption was that I could use basic Newtonian physics to determine position (i.e. PT = P0 + V0T + 1/2AT2, VT = V0 + AT). However, after reading through documentation for pre-existing motion controllers, I discovered that the prevalent method was to use a discrete time method, which is as follows:
VK = VK-1 + A (A = Acceleration)
PK = PK-1 + VK-1 + A/2
I'm having a hard time understanding quite how this equation would generate the target position versus time. In the case of Velocity, it seems to just add the acceleration to the current velocity. But what about everything in between?
I have this code which performs the analysis part of discrete wavelet transform. It works pretty well. However, I wish to reduce the time that it consumes even further. I did use reserve() and it worked upto few msec.
int rows = signal.size(); int cols = signal[0].size(); int cols_lp1 =(int) ceil( (double) cols / 2); vector<vector<double> > lp_dn1(rows, vector<double>(cols_lp1)); vector<double> temp_row; temp_row.reserve(512);
Is there a way to know from a Windows service application (running as a local-system) if a specific logged in interactive user account is configured with a roaming profile? I need this to be compatible with Windows XP SP3.
One of my last programs to write was to use the trapezoidal rule to approx. the definite integral defined in the program. It works, now i am looking for ways to improve this code, if there are any.
Code: #include<stdlib.h>#include<stdio.h> #include<math.h> double integral (double x); int main(void){
[Code] ....
the output is simple:
Code: ssma-imac:ENG-3211 ssma$ ./integralThe integral of x^2 Sin(x) dx from 1 to 5 is -18.953841
And yes this is a very good approximation of the actual integral.
I am new to c programing and I had spend 2 days on a program and I can't fix the error:
Code] .... gcc Test.c -o Test.exe /tmp/ccZkbk0V.o: In function `f': Test.c:(.text+0x2f): undefined reference to `sqrt' collect2: ld returned 1 exit status
I've been trying for more than one month to access a method found in a library called libcocosnas_static.a. I'm using Cocos2d-X version 2.0.4. The library has been used many times by my company to make games using cocos2d-1.0.1-x-0.12.0 without any problem.
This is what I've done: 1- I added the include paths of the library to both eclipse and Android.mk 2- Included the .h file using #include "NASPlatformUtil.h" 3- Added the libcocosnas_static.a file to the proj.androidobjlocalarmeabi folder 4- Added "LOCAL_WHOLE_STATIC_LIBRARIES += cocosnas_static" to the Android.mk file 5- Called the function using: NASPlatformUtil:: openUrl("http://xxx.xxx.com/");
I can right click on the function, click Open Declaration and get it without any problem, but the compiler keeps on giving me that dreaded error...
I am using SDL 2.0. But I don't know how to handle mouse input. Do you think you can explain of how to do that? Or give me a link that explains that really great?
I know how to handle a mouse button that presses down for a sec.
Code: if (event.type == SDL_MOUSEBUTTONDOWN){ if (event.button.button == SDL_BUTTON_LEFT){ // Do something . . . } }
But not how to handle the mouse input of what the mouse is hovering over and that.
Like in a start menu of a game. I want a button for example to appear blue when I hover over it and when I click on it. It should start the game for example.
I have created plane as floor and sphere as ball. I used physics equations to it and ball falls under gravity. Now i want to attach visual arrow to this ball which moves with it according to velocity direction. If ball bounces then direction of velocity is changed so does arrow.
I am working on a project that requires using an arduino microcontroller to control the motion of a servo motor. The arduino language is pretty much C.
The original code is of the form:
Code: #include <Servo.h>
Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
[Code] .....
But the problem is I don't want the motor's motion to behave linearly (constant increments of the pos variable). My desired motion is a sinusoidal like function. How to approach this?
I am quite new to programming, especially with microcontrollers. My guess is that instead of the pos+=1, I would need something like pos+=sin(argument). I am not sure what that argument should be.
I'm currently working on a simulation of the motion of magnets on a rod. As part of it, there are arrays of the properties of the magnets:
long double *accelerations; // These will later be dynamically allocated depending on the number long double *velocities; // of magnets long double *positions;
However, when I go to compile this, the compiler gives me these error for the pointers:
error: two or more data types in declaration of 'accelerations' error: two or more data types in declaration of 'velocities' error: two or more data types in declaration of 'positions'
Apparently, the compiler isn't recognising long double* as a type and is instead reading is as the two types long and double*.
I have a form with a picturebox and some buttons to move the picturebox. I don't want the user to guide the picturebox out of the form even by dragging the form border picturebox moves just in the form border, and also there is a button to guide the picturebox to the start position (start choose by user). What can i do?
I currently have a project that requires me to build a leap motion Virtual Piano. I am using Windows Visual Studio 2013 and i plan to use C++ to code it.
I assume my first step is to create a virtual piano using C++.. Then, link it with leap motion interface.
Can i know which audio library suits my project and how can i go about doing it?
I have a question similar to the one here: [URL] .....
The main difference is I would like to pass a method of derived class as a parameter to some other method in its template base class.
template <typename BaseType> class Base { public: typedef void (Base::*Callback)(int A);
[Code] .....
The above is an example which does not compile. My compiler complains that the two BaseMethod() calls in DerivedMethod() are invalid uses of non-static member function.
Is this not possible to do, or is my syntax simply wrong? All I want is to be able to pass as an an argument to a method in the base class from the derived class some callback as a variable for the base class to invoke later.
#include <iostream> using namespace std; struct A { virtual void f() { cout<<"A "; } };
[code]...
I would expect that both examples 2 & 3 will give me the same result.I tried to figure it out but I could not. Both are references of a base class type, that get a derived object.
Q1 : why is the difference between them ?
As I see it, its kind of a mix between pointer - which in case of virtual method that was override in derived class - would give me the derived method (e.g. "B") and between regular object - which in case of virtual method that was override - would give me the specific method (Still "B"). So, example 2 "use" it as a regular object and example 3, "use" it as pointer.
Q2 : How should I refer to it ? I am using VS2008.
I have 2 classes with a Function with the same definition (both inherited from the same base class) and in my derived class I derive from both of those 2. Is it possible to use the Methods of both classes? for example with an other name?
class A { protected: int print(int a) { std::cout << "int A: " << a << std::endl; } }; class B : A
[Code] ....
is there something like using C::print as printc;?
The Problem, I have a Sprite class that derives from a Rectangle with properties Position, Size, Origin and Angle and a Text class that derives from Rectangle. Now i have a Button class deriving from both Sprite and Text.
- The Position, when moving the Button i have to change the position of both so i Implemented a new Method which calls SetPosition from the Sprite and the Text. - The SetSize just affects the Button so i just did using Sprite::SetSize; - The angle affects both so i just implemented a new Method and hide the other two
The problem is here: - The Origin: writing button.SetOrigin(-1,0) should set the Origin of the Button and writing button.SetTextOrigin should set the Origin of the text.
Should i just reimplement a Mehtod named SetTextOrigin and call Text::SetOrigin from there and hide the button.Text::SetOrigin or is there something like using Text::SetOrigin as SetTextOrigin?
It has been a few years since I have had to do this, but I need to declare a method in my base class, but produce no code for it. Then when this library is used by my second project I will derive a class from this base class and put the code into it there. How is this possible? I used to know how but do not remember how now.
The library is a static library designed for linking with both 32bit and 64bit Windows applications to handle a lot of the tedious stuff with Windows programming. The method in question handles specific command inputs. However, since each program that uses this library will have different uses for these commands, I want to leave it up to the user to code their own handling, but require it to be coded in the derived class.
I want to access the body of the Add() of a list in c# to see how it works, but it only just gives me the declaration.
[DebuggerTypeProxy(typeof (Mscorlib_CollectionDebugView<>))] [DebuggerDisplay("Count = {Count}")] [Serializable] public class List<T> : IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable { public void Add(T item); // thats all. I tried go to declaration but still gives me this line of code. This is from metadata in Visual studio. }
How this thing work. It just a declaration not a definition yet its still doing something. How is that possible.
how to write a "charge simulation method" program in C or C++? It's to calculate electric distribution and also electric potential of two different dielectrics. I have attached the diagram of the shape of the electrode that needs to be investigated.
Allow users to enter their name and favorite saying in a single method that gets invoked two times. If I can only return one value at a time, how am I suppose to get name and favorite saying out of UserInput()?
I have to create a program that accepts 10 numbers from user, and then I display a list of the numbers, the smallest one and the higher number. I have problems with displaying the smallest and higher number, I tried to Array.Sort and Array.Reverse, but I don't know what I'm doing wrong, this is my code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace SmallAndLargeGUI
[Code] ...
Also I tried to set
if (x == 10) numberTextBox.Enabled = false;
to block the textbox when the user has entered 10 numbers, but didn't work either...