View unanswered posts | View active topics It is currently Tue Nov 13, 2018 11:06 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Proportioal Motor Speed
Author Message
Rookie

Joined: Fri Jan 04, 2013 8:27 pm
Posts: 2
Proportioal Motor Speed
We currently have an arm, powered by a motor (port 1). It is attached to a potentiometer, in slot in1.

I am trying to use this code:
 Code: if(SensorValue[in1] > 1000) //At rest the arm is at 0, I want it to raise to the height 1000{if((1000 - SensorValue[in1])>=150) //If the arm's distance from the target position is more than 150{motor[port1] = -127; //Full speed ahead!}if((1000- SensorValue[in1])<150) //However, if it is less than 150 close to the target height, {motor[port1] = (1000-SensorValue[in1])*(127/150); //My logic here is that, when 1000-SensorValue[in1] = 150, the motor runs at 127. When 1000-SensorValue[in1] = 75, the motor runs at 63.5. It decreases until it finally reaches 0, and in that case, the motor also reaches 0. }}

Here is where the problem arises. Apparently the motor value needs to be a constant, and I have no idea how to even make that work.

Basically, what my code does is when the arm tries to reach target height 1000. Starting when it is 150 ticks close, it slows down until it has a force of 0 when it reaches the target position.

There are a few rubber bands pulling it up so we don't have to worry about the motors having 1 force and not being able to move the arm up, and we don't care (right now) if the arm goes over the height, but the main priority is just to figure out how to get this working.

Thanks,
1622

Fri Jan 04, 2013 8:39 pm
Rookie

Joined: Fri Jan 04, 2013 8:27 pm
Posts: 2
Re: Proportioal Motor Speed
Apparently the fix was to define another variable as 1000-sensorvalue[in1], and have it directly multiply and divide:

changedsensorvalue*127/150 works just fine.

Any ideas why?

Fri Jan 04, 2013 8:57 pm
Novice

Joined: Sat Jul 10, 2010 3:06 pm
Posts: 86
Location: Roanoke, VA
Re: Proportioal Motor Speed
This is the same issue I ran into on this thread: viewtopic.php?f=11&t=5309

Let's say that SensorValue[in1] is 925.
Then, the robot evaluates the statement like so:
 Code: motor[port1] = (1000-SensorValue[in1])*(127/150);

 Code: motor[port1] = (1000-925)*(0.8467);

 Code: motor[port1] = (75)*(0.8467);

Now, to perform the multiplication, ROBOTC casts the decimal to an integer. This basically means that ROBOTC truncates the decimal values. Now, we have:
 Code: motor[port1] = (75)*(0);

 Code: motor[port1] = 0;

There is a minor bug in the compiler that doesn't like this (see linked thread).

A fix to your line of code would be (note lack of parenthesis):
 Code: motor[port1] = (1000-SensorValue[in1])*127/150;

_________________
Check out my website! www.RoboDesigners.com

VRC Team 2190

Sat Jan 05, 2013 3:34 pm
Moderator

Joined: Tue Sep 14, 2010 9:19 pm
Posts: 496
Re: Proportioal Motor Speed
to evaluate the division as a float, you can also do:
 Code:127.0 / 150

Or cast one of the numbers to a float:
 Code:((float)127) / 150

_________________
sudo rm -rf /

Sat Jan 05, 2013 4:18 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning